Completed
Pull Request — master (#10005)
by Robin
284:48 queued 266:04
created
apps/provisioning_api/lib/Controller/GroupsController.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -44,247 +44,247 @@
 block discarded – undo
44 44
 
45 45
 class GroupsController extends AUserData {
46 46
 
47
-	/** @var ILogger */
48
-	private $logger;
47
+    /** @var ILogger */
48
+    private $logger;
49 49
 
50
-	/**
51
-	 * @param string $appName
52
-	 * @param IRequest $request
53
-	 * @param IUserManager $userManager
54
-	 * @param IConfig $config
55
-	 * @param IGroupManager $groupManager
56
-	 * @param IUserSession $userSession
57
-	 * @param AccountManager $accountManager
58
-	 * @param ILogger $logger
59
-	 * @param UsersController $userController
60
-	 */
61
-	public function __construct(string $appName,
62
-								IRequest $request,
63
-								IUserManager $userManager,
64
-								IConfig $config,
65
-								IGroupManager $groupManager,
66
-								IUserSession $userSession,
67
-								AccountManager $accountManager,
68
-								ILogger $logger) {
69
-		parent::__construct($appName,
70
-			$request,
71
-			$userManager,
72
-			$config,
73
-			$groupManager,
74
-			$userSession,
75
-			$accountManager);
50
+    /**
51
+     * @param string $appName
52
+     * @param IRequest $request
53
+     * @param IUserManager $userManager
54
+     * @param IConfig $config
55
+     * @param IGroupManager $groupManager
56
+     * @param IUserSession $userSession
57
+     * @param AccountManager $accountManager
58
+     * @param ILogger $logger
59
+     * @param UsersController $userController
60
+     */
61
+    public function __construct(string $appName,
62
+                                IRequest $request,
63
+                                IUserManager $userManager,
64
+                                IConfig $config,
65
+                                IGroupManager $groupManager,
66
+                                IUserSession $userSession,
67
+                                AccountManager $accountManager,
68
+                                ILogger $logger) {
69
+        parent::__construct($appName,
70
+            $request,
71
+            $userManager,
72
+            $config,
73
+            $groupManager,
74
+            $userSession,
75
+            $accountManager);
76 76
 
77
-		$this->logger = $logger;
78
-	}
77
+        $this->logger = $logger;
78
+    }
79 79
 
80
-	/**
81
-	 * returns a list of groups
82
-	 *
83
-	 * @NoAdminRequired
84
-	 *
85
-	 * @param string $search
86
-	 * @param int $limit
87
-	 * @param int $offset
88
-	 * @return DataResponse
89
-	 */
90
-	public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
91
-		$groups = $this->groupManager->search($search, $limit, $offset);
92
-		$groups = array_map(function($group) {
93
-			/** @var IGroup $group */
94
-			return $group->getGID();
95
-		}, $groups);
80
+    /**
81
+     * returns a list of groups
82
+     *
83
+     * @NoAdminRequired
84
+     *
85
+     * @param string $search
86
+     * @param int $limit
87
+     * @param int $offset
88
+     * @return DataResponse
89
+     */
90
+    public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
91
+        $groups = $this->groupManager->search($search, $limit, $offset);
92
+        $groups = array_map(function($group) {
93
+            /** @var IGroup $group */
94
+            return $group->getGID();
95
+        }, $groups);
96 96
 
97
-		return new DataResponse(['groups' => $groups]);
98
-	}
97
+        return new DataResponse(['groups' => $groups]);
98
+    }
99 99
 
100
-	/**
101
-	 * returns a list of groups details with ids and displaynames
102
-	 *
103
-	 * @NoAdminRequired
104
-	 *
105
-	 * @param string $search
106
-	 * @param int $limit
107
-	 * @param int $offset
108
-	 * @return DataResponse
109
-	 */
110
-	public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
111
-		$groups = $this->groupManager->search($search, $limit, $offset);
112
-		$groups = array_map(function($group) {
113
-			/** @var IGroup $group */
114
-			return [
115
-				'id' => $group->getGID(),
116
-				'displayname' => $group->getDisplayName(),
117
-				'usercount' => $group->count(),
118
-				'disabled' => $group->countDisabled(),
119
-				'canAdd' => $group->canAddUser(),
120
-				'canRemove' => $group->canRemoveUser(),
121
-			];
122
-		}, $groups);
100
+    /**
101
+     * returns a list of groups details with ids and displaynames
102
+     *
103
+     * @NoAdminRequired
104
+     *
105
+     * @param string $search
106
+     * @param int $limit
107
+     * @param int $offset
108
+     * @return DataResponse
109
+     */
110
+    public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
111
+        $groups = $this->groupManager->search($search, $limit, $offset);
112
+        $groups = array_map(function($group) {
113
+            /** @var IGroup $group */
114
+            return [
115
+                'id' => $group->getGID(),
116
+                'displayname' => $group->getDisplayName(),
117
+                'usercount' => $group->count(),
118
+                'disabled' => $group->countDisabled(),
119
+                'canAdd' => $group->canAddUser(),
120
+                'canRemove' => $group->canRemoveUser(),
121
+            ];
122
+        }, $groups);
123 123
 
124
-		return new DataResponse(['groups' => $groups]);
125
-	}
124
+        return new DataResponse(['groups' => $groups]);
125
+    }
126 126
 
127
-	/**
128
-	 * @NoAdminRequired
129
-	 *
130
-	 * @param string $groupId
131
-	 * @return DataResponse
132
-	 * @throws OCSException	
133
-	 *
134
-	 * @deprecated 14 Use getGroupUsers
135
-	 */
136
-	public function getGroup(string $groupId): DataResponse {
137
-		return $this->getGroupUsers($groupId);
138
-	}
127
+    /**
128
+     * @NoAdminRequired
129
+     *
130
+     * @param string $groupId
131
+     * @return DataResponse
132
+     * @throws OCSException	
133
+     *
134
+     * @deprecated 14 Use getGroupUsers
135
+     */
136
+    public function getGroup(string $groupId): DataResponse {
137
+        return $this->getGroupUsers($groupId);
138
+    }
139 139
 
140
-	/**
141
-	 * returns an array of users in the specified group
142
-	 *
143
-	 * @NoAdminRequired
144
-	 *
145
-	 * @param string $groupId
146
-	 * @return DataResponse
147
-	 * @throws OCSException
148
-	 */
149
-	public function getGroupUsers(string $groupId): DataResponse {
150
-		$user = $this->userSession->getUser();
151
-		$isSubadminOfGroup = false;
140
+    /**
141
+     * returns an array of users in the specified group
142
+     *
143
+     * @NoAdminRequired
144
+     *
145
+     * @param string $groupId
146
+     * @return DataResponse
147
+     * @throws OCSException
148
+     */
149
+    public function getGroupUsers(string $groupId): DataResponse {
150
+        $user = $this->userSession->getUser();
151
+        $isSubadminOfGroup = false;
152 152
 
153
-		// Check the group exists
154
-		$group = $this->groupManager->get($groupId);
155
-		if ($group !== null) {
156
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
157
-		} else {
158
-			throw new OCSNotFoundException('The requested group could not be found');
159
-		}
153
+        // Check the group exists
154
+        $group = $this->groupManager->get($groupId);
155
+        if ($group !== null) {
156
+            $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
157
+        } else {
158
+            throw new OCSNotFoundException('The requested group could not be found');
159
+        }
160 160
 
161
-		// Check subadmin has access to this group
162
-		if($this->groupManager->isAdmin($user->getUID())
163
-		   || $isSubadminOfGroup) {
164
-			$users = $this->groupManager->get($groupId)->getUsers();
165
-			$users =  array_map(function($user) {
166
-				/** @var IUser $user */
167
-				return $user->getUID();
168
-			}, $users);
169
-			$users = array_values($users);
170
-			return new DataResponse(['users' => $users]);
171
-		}
161
+        // Check subadmin has access to this group
162
+        if($this->groupManager->isAdmin($user->getUID())
163
+           || $isSubadminOfGroup) {
164
+            $users = $this->groupManager->get($groupId)->getUsers();
165
+            $users =  array_map(function($user) {
166
+                /** @var IUser $user */
167
+                return $user->getUID();
168
+            }, $users);
169
+            $users = array_values($users);
170
+            return new DataResponse(['users' => $users]);
171
+        }
172 172
 
173
-		throw new OCSForbiddenException();
174
-	}
173
+        throw new OCSForbiddenException();
174
+    }
175 175
 
176
-	/**
177
-	 * returns an array of users details in the specified group
178
-	 *
179
-	 * @NoAdminRequired
180
-	 *
181
-	 * @param string $groupId
182
-	 * @param string $search
183
-	 * @param int $limit
184
-	 * @param int $offset
185
-	 * @return DataResponse
186
-	 * @throws OCSException
187
-	 */
188
-	public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse {
189
-		$user = $this->userSession->getUser();
190
-		$isSubadminOfGroup = false;
176
+    /**
177
+     * returns an array of users details in the specified group
178
+     *
179
+     * @NoAdminRequired
180
+     *
181
+     * @param string $groupId
182
+     * @param string $search
183
+     * @param int $limit
184
+     * @param int $offset
185
+     * @return DataResponse
186
+     * @throws OCSException
187
+     */
188
+    public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse {
189
+        $user = $this->userSession->getUser();
190
+        $isSubadminOfGroup = false;
191 191
 
192
-		// Check the group exists
193
-		$group = $this->groupManager->get($groupId);
194
-		if ($group !== null) {
195
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
196
-		} else {
197
-			throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
198
-		}
192
+        // Check the group exists
193
+        $group = $this->groupManager->get($groupId);
194
+        if ($group !== null) {
195
+            $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
196
+        } else {
197
+            throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
198
+        }
199 199
 
200
-		// Check subadmin has access to this group
201
-		if($this->groupManager->isAdmin($user->getUID())
202
-		   || $isSubadminOfGroup) {
203
-			$users = $this->groupManager->get($groupId)->searchUsers($search, $limit, $offset);
200
+        // Check subadmin has access to this group
201
+        if($this->groupManager->isAdmin($user->getUID())
202
+           || $isSubadminOfGroup) {
203
+            $users = $this->groupManager->get($groupId)->searchUsers($search, $limit, $offset);
204 204
 
205
-			// Extract required number
206
-			$users = array_keys($users);
207
-			$usersDetails = [];
208
-			foreach ($users as $userId) {
209
-				$userData = $this->getUserData($userId);
210
-				// Do not insert empty entry
211
-				if(!empty($userData)) {
212
-					$usersDetails[$userId] = $userData;
213
-				} else {
214
-					// Logged user does not have permissions to see this user
215
-					// only showing its id
216
-					$usersDetails[$userId] = ['id' => $userId];
217
-				}
218
-			}
219
-			return new DataResponse(['users' => $usersDetails]);
220
-		}
205
+            // Extract required number
206
+            $users = array_keys($users);
207
+            $usersDetails = [];
208
+            foreach ($users as $userId) {
209
+                $userData = $this->getUserData($userId);
210
+                // Do not insert empty entry
211
+                if(!empty($userData)) {
212
+                    $usersDetails[$userId] = $userData;
213
+                } else {
214
+                    // Logged user does not have permissions to see this user
215
+                    // only showing its id
216
+                    $usersDetails[$userId] = ['id' => $userId];
217
+                }
218
+            }
219
+            return new DataResponse(['users' => $usersDetails]);
220
+        }
221 221
 
222
-		throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
223
-	}
222
+        throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
223
+    }
224 224
 
225
-	/**
226
-	 * creates a new group
227
-	 *
228
-	 * @PasswordConfirmationRequired
229
-	 *
230
-	 * @param string $groupid
231
-	 * @return DataResponse
232
-	 * @throws OCSException
233
-	 */
234
-	public function addGroup(string $groupid): DataResponse {
235
-		// Validate name
236
-		if(empty($groupid)) {
237
-			$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
238
-			throw new OCSException('Invalid group name', 101);
239
-		}
240
-		// Check if it exists
241
-		if($this->groupManager->groupExists($groupid)){
242
-			throw new OCSException('group exists', 102);
243
-		}
244
-		$this->groupManager->createGroup($groupid);
245
-		return new DataResponse();
246
-	}
225
+    /**
226
+     * creates a new group
227
+     *
228
+     * @PasswordConfirmationRequired
229
+     *
230
+     * @param string $groupid
231
+     * @return DataResponse
232
+     * @throws OCSException
233
+     */
234
+    public function addGroup(string $groupid): DataResponse {
235
+        // Validate name
236
+        if(empty($groupid)) {
237
+            $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
238
+            throw new OCSException('Invalid group name', 101);
239
+        }
240
+        // Check if it exists
241
+        if($this->groupManager->groupExists($groupid)){
242
+            throw new OCSException('group exists', 102);
243
+        }
244
+        $this->groupManager->createGroup($groupid);
245
+        return new DataResponse();
246
+    }
247 247
 
248
-	/**
249
-	 * @PasswordConfirmationRequired
250
-	 *
251
-	 * @param string $groupId
252
-	 * @return DataResponse
253
-	 * @throws OCSException
254
-	 */
255
-	public function deleteGroup(string $groupId): DataResponse {
256
-		// Check it exists
257
-		if(!$this->groupManager->groupExists($groupId)){
258
-			throw new OCSException('', 101);
259
-		} else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
260
-			// Cannot delete admin group
261
-			throw new OCSException('', 102);
262
-		}
248
+    /**
249
+     * @PasswordConfirmationRequired
250
+     *
251
+     * @param string $groupId
252
+     * @return DataResponse
253
+     * @throws OCSException
254
+     */
255
+    public function deleteGroup(string $groupId): DataResponse {
256
+        // Check it exists
257
+        if(!$this->groupManager->groupExists($groupId)){
258
+            throw new OCSException('', 101);
259
+        } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
260
+            // Cannot delete admin group
261
+            throw new OCSException('', 102);
262
+        }
263 263
 
264
-		return new DataResponse();
265
-	}
264
+        return new DataResponse();
265
+    }
266 266
 
267
-	/**
268
-	 * @param string $groupId
269
-	 * @return DataResponse
270
-	 * @throws OCSException
271
-	 */
272
-	public function getSubAdminsOfGroup(string $groupId): DataResponse {
273
-		// Check group exists
274
-		$targetGroup = $this->groupManager->get($groupId);
275
-		if($targetGroup === null) {
276
-			throw new OCSException('Group does not exist', 101);
277
-		}
267
+    /**
268
+     * @param string $groupId
269
+     * @return DataResponse
270
+     * @throws OCSException
271
+     */
272
+    public function getSubAdminsOfGroup(string $groupId): DataResponse {
273
+        // Check group exists
274
+        $targetGroup = $this->groupManager->get($groupId);
275
+        if($targetGroup === null) {
276
+            throw new OCSException('Group does not exist', 101);
277
+        }
278 278
 
279
-		/** @var IUser[] $subadmins */
280
-		$subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
281
-		// New class returns IUser[] so convert back
282
-		$uids = [];
283
-		foreach ($subadmins as $user) {
284
-			$uids[] = $user->getUID();
285
-		}
279
+        /** @var IUser[] $subadmins */
280
+        $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
281
+        // New class returns IUser[] so convert back
282
+        $uids = [];
283
+        foreach ($subadmins as $user) {
284
+            $uids[] = $user->getUID();
285
+        }
286 286
 
287
-		return new DataResponse($uids);
288
-	}
287
+        return new DataResponse($uids);
288
+    }
289 289
 
290 290
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -153,16 +153,16 @@  discard block
 block discarded – undo
153 153
 		// Check the group exists
154 154
 		$group = $this->groupManager->get($groupId);
155 155
 		if ($group !== null) {
156
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
156
+			$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
157 157
 		} else {
158 158
 			throw new OCSNotFoundException('The requested group could not be found');
159 159
 		}
160 160
 
161 161
 		// Check subadmin has access to this group
162
-		if($this->groupManager->isAdmin($user->getUID())
162
+		if ($this->groupManager->isAdmin($user->getUID())
163 163
 		   || $isSubadminOfGroup) {
164 164
 			$users = $this->groupManager->get($groupId)->getUsers();
165
-			$users =  array_map(function($user) {
165
+			$users = array_map(function($user) {
166 166
 				/** @var IUser $user */
167 167
 				return $user->getUID();
168 168
 			}, $users);
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 		// Check the group exists
193 193
 		$group = $this->groupManager->get($groupId);
194 194
 		if ($group !== null) {
195
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
195
+			$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
196 196
 		} else {
197 197
 			throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
198 198
 		}
199 199
 
200 200
 		// Check subadmin has access to this group
201
-		if($this->groupManager->isAdmin($user->getUID())
201
+		if ($this->groupManager->isAdmin($user->getUID())
202 202
 		   || $isSubadminOfGroup) {
203 203
 			$users = $this->groupManager->get($groupId)->searchUsers($search, $limit, $offset);
204 204
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 			foreach ($users as $userId) {
209 209
 				$userData = $this->getUserData($userId);
210 210
 				// Do not insert empty entry
211
-				if(!empty($userData)) {
211
+				if (!empty($userData)) {
212 212
 					$usersDetails[$userId] = $userData;
213 213
 				} else {
214 214
 					// Logged user does not have permissions to see this user
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
 	 */
234 234
 	public function addGroup(string $groupid): DataResponse {
235 235
 		// Validate name
236
-		if(empty($groupid)) {
236
+		if (empty($groupid)) {
237 237
 			$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
238 238
 			throw new OCSException('Invalid group name', 101);
239 239
 		}
240 240
 		// Check if it exists
241
-		if($this->groupManager->groupExists($groupid)){
241
+		if ($this->groupManager->groupExists($groupid)) {
242 242
 			throw new OCSException('group exists', 102);
243 243
 		}
244 244
 		$this->groupManager->createGroup($groupid);
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 	 */
255 255
 	public function deleteGroup(string $groupId): DataResponse {
256 256
 		// Check it exists
257
-		if(!$this->groupManager->groupExists($groupId)){
257
+		if (!$this->groupManager->groupExists($groupId)) {
258 258
 			throw new OCSException('', 101);
259
-		} else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
259
+		} else if ($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()) {
260 260
 			// Cannot delete admin group
261 261
 			throw new OCSException('', 102);
262 262
 		}
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	public function getSubAdminsOfGroup(string $groupId): DataResponse {
273 273
 		// Check group exists
274 274
 		$targetGroup = $this->groupManager->get($groupId);
275
-		if($targetGroup === null) {
275
+		if ($targetGroup === null) {
276 276
 			throw new OCSException('Group does not exist', 101);
277 277
 		}
278 278
 
Please login to merge, or discard this patch.