Completed
Pull Request — master (#8904)
by Joas
33:07 queued 15:47
created
apps/provisioning_api/appinfo/routes.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -25,47 +25,47 @@
 block discarded – undo
25 25
  */
26 26
 
27 27
 return [
28
-	'ocs' => [
29
-		// Apps
30
-		['root' => '/cloud', 'name' => 'Apps#getApps', 'url' => '/apps', 'verb' => 'GET'],
31
-		['root' => '/cloud', 'name' => 'Apps#getAppInfo', 'url' => '/apps/{app}', 'verb' => 'GET'],
32
-		['root' => '/cloud', 'name' => 'Apps#enable', 'url' => '/apps/{app}', 'verb' => 'POST'],
33
-		['root' => '/cloud', 'name' => 'Apps#disable', 'url' => '/apps/{app}', 'verb' => 'DELETE'],
28
+    'ocs' => [
29
+        // Apps
30
+        ['root' => '/cloud', 'name' => 'Apps#getApps', 'url' => '/apps', 'verb' => 'GET'],
31
+        ['root' => '/cloud', 'name' => 'Apps#getAppInfo', 'url' => '/apps/{app}', 'verb' => 'GET'],
32
+        ['root' => '/cloud', 'name' => 'Apps#enable', 'url' => '/apps/{app}', 'verb' => 'POST'],
33
+        ['root' => '/cloud', 'name' => 'Apps#disable', 'url' => '/apps/{app}', 'verb' => 'DELETE'],
34 34
 
35
-		// Groups
36
-		['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'],
37
-		['root' => '/cloud', 'name' => 'Groups#getGroupsDetails', 'url' => '/groups/details', 'verb' => 'GET'],
38
-		['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'],
39
-		['root' => '/cloud', 'name' => 'Groups#getGroupUsers', 'url' => '/groups/{groupId}/users', 'verb' => 'GET'],
40
-		['root' => '/cloud', 'name' => 'Groups#getGroupUsersDetails', 'url' => '/groups/{groupId}/users/details', 'verb' => 'GET'],
41
-		['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'],
42
-		['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'],
43
-		['root' => '/cloud', 'name' => 'Groups#getSubAdminsOfGroup', 'url' => '/groups/{groupId}/subadmins', 'verb' => 'GET'],
35
+        // Groups
36
+        ['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'],
37
+        ['root' => '/cloud', 'name' => 'Groups#getGroupsDetails', 'url' => '/groups/details', 'verb' => 'GET'],
38
+        ['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'],
39
+        ['root' => '/cloud', 'name' => 'Groups#getGroupUsers', 'url' => '/groups/{groupId}/users', 'verb' => 'GET'],
40
+        ['root' => '/cloud', 'name' => 'Groups#getGroupUsersDetails', 'url' => '/groups/{groupId}/users/details', 'verb' => 'GET'],
41
+        ['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'],
42
+        ['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'],
43
+        ['root' => '/cloud', 'name' => 'Groups#getSubAdminsOfGroup', 'url' => '/groups/{groupId}/subadmins', 'verb' => 'GET'],
44 44
 
45
-		// Users
46
-		['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'],
47
-		['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'],
48
-		['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'],
49
-		['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'],
50
-		['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'],
51
-		['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'],
52
-		['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'],
53
-		['root' => '/cloud', 'name' => 'Users#deleteUser', 'url' => '/users/{userId}', 'verb' => 'DELETE'],
54
-		['root' => '/cloud', 'name' => 'Users#enableUser', 'url' => '/users/{userId}/enable', 'verb' => 'PUT'],
55
-		['root' => '/cloud', 'name' => 'Users#disableUser', 'url' => '/users/{userId}/disable', 'verb' => 'PUT'],
56
-		['root' => '/cloud', 'name' => 'Users#getUsersGroups', 'url' => '/users/{userId}/groups', 'verb' => 'GET'],
57
-		['root' => '/cloud', 'name' => 'Users#addToGroup', 'url' => '/users/{userId}/groups', 'verb' => 'POST'],
58
-		['root' => '/cloud', 'name' => 'Users#removeFromGroup', 'url' => '/users/{userId}/groups', 'verb' => 'DELETE'],
59
-		['root' => '/cloud', 'name' => 'Users#getUserSubAdminGroups', 'url' => '/users/{userId}/subadmins', 'verb' => 'GET'],
60
-		['root' => '/cloud', 'name' => 'Users#addSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'POST'],
61
-		['root' => '/cloud', 'name' => 'Users#removeSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'DELETE'],
62
-		['root' => '/cloud', 'name' => 'Users#resendWelcomeMessage', 'url' => '/users/{userId}/welcome', 'verb' => 'POST'],
45
+        // Users
46
+        ['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'],
47
+        ['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'],
48
+        ['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'],
49
+        ['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'],
50
+        ['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'],
51
+        ['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'],
52
+        ['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'],
53
+        ['root' => '/cloud', 'name' => 'Users#deleteUser', 'url' => '/users/{userId}', 'verb' => 'DELETE'],
54
+        ['root' => '/cloud', 'name' => 'Users#enableUser', 'url' => '/users/{userId}/enable', 'verb' => 'PUT'],
55
+        ['root' => '/cloud', 'name' => 'Users#disableUser', 'url' => '/users/{userId}/disable', 'verb' => 'PUT'],
56
+        ['root' => '/cloud', 'name' => 'Users#getUsersGroups', 'url' => '/users/{userId}/groups', 'verb' => 'GET'],
57
+        ['root' => '/cloud', 'name' => 'Users#addToGroup', 'url' => '/users/{userId}/groups', 'verb' => 'POST'],
58
+        ['root' => '/cloud', 'name' => 'Users#removeFromGroup', 'url' => '/users/{userId}/groups', 'verb' => 'DELETE'],
59
+        ['root' => '/cloud', 'name' => 'Users#getUserSubAdminGroups', 'url' => '/users/{userId}/subadmins', 'verb' => 'GET'],
60
+        ['root' => '/cloud', 'name' => 'Users#addSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'POST'],
61
+        ['root' => '/cloud', 'name' => 'Users#removeSubAdmin', 'url' => '/users/{userId}/subadmins', 'verb' => 'DELETE'],
62
+        ['root' => '/cloud', 'name' => 'Users#resendWelcomeMessage', 'url' => '/users/{userId}/welcome', 'verb' => 'POST'],
63 63
 
64
-		// Config
65
-		['name' => 'AppConfig#getApps', 'url' => '/api/v1/config/apps', 'verb' => 'GET'],
66
-		['name' => 'AppConfig#getKeys', 'url' => '/api/v1/config/apps/{app}', 'verb' => 'GET'],
67
-		['name' => 'AppConfig#getValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'GET'],
68
-		['name' => 'AppConfig#setValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'POST'],
69
-		['name' => 'AppConfig#deleteKey', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'DELETE'],
70
-	],
64
+        // Config
65
+        ['name' => 'AppConfig#getApps', 'url' => '/api/v1/config/apps', 'verb' => 'GET'],
66
+        ['name' => 'AppConfig#getKeys', 'url' => '/api/v1/config/apps/{app}', 'verb' => 'GET'],
67
+        ['name' => 'AppConfig#getValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'GET'],
68
+        ['name' => 'AppConfig#setValue', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'POST'],
69
+        ['name' => 'AppConfig#deleteKey', 'url' => '/api/v1/config/apps/{app}/{key}', 'verb' => 'DELETE'],
70
+    ],
71 71
 ];
Please login to merge, or discard this patch.
apps/provisioning_api/lib/Controller/UsersController.php 2 patches
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 /**
4 4
  * @copyright Copyright (c) 2016, ownCloud, Inc.
5 5
  *
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		// Admin? Or SubAdmin?
141 141
 		$uid = $user->getUID();
142 142
 		$subAdminManager = $this->groupManager->getSubAdmin();
143
-		if($this->groupManager->isAdmin($uid)){
143
+		if ($this->groupManager->isAdmin($uid)) {
144 144
 			$users = $this->userManager->search($search, $limit, $offset);
145 145
 		} else if ($subAdminManager->isSubAdmin($user)) {
146 146
 			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		// Admin? Or SubAdmin?
174 174
 		$uid = $user->getUID();
175 175
 		$subAdminManager = $this->groupManager->getSubAdmin();
176
-		if($this->groupManager->isAdmin($uid)){
176
+		if ($this->groupManager->isAdmin($uid)) {
177 177
 			$users = $this->userManager->search($search, $limit, $offset);
178 178
 		} else if ($subAdminManager->isSubAdmin($user)) {
179 179
 			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 		foreach ($users as $key => $userId) {
193 193
 			$userData = $this->getUserData($userId);
194 194
 			// Do not insert empty entry
195
-			if(!empty($userData)) {
195
+			if (!empty($userData)) {
196 196
 				$usersDetails[$userId] = $userData;
197 197
 			}
198 198
 		}
@@ -213,27 +213,27 @@  discard block
 block discarded – undo
213 213
 	 * @return DataResponse
214 214
 	 * @throws OCSException
215 215
 	 */
216
-	public function addUser(string $userid, string $password = '', string $email='', array $groups = []): DataResponse {
216
+	public function addUser(string $userid, string $password = '', string $email = '', array $groups = []): DataResponse {
217 217
 		$user = $this->userSession->getUser();
218 218
 		$isAdmin = $this->groupManager->isAdmin($user->getUID());
219 219
 		$subAdminManager = $this->groupManager->getSubAdmin();
220 220
 
221
-		if($this->userManager->userExists($userid)) {
221
+		if ($this->userManager->userExists($userid)) {
222 222
 			$this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
223 223
 			throw new OCSException('User already exists', 102);
224 224
 		}
225 225
 
226
-		if($groups !== []) {
226
+		if ($groups !== []) {
227 227
 			foreach ($groups as $group) {
228
-				if(!$this->groupManager->groupExists($group)) {
228
+				if (!$this->groupManager->groupExists($group)) {
229 229
 					throw new OCSException('group '.$group.' does not exist', 104);
230 230
 				}
231
-				if(!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
232
-					throw new OCSException('insufficient privileges for group '. $group, 105);
231
+				if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
232
+					throw new OCSException('insufficient privileges for group '.$group, 105);
233 233
 				}
234 234
 			}
235 235
 		} else {
236
-			if(!$isAdmin) {
236
+			if (!$isAdmin) {
237 237
 				throw new OCSException('no group specified (required for subadmins)', 106);
238 238
 			}
239 239
 		}
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
 
253 253
 		try {
254 254
 			$newUser = $this->userManager->createUser($userid, $password);
255
-			$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
255
+			$this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']);
256 256
 
257 257
 			foreach ($groups as $group) {
258 258
 				$this->groupManager->get($group)->addUser($newUser);
259
-				$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
259
+				$this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']);
260 260
 			}
261 261
 
262 262
 			// Send new user mail only if a mail is set
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 
278 278
 			return new DataResponse();
279 279
 
280
-		} catch (HintException $e ) {
280
+		} catch (HintException $e) {
281 281
 			$this->logger->logException($e, [
282 282
 				'message' => 'Failed addUser attempt with hint exception.',
283 283
 				'level' => \OCP\Util::WARN,
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 	public function getUser(string $userId): DataResponse {
308 308
 		$data = $this->getUserData($userId);
309 309
 		// getUserData returns empty array if not enough permissions
310
-		if(empty($data)) {
310
+		if (empty($data)) {
311 311
 			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
312 312
 		}
313 313
 		return new DataResponse($data);
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	public function getCurrentUser(): DataResponse {
326 326
 		$user = $this->userSession->getUser();
327 327
 		if ($user) {
328
-			$data =  $this->getUserData($user->getUID());
328
+			$data = $this->getUserData($user->getUID());
329 329
 			// rename "displayname" to "display-name" only for this call to keep
330 330
 			// the API stable.
331 331
 			$data['display-name'] = $data['displayname'];
@@ -381,12 +381,12 @@  discard block
 block discarded – undo
381 381
 		$currentLoggedInUser = $this->userSession->getUser();
382 382
 
383 383
 		$targetUser = $this->userManager->get($userId);
384
-		if($targetUser === null) {
384
+		if ($targetUser === null) {
385 385
 			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
386 386
 		}
387 387
 
388 388
 		$permittedFields = [];
389
-		if($targetUser->getUID() === $currentLoggedInUser->getUID()) {
389
+		if ($targetUser->getUID() === $currentLoggedInUser->getUID()) {
390 390
 			// Editing self (display, email)
391 391
 			if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
392 392
 				$permittedFields[] = 'display';
@@ -412,13 +412,13 @@  discard block
 block discarded – undo
412 412
 			}
413 413
 
414 414
 			// If admin they can edit their own quota
415
-			if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
415
+			if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
416 416
 				$permittedFields[] = 'quota';
417 417
 			}
418 418
 		} else {
419 419
 			// Check if admin / subadmin
420 420
 			$subAdminManager = $this->groupManager->getSubAdmin();
421
-			if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
421
+			if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
422 422
 			|| $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
423 423
 				// They have permissions over the user
424 424
 				$permittedFields[] = 'display';
@@ -437,18 +437,18 @@  discard block
 block discarded – undo
437 437
 			}
438 438
 		}
439 439
 		// Check if permitted to edit this field
440
-		if(!in_array($key, $permittedFields)) {
440
+		if (!in_array($key, $permittedFields)) {
441 441
 			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
442 442
 		}
443 443
 		// Process the edit
444
-		switch($key) {
444
+		switch ($key) {
445 445
 			case 'display':
446 446
 			case AccountManager::PROPERTY_DISPLAYNAME:
447 447
 				$targetUser->setDisplayName($value);
448 448
 				break;
449 449
 			case 'quota':
450 450
 				$quota = $value;
451
-				if($quota !== 'none' && $quota !== 'default') {
451
+				if ($quota !== 'none' && $quota !== 'default') {
452 452
 					if (is_numeric($quota)) {
453 453
 						$quota = (float) $quota;
454 454
 					} else {
@@ -457,9 +457,9 @@  discard block
 block discarded – undo
457 457
 					if ($quota === false) {
458 458
 						throw new OCSException('Invalid quota value '.$value, 103);
459 459
 					}
460
-					if($quota === 0) {
460
+					if ($quota === 0) {
461 461
 						$quota = 'default';
462
-					}else if($quota === -1) {
462
+					} else if ($quota === -1) {
463 463
 						$quota = 'none';
464 464
 					} else {
465 465
 						$quota = \OCP\Util::humanFileSize($quota);
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 				$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
479 479
 				break;
480 480
 			case AccountManager::PROPERTY_EMAIL:
481
-				if(filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
481
+				if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
482 482
 					$targetUser->setEMailAddress($value);
483 483
 				} else {
484 484
 					throw new OCSException('', 102);
@@ -513,18 +513,18 @@  discard block
 block discarded – undo
513 513
 
514 514
 		$targetUser = $this->userManager->get($userId);
515 515
 
516
-		if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
516
+		if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
517 517
 			throw new OCSException('', 101);
518 518
 		}
519 519
 
520 520
 		// If not permitted
521 521
 		$subAdminManager = $this->groupManager->getSubAdmin();
522
-		if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
522
+		if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
523 523
 			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
524 524
 		}
525 525
 
526 526
 		// Go ahead with the delete
527
-		if($targetUser->delete()) {
527
+		if ($targetUser->delete()) {
528 528
 			return new DataResponse();
529 529
 		} else {
530 530
 			throw new OCSException('', 101);
@@ -567,13 +567,13 @@  discard block
 block discarded – undo
567 567
 		$currentLoggedInUser = $this->userSession->getUser();
568 568
 
569 569
 		$targetUser = $this->userManager->get($userId);
570
-		if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
570
+		if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
571 571
 			throw new OCSException('', 101);
572 572
 		}
573 573
 
574 574
 		// If not permitted
575 575
 		$subAdminManager = $this->groupManager->getSubAdmin();
576
-		if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
576
+		if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
577 577
 			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
578 578
 		}
579 579
 
@@ -594,11 +594,11 @@  discard block
 block discarded – undo
594 594
 		$loggedInUser = $this->userSession->getUser();
595 595
 
596 596
 		$targetUser = $this->userManager->get($userId);
597
-		if($targetUser === null) {
597
+		if ($targetUser === null) {
598 598
 			throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
599 599
 		}
600 600
 
601
-		if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
601
+		if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
602 602
 			// Self lookup or admin lookup
603 603
 			return new DataResponse([
604 604
 				'groups' => $this->groupManager->getUserGroupIds($targetUser)
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 			$subAdminManager = $this->groupManager->getSubAdmin();
608 608
 
609 609
 			// Looking up someone else
610
-			if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
610
+			if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
611 611
 				// Return the group that the method caller is subadmin of for the user in question
612 612
 				/** @var IGroup[] $getSubAdminsGroups */
613 613
 				$getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
@@ -637,16 +637,16 @@  discard block
 block discarded – undo
637 637
 	 * @throws OCSException
638 638
 	 */
639 639
 	public function addToGroup(string $userId, string $groupid = ''): DataResponse {
640
-		if($groupid === '') {
640
+		if ($groupid === '') {
641 641
 			throw new OCSException('', 101);
642 642
 		}
643 643
 
644 644
 		$group = $this->groupManager->get($groupid);
645 645
 		$targetUser = $this->userManager->get($userId);
646
-		if($group === null) {
646
+		if ($group === null) {
647 647
 			throw new OCSException('', 102);
648 648
 		}
649
-		if($targetUser === null) {
649
+		if ($targetUser === null) {
650 650
 			throw new OCSException('', 103);
651 651
 		}
652 652
 
@@ -674,17 +674,17 @@  discard block
 block discarded – undo
674 674
 	public function removeFromGroup(string $userId, string $groupid): DataResponse {
675 675
 		$loggedInUser = $this->userSession->getUser();
676 676
 
677
-		if($groupid === null || trim($groupid) === '') {
677
+		if ($groupid === null || trim($groupid) === '') {
678 678
 			throw new OCSException('', 101);
679 679
 		}
680 680
 
681 681
 		$group = $this->groupManager->get($groupid);
682
-		if($group === null) {
682
+		if ($group === null) {
683 683
 			throw new OCSException('', 102);
684 684
 		}
685 685
 
686 686
 		$targetUser = $this->userManager->get($userId);
687
-		if($targetUser === null) {
687
+		if ($targetUser === null) {
688 688
 			throw new OCSException('', 103);
689 689
 		}
690 690
 
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 		} else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
709 709
 			/** @var IGroup[] $subAdminGroups */
710 710
 			$subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
711
-			$subAdminGroups = array_map(function (IGroup $subAdminGroup) {
711
+			$subAdminGroups = array_map(function(IGroup $subAdminGroup) {
712 712
 				return $subAdminGroup->getGID();
713 713
 			}, $subAdminGroups);
714 714
 			$userGroups = $this->groupManager->getUserGroupIds($targetUser);
@@ -740,15 +740,15 @@  discard block
 block discarded – undo
740 740
 		$user = $this->userManager->get($userId);
741 741
 
742 742
 		// Check if the user exists
743
-		if($user === null) {
743
+		if ($user === null) {
744 744
 			throw new OCSException('User does not exist', 101);
745 745
 		}
746 746
 		// Check if group exists
747
-		if($group === null) {
748
-			throw new OCSException('Group does not exist',  102);
747
+		if ($group === null) {
748
+			throw new OCSException('Group does not exist', 102);
749 749
 		}
750 750
 		// Check if trying to make subadmin of admin group
751
-		if($group->getGID() === 'admin') {
751
+		if ($group->getGID() === 'admin') {
752 752
 			throw new OCSException('Cannot create subadmins for admin group', 103);
753 753
 		}
754 754
 
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 			return new DataResponse();
760 760
 		}
761 761
 		// Go
762
-		if($subAdminManager->createSubAdmin($user, $group)) {
762
+		if ($subAdminManager->createSubAdmin($user, $group)) {
763 763
 			return new DataResponse();
764 764
 		} else {
765 765
 			throw new OCSException('Unknown error occurred', 103);
@@ -782,20 +782,20 @@  discard block
 block discarded – undo
782 782
 		$subAdminManager = $this->groupManager->getSubAdmin();
783 783
 
784 784
 		// Check if the user exists
785
-		if($user === null) {
785
+		if ($user === null) {
786 786
 			throw new OCSException('User does not exist', 101);
787 787
 		}
788 788
 		// Check if the group exists
789
-		if($group === null) {
789
+		if ($group === null) {
790 790
 			throw new OCSException('Group does not exist', 101);
791 791
 		}
792 792
 		// Check if they are a subadmin of this said group
793
-		if(!$subAdminManager->isSubAdminOfGroup($user, $group)) {
793
+		if (!$subAdminManager->isSubAdminOfGroup($user, $group)) {
794 794
 			throw new OCSException('User is not a subadmin of this group', 102);
795 795
 		}
796 796
 
797 797
 		// Go
798
-		if($subAdminManager->deleteSubAdmin($user, $group)) {
798
+		if ($subAdminManager->deleteSubAdmin($user, $group)) {
799 799
 			return new DataResponse();
800 800
 		} else {
801 801
 			throw new OCSException('Unknown error occurred', 103);
@@ -828,13 +828,13 @@  discard block
 block discarded – undo
828 828
 		$currentLoggedInUser = $this->userSession->getUser();
829 829
 
830 830
 		$targetUser = $this->userManager->get($userId);
831
-		if($targetUser === null) {
831
+		if ($targetUser === null) {
832 832
 			throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
833 833
 		}
834 834
 
835 835
 		// Check if admin / subadmin
836 836
 		$subAdminManager = $this->groupManager->getSubAdmin();
837
-		if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
837
+		if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
838 838
 			&& !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
839 839
 			// No rights
840 840
 			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 			$this->newUserMailHelper->setL10N($l10n);
857 857
 			$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
858 858
 			$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
859
-		} catch(\Exception $e) {
859
+		} catch (\Exception $e) {
860 860
 			$this->logger->logException($e, [
861 861
 				'message' => "Can't send new user mail to $email",
862 862
 				'level' => \OCP\Util::ERROR,
Please login to merge, or discard this patch.
Indentation   +801 added lines, -801 removed lines patch added patch discarded remove patch
@@ -52,805 +52,805 @@
 block discarded – undo
52 52
 
53 53
 class UsersController extends AUserData {
54 54
 
55
-	/** @var IAppManager */
56
-	private $appManager;
57
-	/** @var ILogger */
58
-	private $logger;
59
-	/** @var IFactory */
60
-	private $l10nFactory;
61
-	/** @var NewUserMailHelper */
62
-	private $newUserMailHelper;
63
-	/** @var FederatedFileSharingFactory */
64
-	private $federatedFileSharingFactory;
65
-	/** @var ISecureRandom */
66
-	private $secureRandom;
67
-
68
-	/**
69
-	 * @param string $appName
70
-	 * @param IRequest $request
71
-	 * @param IUserManager $userManager
72
-	 * @param IConfig $config
73
-	 * @param IAppManager $appManager
74
-	 * @param IGroupManager $groupManager
75
-	 * @param IUserSession $userSession
76
-	 * @param AccountManager $accountManager
77
-	 * @param ILogger $logger
78
-	 * @param IFactory $l10nFactory
79
-	 * @param NewUserMailHelper $newUserMailHelper
80
-	 * @param FederatedFileSharingFactory $federatedFileSharingFactory
81
-	 * @param ISecureRandom $secureRandom
82
-	 */
83
-	public function __construct(string $appName,
84
-								IRequest $request,
85
-								IUserManager $userManager,
86
-								IConfig $config,
87
-								IAppManager $appManager,
88
-								IGroupManager $groupManager,
89
-								IUserSession $userSession,
90
-								AccountManager $accountManager,
91
-								ILogger $logger,
92
-								IFactory $l10nFactory,
93
-								NewUserMailHelper $newUserMailHelper,
94
-								FederatedFileSharingFactory $federatedFileSharingFactory,
95
-								ISecureRandom $secureRandom) {
96
-		parent::__construct($appName,
97
-							$request,
98
-							$userManager,
99
-							$config,
100
-							$groupManager,
101
-							$userSession,
102
-							$accountManager);
103
-
104
-		$this->appManager = $appManager;
105
-		$this->logger = $logger;
106
-		$this->l10nFactory = $l10nFactory;
107
-		$this->newUserMailHelper = $newUserMailHelper;
108
-		$this->federatedFileSharingFactory = $federatedFileSharingFactory;
109
-		$this->secureRandom = $secureRandom;
110
-	}
111
-
112
-	/**
113
-	 * @NoAdminRequired
114
-	 *
115
-	 * returns a list of users
116
-	 *
117
-	 * @param string $search
118
-	 * @param int $limit
119
-	 * @param int $offset
120
-	 * @return DataResponse
121
-	 */
122
-	public function getUsers(string $search = '', $limit = null, $offset = 0): DataResponse {
123
-		$user = $this->userSession->getUser();
124
-		$users = [];
125
-
126
-		// Admin? Or SubAdmin?
127
-		$uid = $user->getUID();
128
-		$subAdminManager = $this->groupManager->getSubAdmin();
129
-		if($this->groupManager->isAdmin($uid)){
130
-			$users = $this->userManager->search($search, $limit, $offset);
131
-		} else if ($subAdminManager->isSubAdmin($user)) {
132
-			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
133
-			foreach ($subAdminOfGroups as $key => $group) {
134
-				$subAdminOfGroups[$key] = $group->getGID();
135
-			}
136
-
137
-			$users = [];
138
-			foreach ($subAdminOfGroups as $group) {
139
-				$users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
140
-			}
141
-		}
142
-
143
-		$users = array_keys($users);
144
-
145
-		return new DataResponse([
146
-			'users' => $users
147
-		]);
148
-	}
149
-
150
-	/**
151
-	 * @NoAdminRequired
152
-	 *
153
-	 * returns a list of users and their data
154
-	 */
155
-	public function getUsersDetails(string $search = '', $limit = null, $offset = 0): DataResponse {
156
-		$user = $this->userSession->getUser();
157
-		$users = [];
158
-
159
-		// Admin? Or SubAdmin?
160
-		$uid = $user->getUID();
161
-		$subAdminManager = $this->groupManager->getSubAdmin();
162
-		if($this->groupManager->isAdmin($uid)){
163
-			$users = $this->userManager->search($search, $limit, $offset);
164
-		} else if ($subAdminManager->isSubAdmin($user)) {
165
-			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
166
-			foreach ($subAdminOfGroups as $key => $group) {
167
-				$subAdminOfGroups[$key] = $group->getGID();
168
-			}
169
-
170
-			$users = [];
171
-			foreach ($subAdminOfGroups as $group) {
172
-				$users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
173
-			}
174
-		}
175
-
176
-		$users = array_keys($users);
177
-		$usersDetails = [];
178
-		foreach ($users as $key => $userId) {
179
-			$userData = $this->getUserData($userId);
180
-			// Do not insert empty entry
181
-			if(!empty($userData)) {
182
-				$usersDetails[$userId] = $userData;
183
-			}
184
-		}
185
-
186
-		return new DataResponse([
187
-			'users' => $usersDetails
188
-		]);
189
-	}
190
-
191
-	/**
192
-	 * @PasswordConfirmationRequired
193
-	 * @NoAdminRequired
194
-	 *
195
-	 * @param string $userid
196
-	 * @param string $password
197
-	 * @param string $email
198
-	 * @param array $groups
199
-	 * @return DataResponse
200
-	 * @throws OCSException
201
-	 */
202
-	public function addUser(string $userid, string $password = '', string $email='', array $groups = []): DataResponse {
203
-		$user = $this->userSession->getUser();
204
-		$isAdmin = $this->groupManager->isAdmin($user->getUID());
205
-		$subAdminManager = $this->groupManager->getSubAdmin();
206
-
207
-		if($this->userManager->userExists($userid)) {
208
-			$this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
209
-			throw new OCSException('User already exists', 102);
210
-		}
211
-
212
-		if($groups !== []) {
213
-			foreach ($groups as $group) {
214
-				if(!$this->groupManager->groupExists($group)) {
215
-					throw new OCSException('group '.$group.' does not exist', 104);
216
-				}
217
-				if(!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
218
-					throw new OCSException('insufficient privileges for group '. $group, 105);
219
-				}
220
-			}
221
-		} else {
222
-			if(!$isAdmin) {
223
-				throw new OCSException('no group specified (required for subadmins)', 106);
224
-			}
225
-		}
226
-
227
-		$generatePasswordResetToken = false;
228
-		if ($password === '') {
229
-			if ($email === '') {
230
-				throw new OCSException('To send a password link to the user an email address is required.', 108);
231
-			}
232
-
233
-			$password = $this->secureRandom->generate(10);
234
-			// Make sure we pass the password_policy
235
-			$password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()');
236
-			$generatePasswordResetToken = true;
237
-		}
238
-
239
-		try {
240
-			$newUser = $this->userManager->createUser($userid, $password);
241
-			$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
242
-
243
-			foreach ($groups as $group) {
244
-				$this->groupManager->get($group)->addUser($newUser);
245
-				$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
246
-			}
247
-
248
-			// Send new user mail only if a mail is set
249
-			if ($email !== '') {
250
-				$newUser->setEMailAddress($email);
251
-				try {
252
-					$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
253
-					$this->newUserMailHelper->sendMail($newUser, $emailTemplate);
254
-				} catch (\Exception $e) {
255
-					$this->logger->logException($e, [
256
-						'message' => "Can't send new user mail to $email",
257
-						'level' => \OCP\Util::ERROR,
258
-						'app' => 'ocs_api',
259
-					]);
260
-					throw new OCSException('Unable to send the invitation mail', 109);
261
-				}
262
-			}
263
-
264
-			return new DataResponse();
265
-
266
-		} catch (HintException $e ) {
267
-			$this->logger->logException($e, [
268
-				'message' => 'Failed addUser attempt with hint exception.',
269
-				'level' => \OCP\Util::WARN,
270
-				'app' => 'ocs_api',
271
-			]);
272
-			throw new OCSException($e->getHint(), 107);
273
-		} catch (\Exception $e) {
274
-			$this->logger->logException($e, [
275
-				'message' => 'Failed addUser attempt with exception.',
276
-				'level' => \OCP\Util::ERROR,
277
-				'app' => 'ocs_api',
278
-			]);
279
-			throw new OCSException('Bad request', 101);
280
-		}
281
-	}
282
-
283
-	/**
284
-	 * @NoAdminRequired
285
-	 * @NoSubAdminRequired
286
-	 *
287
-	 * gets user info
288
-	 *
289
-	 * @param string $userId
290
-	 * @return DataResponse
291
-	 * @throws OCSException
292
-	 */
293
-	public function getUser(string $userId): DataResponse {
294
-		$data = $this->getUserData($userId);
295
-		// getUserData returns empty array if not enough permissions
296
-		if(empty($data)) {
297
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
298
-		}
299
-		return new DataResponse($data);
300
-	}
301
-
302
-	/**
303
-	 * @NoAdminRequired
304
-	 * @NoSubAdminRequired
305
-	 *
306
-	 * gets user info from the currently logged in user
307
-	 *
308
-	 * @return DataResponse
309
-	 * @throws OCSException
310
-	 */
311
-	public function getCurrentUser(): DataResponse {
312
-		$user = $this->userSession->getUser();
313
-		if ($user) {
314
-			$data =  $this->getUserData($user->getUID());
315
-			// rename "displayname" to "display-name" only for this call to keep
316
-			// the API stable.
317
-			$data['display-name'] = $data['displayname'];
318
-			unset($data['displayname']);
319
-			return new DataResponse($data);
320
-
321
-		}
322
-
323
-		throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
324
-	}
325
-
326
-	/**
327
-	 * @NoAdminRequired
328
-	 * @NoSubAdminRequired
329
-	 */
330
-	public function getEditableFields(): DataResponse {
331
-		$permittedFields = [];
332
-
333
-		// Editing self (display, email)
334
-		if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
335
-			$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
336
-			$permittedFields[] = AccountManager::PROPERTY_EMAIL;
337
-		}
338
-
339
-		if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
340
-			$federatedFileSharing = $this->federatedFileSharingFactory->get();
341
-			$shareProvider = $federatedFileSharing->getFederatedShareProvider();
342
-			if ($shareProvider->isLookupServerUploadEnabled()) {
343
-				$permittedFields[] = AccountManager::PROPERTY_PHONE;
344
-				$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
345
-				$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
346
-				$permittedFields[] = AccountManager::PROPERTY_TWITTER;
347
-			}
348
-		}
349
-
350
-		return new DataResponse($permittedFields);
351
-	}
352
-
353
-	/**
354
-	 * @NoAdminRequired
355
-	 * @NoSubAdminRequired
356
-	 * @PasswordConfirmationRequired
357
-	 *
358
-	 * edit users
359
-	 *
360
-	 * @param string $userId
361
-	 * @param string $key
362
-	 * @param string $value
363
-	 * @return DataResponse
364
-	 * @throws OCSException
365
-	 */
366
-	public function editUser(string $userId, string $key, string $value): DataResponse {
367
-		$currentLoggedInUser = $this->userSession->getUser();
368
-
369
-		$targetUser = $this->userManager->get($userId);
370
-		if($targetUser === null) {
371
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
372
-		}
373
-
374
-		$permittedFields = [];
375
-		if($targetUser->getUID() === $currentLoggedInUser->getUID()) {
376
-			// Editing self (display, email)
377
-			if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
378
-				$permittedFields[] = 'display';
379
-				$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
380
-				$permittedFields[] = AccountManager::PROPERTY_EMAIL;
381
-			}
382
-
383
-			$permittedFields[] = 'password';
384
-			if ($this->config->getSystemValue('force_language', false) === false ||
385
-				$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
386
-				$permittedFields[] = 'language';
387
-			}
388
-
389
-			if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
390
-				$federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
391
-				$shareProvider = $federatedFileSharing->getFederatedShareProvider();
392
-				if ($shareProvider->isLookupServerUploadEnabled()) {
393
-					$permittedFields[] = AccountManager::PROPERTY_PHONE;
394
-					$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
395
-					$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
396
-					$permittedFields[] = AccountManager::PROPERTY_TWITTER;
397
-				}
398
-			}
399
-
400
-			// If admin they can edit their own quota
401
-			if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
402
-				$permittedFields[] = 'quota';
403
-			}
404
-		} else {
405
-			// Check if admin / subadmin
406
-			$subAdminManager = $this->groupManager->getSubAdmin();
407
-			if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
408
-			|| $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
409
-				// They have permissions over the user
410
-				$permittedFields[] = 'display';
411
-				$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
412
-				$permittedFields[] = AccountManager::PROPERTY_EMAIL;
413
-				$permittedFields[] = 'password';
414
-				$permittedFields[] = 'language';
415
-				$permittedFields[] = AccountManager::PROPERTY_PHONE;
416
-				$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
417
-				$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
418
-				$permittedFields[] = AccountManager::PROPERTY_TWITTER;
419
-				$permittedFields[] = 'quota';
420
-			} else {
421
-				// No rights
422
-				throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
423
-			}
424
-		}
425
-		// Check if permitted to edit this field
426
-		if(!in_array($key, $permittedFields)) {
427
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
428
-		}
429
-		// Process the edit
430
-		switch($key) {
431
-			case 'display':
432
-			case AccountManager::PROPERTY_DISPLAYNAME:
433
-				$targetUser->setDisplayName($value);
434
-				break;
435
-			case 'quota':
436
-				$quota = $value;
437
-				if($quota !== 'none' && $quota !== 'default') {
438
-					if (is_numeric($quota)) {
439
-						$quota = (float) $quota;
440
-					} else {
441
-						$quota = \OCP\Util::computerFileSize($quota);
442
-					}
443
-					if ($quota === false) {
444
-						throw new OCSException('Invalid quota value '.$value, 103);
445
-					}
446
-					if($quota === 0) {
447
-						$quota = 'default';
448
-					}else if($quota === -1) {
449
-						$quota = 'none';
450
-					} else {
451
-						$quota = \OCP\Util::humanFileSize($quota);
452
-					}
453
-				}
454
-				$targetUser->setQuota($quota);
455
-				break;
456
-			case 'password':
457
-				$targetUser->setPassword($value);
458
-				break;
459
-			case 'language':
460
-				$languagesCodes = $this->l10nFactory->findAvailableLanguages();
461
-				if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
462
-					throw new OCSException('Invalid language', 102);
463
-				}
464
-				$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
465
-				break;
466
-			case AccountManager::PROPERTY_EMAIL:
467
-				if(filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
468
-					$targetUser->setEMailAddress($value);
469
-				} else {
470
-					throw new OCSException('', 102);
471
-				}
472
-				break;
473
-			case AccountManager::PROPERTY_PHONE:
474
-			case AccountManager::PROPERTY_ADDRESS:
475
-			case AccountManager::PROPERTY_WEBSITE:
476
-			case AccountManager::PROPERTY_TWITTER:
477
-				$userAccount = $this->accountManager->getUser($targetUser);
478
-				if ($userAccount[$key]['value'] !== $value) {
479
-					$userAccount[$key]['value'] = $value;
480
-					$this->accountManager->updateUser($targetUser, $userAccount);
481
-				}
482
-				break;
483
-			default:
484
-				throw new OCSException('', 103);
485
-		}
486
-		return new DataResponse();
487
-	}
488
-
489
-	/**
490
-	 * @PasswordConfirmationRequired
491
-	 * @NoAdminRequired
492
-	 *
493
-	 * @param string $userId
494
-	 * @return DataResponse
495
-	 * @throws OCSException
496
-	 */
497
-	public function deleteUser(string $userId): DataResponse {
498
-		$currentLoggedInUser = $this->userSession->getUser();
499
-
500
-		$targetUser = $this->userManager->get($userId);
501
-
502
-		if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
503
-			throw new OCSException('', 101);
504
-		}
505
-
506
-		// If not permitted
507
-		$subAdminManager = $this->groupManager->getSubAdmin();
508
-		if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
509
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
510
-		}
511
-
512
-		// Go ahead with the delete
513
-		if($targetUser->delete()) {
514
-			return new DataResponse();
515
-		} else {
516
-			throw new OCSException('', 101);
517
-		}
518
-	}
519
-
520
-	/**
521
-	 * @PasswordConfirmationRequired
522
-	 * @NoAdminRequired
523
-	 *
524
-	 * @param string $userId
525
-	 * @return DataResponse
526
-	 * @throws OCSException
527
-	 * @throws OCSForbiddenException
528
-	 */
529
-	public function disableUser(string $userId): DataResponse {
530
-		return $this->setEnabled($userId, false);
531
-	}
532
-
533
-	/**
534
-	 * @PasswordConfirmationRequired
535
-	 * @NoAdminRequired
536
-	 *
537
-	 * @param string $userId
538
-	 * @return DataResponse
539
-	 * @throws OCSException
540
-	 * @throws OCSForbiddenException
541
-	 */
542
-	public function enableUser(string $userId): DataResponse {
543
-		return $this->setEnabled($userId, true);
544
-	}
545
-
546
-	/**
547
-	 * @param string $userId
548
-	 * @param bool $value
549
-	 * @return DataResponse
550
-	 * @throws OCSException
551
-	 */
552
-	private function setEnabled(string $userId, bool $value): DataResponse {
553
-		$currentLoggedInUser = $this->userSession->getUser();
554
-
555
-		$targetUser = $this->userManager->get($userId);
556
-		if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
557
-			throw new OCSException('', 101);
558
-		}
559
-
560
-		// If not permitted
561
-		$subAdminManager = $this->groupManager->getSubAdmin();
562
-		if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
563
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
564
-		}
565
-
566
-		// enable/disable the user now
567
-		$targetUser->setEnabled($value);
568
-		return new DataResponse();
569
-	}
570
-
571
-	/**
572
-	 * @NoAdminRequired
573
-	 * @NoSubAdminRequired
574
-	 *
575
-	 * @param string $userId
576
-	 * @return DataResponse
577
-	 * @throws OCSException
578
-	 */
579
-	public function getUsersGroups(string $userId): DataResponse {
580
-		$loggedInUser = $this->userSession->getUser();
581
-
582
-		$targetUser = $this->userManager->get($userId);
583
-		if($targetUser === null) {
584
-			throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
585
-		}
586
-
587
-		if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
588
-			// Self lookup or admin lookup
589
-			return new DataResponse([
590
-				'groups' => $this->groupManager->getUserGroupIds($targetUser)
591
-			]);
592
-		} else {
593
-			$subAdminManager = $this->groupManager->getSubAdmin();
594
-
595
-			// Looking up someone else
596
-			if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
597
-				// Return the group that the method caller is subadmin of for the user in question
598
-				/** @var IGroup[] $getSubAdminsGroups */
599
-				$getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
600
-				foreach ($getSubAdminsGroups as $key => $group) {
601
-					$getSubAdminsGroups[$key] = $group->getGID();
602
-				}
603
-				$groups = array_intersect(
604
-					$getSubAdminsGroups,
605
-					$this->groupManager->getUserGroupIds($targetUser)
606
-				);
607
-				return new DataResponse(['groups' => $groups]);
608
-			} else {
609
-				// Not permitted
610
-				throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
611
-			}
612
-		}
613
-
614
-	}
615
-
616
-	/**
617
-	 * @PasswordConfirmationRequired
618
-	 * @NoAdminRequired
619
-	 *
620
-	 * @param string $userId
621
-	 * @param string $groupid
622
-	 * @return DataResponse
623
-	 * @throws OCSException
624
-	 */
625
-	public function addToGroup(string $userId, string $groupid = ''): DataResponse {
626
-		if($groupid === '') {
627
-			throw new OCSException('', 101);
628
-		}
629
-
630
-		$group = $this->groupManager->get($groupid);
631
-		$targetUser = $this->userManager->get($userId);
632
-		if($group === null) {
633
-			throw new OCSException('', 102);
634
-		}
635
-		if($targetUser === null) {
636
-			throw new OCSException('', 103);
637
-		}
638
-
639
-		// If they're not an admin, check they are a subadmin of the group in question
640
-		$loggedInUser = $this->userSession->getUser();
641
-		$subAdminManager = $this->groupManager->getSubAdmin();
642
-		if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
643
-			throw new OCSException('', 104);
644
-		}
645
-
646
-		// Add user to group
647
-		$group->addUser($targetUser);
648
-		return new DataResponse();
649
-	}
650
-
651
-	/**
652
-	 * @PasswordConfirmationRequired
653
-	 * @NoAdminRequired
654
-	 *
655
-	 * @param string $userId
656
-	 * @param string $groupid
657
-	 * @return DataResponse
658
-	 * @throws OCSException
659
-	 */
660
-	public function removeFromGroup(string $userId, string $groupid): DataResponse {
661
-		$loggedInUser = $this->userSession->getUser();
662
-
663
-		if($groupid === null || trim($groupid) === '') {
664
-			throw new OCSException('', 101);
665
-		}
666
-
667
-		$group = $this->groupManager->get($groupid);
668
-		if($group === null) {
669
-			throw new OCSException('', 102);
670
-		}
671
-
672
-		$targetUser = $this->userManager->get($userId);
673
-		if($targetUser === null) {
674
-			throw new OCSException('', 103);
675
-		}
676
-
677
-		// If they're not an admin, check they are a subadmin of the group in question
678
-		$subAdminManager = $this->groupManager->getSubAdmin();
679
-		if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
680
-			throw new OCSException('', 104);
681
-		}
682
-
683
-		// Check they aren't removing themselves from 'admin' or their 'subadmin; group
684
-		if ($targetUser->getUID() === $loggedInUser->getUID()) {
685
-			if ($this->groupManager->isAdmin($loggedInUser->getUID())) {
686
-				if ($group->getGID() === 'admin') {
687
-					throw new OCSException('Cannot remove yourself from the admin group', 105);
688
-				}
689
-			} else {
690
-				// Not an admin, so the user must be a subadmin of this group, but that is not allowed.
691
-				throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105);
692
-			}
693
-
694
-		} else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
695
-			/** @var IGroup[] $subAdminGroups */
696
-			$subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
697
-			$subAdminGroups = array_map(function (IGroup $subAdminGroup) {
698
-				return $subAdminGroup->getGID();
699
-			}, $subAdminGroups);
700
-			$userGroups = $this->groupManager->getUserGroupIds($targetUser);
701
-			$userSubAdminGroups = array_intersect($subAdminGroups, $userGroups);
702
-
703
-			if (count($userSubAdminGroups) <= 1) {
704
-				// Subadmin must not be able to remove a user from all their subadmin groups.
705
-				throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105);
706
-			}
707
-		}
708
-
709
-		// Remove user from group
710
-		$group->removeUser($targetUser);
711
-		return new DataResponse();
712
-	}
713
-
714
-	/**
715
-	 * Creates a subadmin
716
-	 *
717
-	 * @PasswordConfirmationRequired
718
-	 *
719
-	 * @param string $userId
720
-	 * @param string $groupid
721
-	 * @return DataResponse
722
-	 * @throws OCSException
723
-	 */
724
-	public function addSubAdmin(string $userId, string $groupid): DataResponse {
725
-		$group = $this->groupManager->get($groupid);
726
-		$user = $this->userManager->get($userId);
727
-
728
-		// Check if the user exists
729
-		if($user === null) {
730
-			throw new OCSException('User does not exist', 101);
731
-		}
732
-		// Check if group exists
733
-		if($group === null) {
734
-			throw new OCSException('Group does not exist',  102);
735
-		}
736
-		// Check if trying to make subadmin of admin group
737
-		if($group->getGID() === 'admin') {
738
-			throw new OCSException('Cannot create subadmins for admin group', 103);
739
-		}
740
-
741
-		$subAdminManager = $this->groupManager->getSubAdmin();
742
-
743
-		// We cannot be subadmin twice
744
-		if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
745
-			return new DataResponse();
746
-		}
747
-		// Go
748
-		if($subAdminManager->createSubAdmin($user, $group)) {
749
-			return new DataResponse();
750
-		} else {
751
-			throw new OCSException('Unknown error occurred', 103);
752
-		}
753
-	}
754
-
755
-	/**
756
-	 * Removes a subadmin from a group
757
-	 *
758
-	 * @PasswordConfirmationRequired
759
-	 *
760
-	 * @param string $userId
761
-	 * @param string $groupid
762
-	 * @return DataResponse
763
-	 * @throws OCSException
764
-	 */
765
-	public function removeSubAdmin(string $userId, string $groupid): DataResponse {
766
-		$group = $this->groupManager->get($groupid);
767
-		$user = $this->userManager->get($userId);
768
-		$subAdminManager = $this->groupManager->getSubAdmin();
769
-
770
-		// Check if the user exists
771
-		if($user === null) {
772
-			throw new OCSException('User does not exist', 101);
773
-		}
774
-		// Check if the group exists
775
-		if($group === null) {
776
-			throw new OCSException('Group does not exist', 101);
777
-		}
778
-		// Check if they are a subadmin of this said group
779
-		if(!$subAdminManager->isSubAdminOfGroup($user, $group)) {
780
-			throw new OCSException('User is not a subadmin of this group', 102);
781
-		}
782
-
783
-		// Go
784
-		if($subAdminManager->deleteSubAdmin($user, $group)) {
785
-			return new DataResponse();
786
-		} else {
787
-			throw new OCSException('Unknown error occurred', 103);
788
-		}
789
-	}
790
-
791
-	/**
792
-	 * Get the groups a user is a subadmin of
793
-	 *
794
-	 * @param string $userId
795
-	 * @return DataResponse
796
-	 * @throws OCSException
797
-	 */
798
-	public function getUserSubAdminGroups(string $userId): DataResponse {
799
-		$groups = $this->getUserSubAdminGroupsData($userId);
800
-		return new DataResponse($groups);
801
-	}
802
-
803
-	/**
804
-	 * @NoAdminRequired
805
-	 * @PasswordConfirmationRequired
806
-	 *
807
-	 * resend welcome message
808
-	 *
809
-	 * @param string $userId
810
-	 * @return DataResponse
811
-	 * @throws OCSException
812
-	 */
813
-	public function resendWelcomeMessage(string $userId): DataResponse {
814
-		$currentLoggedInUser = $this->userSession->getUser();
815
-
816
-		$targetUser = $this->userManager->get($userId);
817
-		if($targetUser === null) {
818
-			throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
819
-		}
820
-
821
-		// Check if admin / subadmin
822
-		$subAdminManager = $this->groupManager->getSubAdmin();
823
-		if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
824
-			&& !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
825
-			// No rights
826
-			throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
827
-		}
828
-
829
-		$email = $targetUser->getEMailAddress();
830
-		if ($email === '' || $email === null) {
831
-			throw new OCSException('Email address not available', 101);
832
-		}
833
-		$username = $targetUser->getUID();
834
-		$lang = $this->config->getUserValue($username, 'core', 'lang', 'en');
835
-		if (!$this->l10nFactory->languageExists('settings', $lang)) {
836
-			$lang = 'en';
837
-		}
838
-
839
-		$l10n = $this->l10nFactory->get('settings', $lang);
840
-
841
-		try {
842
-			$this->newUserMailHelper->setL10N($l10n);
843
-			$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
844
-			$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
845
-		} catch(\Exception $e) {
846
-			$this->logger->logException($e, [
847
-				'message' => "Can't send new user mail to $email",
848
-				'level' => \OCP\Util::ERROR,
849
-				'app' => 'settings',
850
-			]);
851
-			throw new OCSException('Sending email failed', 102);
852
-		}
853
-
854
-		return new DataResponse();
855
-	}
55
+    /** @var IAppManager */
56
+    private $appManager;
57
+    /** @var ILogger */
58
+    private $logger;
59
+    /** @var IFactory */
60
+    private $l10nFactory;
61
+    /** @var NewUserMailHelper */
62
+    private $newUserMailHelper;
63
+    /** @var FederatedFileSharingFactory */
64
+    private $federatedFileSharingFactory;
65
+    /** @var ISecureRandom */
66
+    private $secureRandom;
67
+
68
+    /**
69
+     * @param string $appName
70
+     * @param IRequest $request
71
+     * @param IUserManager $userManager
72
+     * @param IConfig $config
73
+     * @param IAppManager $appManager
74
+     * @param IGroupManager $groupManager
75
+     * @param IUserSession $userSession
76
+     * @param AccountManager $accountManager
77
+     * @param ILogger $logger
78
+     * @param IFactory $l10nFactory
79
+     * @param NewUserMailHelper $newUserMailHelper
80
+     * @param FederatedFileSharingFactory $federatedFileSharingFactory
81
+     * @param ISecureRandom $secureRandom
82
+     */
83
+    public function __construct(string $appName,
84
+                                IRequest $request,
85
+                                IUserManager $userManager,
86
+                                IConfig $config,
87
+                                IAppManager $appManager,
88
+                                IGroupManager $groupManager,
89
+                                IUserSession $userSession,
90
+                                AccountManager $accountManager,
91
+                                ILogger $logger,
92
+                                IFactory $l10nFactory,
93
+                                NewUserMailHelper $newUserMailHelper,
94
+                                FederatedFileSharingFactory $federatedFileSharingFactory,
95
+                                ISecureRandom $secureRandom) {
96
+        parent::__construct($appName,
97
+                            $request,
98
+                            $userManager,
99
+                            $config,
100
+                            $groupManager,
101
+                            $userSession,
102
+                            $accountManager);
103
+
104
+        $this->appManager = $appManager;
105
+        $this->logger = $logger;
106
+        $this->l10nFactory = $l10nFactory;
107
+        $this->newUserMailHelper = $newUserMailHelper;
108
+        $this->federatedFileSharingFactory = $federatedFileSharingFactory;
109
+        $this->secureRandom = $secureRandom;
110
+    }
111
+
112
+    /**
113
+     * @NoAdminRequired
114
+     *
115
+     * returns a list of users
116
+     *
117
+     * @param string $search
118
+     * @param int $limit
119
+     * @param int $offset
120
+     * @return DataResponse
121
+     */
122
+    public function getUsers(string $search = '', $limit = null, $offset = 0): DataResponse {
123
+        $user = $this->userSession->getUser();
124
+        $users = [];
125
+
126
+        // Admin? Or SubAdmin?
127
+        $uid = $user->getUID();
128
+        $subAdminManager = $this->groupManager->getSubAdmin();
129
+        if($this->groupManager->isAdmin($uid)){
130
+            $users = $this->userManager->search($search, $limit, $offset);
131
+        } else if ($subAdminManager->isSubAdmin($user)) {
132
+            $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
133
+            foreach ($subAdminOfGroups as $key => $group) {
134
+                $subAdminOfGroups[$key] = $group->getGID();
135
+            }
136
+
137
+            $users = [];
138
+            foreach ($subAdminOfGroups as $group) {
139
+                $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
140
+            }
141
+        }
142
+
143
+        $users = array_keys($users);
144
+
145
+        return new DataResponse([
146
+            'users' => $users
147
+        ]);
148
+    }
149
+
150
+    /**
151
+     * @NoAdminRequired
152
+     *
153
+     * returns a list of users and their data
154
+     */
155
+    public function getUsersDetails(string $search = '', $limit = null, $offset = 0): DataResponse {
156
+        $user = $this->userSession->getUser();
157
+        $users = [];
158
+
159
+        // Admin? Or SubAdmin?
160
+        $uid = $user->getUID();
161
+        $subAdminManager = $this->groupManager->getSubAdmin();
162
+        if($this->groupManager->isAdmin($uid)){
163
+            $users = $this->userManager->search($search, $limit, $offset);
164
+        } else if ($subAdminManager->isSubAdmin($user)) {
165
+            $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
166
+            foreach ($subAdminOfGroups as $key => $group) {
167
+                $subAdminOfGroups[$key] = $group->getGID();
168
+            }
169
+
170
+            $users = [];
171
+            foreach ($subAdminOfGroups as $group) {
172
+                $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
173
+            }
174
+        }
175
+
176
+        $users = array_keys($users);
177
+        $usersDetails = [];
178
+        foreach ($users as $key => $userId) {
179
+            $userData = $this->getUserData($userId);
180
+            // Do not insert empty entry
181
+            if(!empty($userData)) {
182
+                $usersDetails[$userId] = $userData;
183
+            }
184
+        }
185
+
186
+        return new DataResponse([
187
+            'users' => $usersDetails
188
+        ]);
189
+    }
190
+
191
+    /**
192
+     * @PasswordConfirmationRequired
193
+     * @NoAdminRequired
194
+     *
195
+     * @param string $userid
196
+     * @param string $password
197
+     * @param string $email
198
+     * @param array $groups
199
+     * @return DataResponse
200
+     * @throws OCSException
201
+     */
202
+    public function addUser(string $userid, string $password = '', string $email='', array $groups = []): DataResponse {
203
+        $user = $this->userSession->getUser();
204
+        $isAdmin = $this->groupManager->isAdmin($user->getUID());
205
+        $subAdminManager = $this->groupManager->getSubAdmin();
206
+
207
+        if($this->userManager->userExists($userid)) {
208
+            $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
209
+            throw new OCSException('User already exists', 102);
210
+        }
211
+
212
+        if($groups !== []) {
213
+            foreach ($groups as $group) {
214
+                if(!$this->groupManager->groupExists($group)) {
215
+                    throw new OCSException('group '.$group.' does not exist', 104);
216
+                }
217
+                if(!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
218
+                    throw new OCSException('insufficient privileges for group '. $group, 105);
219
+                }
220
+            }
221
+        } else {
222
+            if(!$isAdmin) {
223
+                throw new OCSException('no group specified (required for subadmins)', 106);
224
+            }
225
+        }
226
+
227
+        $generatePasswordResetToken = false;
228
+        if ($password === '') {
229
+            if ($email === '') {
230
+                throw new OCSException('To send a password link to the user an email address is required.', 108);
231
+            }
232
+
233
+            $password = $this->secureRandom->generate(10);
234
+            // Make sure we pass the password_policy
235
+            $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()');
236
+            $generatePasswordResetToken = true;
237
+        }
238
+
239
+        try {
240
+            $newUser = $this->userManager->createUser($userid, $password);
241
+            $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
242
+
243
+            foreach ($groups as $group) {
244
+                $this->groupManager->get($group)->addUser($newUser);
245
+                $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
246
+            }
247
+
248
+            // Send new user mail only if a mail is set
249
+            if ($email !== '') {
250
+                $newUser->setEMailAddress($email);
251
+                try {
252
+                    $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
253
+                    $this->newUserMailHelper->sendMail($newUser, $emailTemplate);
254
+                } catch (\Exception $e) {
255
+                    $this->logger->logException($e, [
256
+                        'message' => "Can't send new user mail to $email",
257
+                        'level' => \OCP\Util::ERROR,
258
+                        'app' => 'ocs_api',
259
+                    ]);
260
+                    throw new OCSException('Unable to send the invitation mail', 109);
261
+                }
262
+            }
263
+
264
+            return new DataResponse();
265
+
266
+        } catch (HintException $e ) {
267
+            $this->logger->logException($e, [
268
+                'message' => 'Failed addUser attempt with hint exception.',
269
+                'level' => \OCP\Util::WARN,
270
+                'app' => 'ocs_api',
271
+            ]);
272
+            throw new OCSException($e->getHint(), 107);
273
+        } catch (\Exception $e) {
274
+            $this->logger->logException($e, [
275
+                'message' => 'Failed addUser attempt with exception.',
276
+                'level' => \OCP\Util::ERROR,
277
+                'app' => 'ocs_api',
278
+            ]);
279
+            throw new OCSException('Bad request', 101);
280
+        }
281
+    }
282
+
283
+    /**
284
+     * @NoAdminRequired
285
+     * @NoSubAdminRequired
286
+     *
287
+     * gets user info
288
+     *
289
+     * @param string $userId
290
+     * @return DataResponse
291
+     * @throws OCSException
292
+     */
293
+    public function getUser(string $userId): DataResponse {
294
+        $data = $this->getUserData($userId);
295
+        // getUserData returns empty array if not enough permissions
296
+        if(empty($data)) {
297
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
298
+        }
299
+        return new DataResponse($data);
300
+    }
301
+
302
+    /**
303
+     * @NoAdminRequired
304
+     * @NoSubAdminRequired
305
+     *
306
+     * gets user info from the currently logged in user
307
+     *
308
+     * @return DataResponse
309
+     * @throws OCSException
310
+     */
311
+    public function getCurrentUser(): DataResponse {
312
+        $user = $this->userSession->getUser();
313
+        if ($user) {
314
+            $data =  $this->getUserData($user->getUID());
315
+            // rename "displayname" to "display-name" only for this call to keep
316
+            // the API stable.
317
+            $data['display-name'] = $data['displayname'];
318
+            unset($data['displayname']);
319
+            return new DataResponse($data);
320
+
321
+        }
322
+
323
+        throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
324
+    }
325
+
326
+    /**
327
+     * @NoAdminRequired
328
+     * @NoSubAdminRequired
329
+     */
330
+    public function getEditableFields(): DataResponse {
331
+        $permittedFields = [];
332
+
333
+        // Editing self (display, email)
334
+        if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
335
+            $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
336
+            $permittedFields[] = AccountManager::PROPERTY_EMAIL;
337
+        }
338
+
339
+        if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
340
+            $federatedFileSharing = $this->federatedFileSharingFactory->get();
341
+            $shareProvider = $federatedFileSharing->getFederatedShareProvider();
342
+            if ($shareProvider->isLookupServerUploadEnabled()) {
343
+                $permittedFields[] = AccountManager::PROPERTY_PHONE;
344
+                $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
345
+                $permittedFields[] = AccountManager::PROPERTY_WEBSITE;
346
+                $permittedFields[] = AccountManager::PROPERTY_TWITTER;
347
+            }
348
+        }
349
+
350
+        return new DataResponse($permittedFields);
351
+    }
352
+
353
+    /**
354
+     * @NoAdminRequired
355
+     * @NoSubAdminRequired
356
+     * @PasswordConfirmationRequired
357
+     *
358
+     * edit users
359
+     *
360
+     * @param string $userId
361
+     * @param string $key
362
+     * @param string $value
363
+     * @return DataResponse
364
+     * @throws OCSException
365
+     */
366
+    public function editUser(string $userId, string $key, string $value): DataResponse {
367
+        $currentLoggedInUser = $this->userSession->getUser();
368
+
369
+        $targetUser = $this->userManager->get($userId);
370
+        if($targetUser === null) {
371
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
372
+        }
373
+
374
+        $permittedFields = [];
375
+        if($targetUser->getUID() === $currentLoggedInUser->getUID()) {
376
+            // Editing self (display, email)
377
+            if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
378
+                $permittedFields[] = 'display';
379
+                $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
380
+                $permittedFields[] = AccountManager::PROPERTY_EMAIL;
381
+            }
382
+
383
+            $permittedFields[] = 'password';
384
+            if ($this->config->getSystemValue('force_language', false) === false ||
385
+                $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
386
+                $permittedFields[] = 'language';
387
+            }
388
+
389
+            if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
390
+                $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
391
+                $shareProvider = $federatedFileSharing->getFederatedShareProvider();
392
+                if ($shareProvider->isLookupServerUploadEnabled()) {
393
+                    $permittedFields[] = AccountManager::PROPERTY_PHONE;
394
+                    $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
395
+                    $permittedFields[] = AccountManager::PROPERTY_WEBSITE;
396
+                    $permittedFields[] = AccountManager::PROPERTY_TWITTER;
397
+                }
398
+            }
399
+
400
+            // If admin they can edit their own quota
401
+            if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
402
+                $permittedFields[] = 'quota';
403
+            }
404
+        } else {
405
+            // Check if admin / subadmin
406
+            $subAdminManager = $this->groupManager->getSubAdmin();
407
+            if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
408
+            || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
409
+                // They have permissions over the user
410
+                $permittedFields[] = 'display';
411
+                $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
412
+                $permittedFields[] = AccountManager::PROPERTY_EMAIL;
413
+                $permittedFields[] = 'password';
414
+                $permittedFields[] = 'language';
415
+                $permittedFields[] = AccountManager::PROPERTY_PHONE;
416
+                $permittedFields[] = AccountManager::PROPERTY_ADDRESS;
417
+                $permittedFields[] = AccountManager::PROPERTY_WEBSITE;
418
+                $permittedFields[] = AccountManager::PROPERTY_TWITTER;
419
+                $permittedFields[] = 'quota';
420
+            } else {
421
+                // No rights
422
+                throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
423
+            }
424
+        }
425
+        // Check if permitted to edit this field
426
+        if(!in_array($key, $permittedFields)) {
427
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
428
+        }
429
+        // Process the edit
430
+        switch($key) {
431
+            case 'display':
432
+            case AccountManager::PROPERTY_DISPLAYNAME:
433
+                $targetUser->setDisplayName($value);
434
+                break;
435
+            case 'quota':
436
+                $quota = $value;
437
+                if($quota !== 'none' && $quota !== 'default') {
438
+                    if (is_numeric($quota)) {
439
+                        $quota = (float) $quota;
440
+                    } else {
441
+                        $quota = \OCP\Util::computerFileSize($quota);
442
+                    }
443
+                    if ($quota === false) {
444
+                        throw new OCSException('Invalid quota value '.$value, 103);
445
+                    }
446
+                    if($quota === 0) {
447
+                        $quota = 'default';
448
+                    }else if($quota === -1) {
449
+                        $quota = 'none';
450
+                    } else {
451
+                        $quota = \OCP\Util::humanFileSize($quota);
452
+                    }
453
+                }
454
+                $targetUser->setQuota($quota);
455
+                break;
456
+            case 'password':
457
+                $targetUser->setPassword($value);
458
+                break;
459
+            case 'language':
460
+                $languagesCodes = $this->l10nFactory->findAvailableLanguages();
461
+                if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
462
+                    throw new OCSException('Invalid language', 102);
463
+                }
464
+                $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
465
+                break;
466
+            case AccountManager::PROPERTY_EMAIL:
467
+                if(filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
468
+                    $targetUser->setEMailAddress($value);
469
+                } else {
470
+                    throw new OCSException('', 102);
471
+                }
472
+                break;
473
+            case AccountManager::PROPERTY_PHONE:
474
+            case AccountManager::PROPERTY_ADDRESS:
475
+            case AccountManager::PROPERTY_WEBSITE:
476
+            case AccountManager::PROPERTY_TWITTER:
477
+                $userAccount = $this->accountManager->getUser($targetUser);
478
+                if ($userAccount[$key]['value'] !== $value) {
479
+                    $userAccount[$key]['value'] = $value;
480
+                    $this->accountManager->updateUser($targetUser, $userAccount);
481
+                }
482
+                break;
483
+            default:
484
+                throw new OCSException('', 103);
485
+        }
486
+        return new DataResponse();
487
+    }
488
+
489
+    /**
490
+     * @PasswordConfirmationRequired
491
+     * @NoAdminRequired
492
+     *
493
+     * @param string $userId
494
+     * @return DataResponse
495
+     * @throws OCSException
496
+     */
497
+    public function deleteUser(string $userId): DataResponse {
498
+        $currentLoggedInUser = $this->userSession->getUser();
499
+
500
+        $targetUser = $this->userManager->get($userId);
501
+
502
+        if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
503
+            throw new OCSException('', 101);
504
+        }
505
+
506
+        // If not permitted
507
+        $subAdminManager = $this->groupManager->getSubAdmin();
508
+        if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
509
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
510
+        }
511
+
512
+        // Go ahead with the delete
513
+        if($targetUser->delete()) {
514
+            return new DataResponse();
515
+        } else {
516
+            throw new OCSException('', 101);
517
+        }
518
+    }
519
+
520
+    /**
521
+     * @PasswordConfirmationRequired
522
+     * @NoAdminRequired
523
+     *
524
+     * @param string $userId
525
+     * @return DataResponse
526
+     * @throws OCSException
527
+     * @throws OCSForbiddenException
528
+     */
529
+    public function disableUser(string $userId): DataResponse {
530
+        return $this->setEnabled($userId, false);
531
+    }
532
+
533
+    /**
534
+     * @PasswordConfirmationRequired
535
+     * @NoAdminRequired
536
+     *
537
+     * @param string $userId
538
+     * @return DataResponse
539
+     * @throws OCSException
540
+     * @throws OCSForbiddenException
541
+     */
542
+    public function enableUser(string $userId): DataResponse {
543
+        return $this->setEnabled($userId, true);
544
+    }
545
+
546
+    /**
547
+     * @param string $userId
548
+     * @param bool $value
549
+     * @return DataResponse
550
+     * @throws OCSException
551
+     */
552
+    private function setEnabled(string $userId, bool $value): DataResponse {
553
+        $currentLoggedInUser = $this->userSession->getUser();
554
+
555
+        $targetUser = $this->userManager->get($userId);
556
+        if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
557
+            throw new OCSException('', 101);
558
+        }
559
+
560
+        // If not permitted
561
+        $subAdminManager = $this->groupManager->getSubAdmin();
562
+        if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
563
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
564
+        }
565
+
566
+        // enable/disable the user now
567
+        $targetUser->setEnabled($value);
568
+        return new DataResponse();
569
+    }
570
+
571
+    /**
572
+     * @NoAdminRequired
573
+     * @NoSubAdminRequired
574
+     *
575
+     * @param string $userId
576
+     * @return DataResponse
577
+     * @throws OCSException
578
+     */
579
+    public function getUsersGroups(string $userId): DataResponse {
580
+        $loggedInUser = $this->userSession->getUser();
581
+
582
+        $targetUser = $this->userManager->get($userId);
583
+        if($targetUser === null) {
584
+            throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
585
+        }
586
+
587
+        if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
588
+            // Self lookup or admin lookup
589
+            return new DataResponse([
590
+                'groups' => $this->groupManager->getUserGroupIds($targetUser)
591
+            ]);
592
+        } else {
593
+            $subAdminManager = $this->groupManager->getSubAdmin();
594
+
595
+            // Looking up someone else
596
+            if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
597
+                // Return the group that the method caller is subadmin of for the user in question
598
+                /** @var IGroup[] $getSubAdminsGroups */
599
+                $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
600
+                foreach ($getSubAdminsGroups as $key => $group) {
601
+                    $getSubAdminsGroups[$key] = $group->getGID();
602
+                }
603
+                $groups = array_intersect(
604
+                    $getSubAdminsGroups,
605
+                    $this->groupManager->getUserGroupIds($targetUser)
606
+                );
607
+                return new DataResponse(['groups' => $groups]);
608
+            } else {
609
+                // Not permitted
610
+                throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
611
+            }
612
+        }
613
+
614
+    }
615
+
616
+    /**
617
+     * @PasswordConfirmationRequired
618
+     * @NoAdminRequired
619
+     *
620
+     * @param string $userId
621
+     * @param string $groupid
622
+     * @return DataResponse
623
+     * @throws OCSException
624
+     */
625
+    public function addToGroup(string $userId, string $groupid = ''): DataResponse {
626
+        if($groupid === '') {
627
+            throw new OCSException('', 101);
628
+        }
629
+
630
+        $group = $this->groupManager->get($groupid);
631
+        $targetUser = $this->userManager->get($userId);
632
+        if($group === null) {
633
+            throw new OCSException('', 102);
634
+        }
635
+        if($targetUser === null) {
636
+            throw new OCSException('', 103);
637
+        }
638
+
639
+        // If they're not an admin, check they are a subadmin of the group in question
640
+        $loggedInUser = $this->userSession->getUser();
641
+        $subAdminManager = $this->groupManager->getSubAdmin();
642
+        if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
643
+            throw new OCSException('', 104);
644
+        }
645
+
646
+        // Add user to group
647
+        $group->addUser($targetUser);
648
+        return new DataResponse();
649
+    }
650
+
651
+    /**
652
+     * @PasswordConfirmationRequired
653
+     * @NoAdminRequired
654
+     *
655
+     * @param string $userId
656
+     * @param string $groupid
657
+     * @return DataResponse
658
+     * @throws OCSException
659
+     */
660
+    public function removeFromGroup(string $userId, string $groupid): DataResponse {
661
+        $loggedInUser = $this->userSession->getUser();
662
+
663
+        if($groupid === null || trim($groupid) === '') {
664
+            throw new OCSException('', 101);
665
+        }
666
+
667
+        $group = $this->groupManager->get($groupid);
668
+        if($group === null) {
669
+            throw new OCSException('', 102);
670
+        }
671
+
672
+        $targetUser = $this->userManager->get($userId);
673
+        if($targetUser === null) {
674
+            throw new OCSException('', 103);
675
+        }
676
+
677
+        // If they're not an admin, check they are a subadmin of the group in question
678
+        $subAdminManager = $this->groupManager->getSubAdmin();
679
+        if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
680
+            throw new OCSException('', 104);
681
+        }
682
+
683
+        // Check they aren't removing themselves from 'admin' or their 'subadmin; group
684
+        if ($targetUser->getUID() === $loggedInUser->getUID()) {
685
+            if ($this->groupManager->isAdmin($loggedInUser->getUID())) {
686
+                if ($group->getGID() === 'admin') {
687
+                    throw new OCSException('Cannot remove yourself from the admin group', 105);
688
+                }
689
+            } else {
690
+                // Not an admin, so the user must be a subadmin of this group, but that is not allowed.
691
+                throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105);
692
+            }
693
+
694
+        } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
695
+            /** @var IGroup[] $subAdminGroups */
696
+            $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
697
+            $subAdminGroups = array_map(function (IGroup $subAdminGroup) {
698
+                return $subAdminGroup->getGID();
699
+            }, $subAdminGroups);
700
+            $userGroups = $this->groupManager->getUserGroupIds($targetUser);
701
+            $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups);
702
+
703
+            if (count($userSubAdminGroups) <= 1) {
704
+                // Subadmin must not be able to remove a user from all their subadmin groups.
705
+                throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105);
706
+            }
707
+        }
708
+
709
+        // Remove user from group
710
+        $group->removeUser($targetUser);
711
+        return new DataResponse();
712
+    }
713
+
714
+    /**
715
+     * Creates a subadmin
716
+     *
717
+     * @PasswordConfirmationRequired
718
+     *
719
+     * @param string $userId
720
+     * @param string $groupid
721
+     * @return DataResponse
722
+     * @throws OCSException
723
+     */
724
+    public function addSubAdmin(string $userId, string $groupid): DataResponse {
725
+        $group = $this->groupManager->get($groupid);
726
+        $user = $this->userManager->get($userId);
727
+
728
+        // Check if the user exists
729
+        if($user === null) {
730
+            throw new OCSException('User does not exist', 101);
731
+        }
732
+        // Check if group exists
733
+        if($group === null) {
734
+            throw new OCSException('Group does not exist',  102);
735
+        }
736
+        // Check if trying to make subadmin of admin group
737
+        if($group->getGID() === 'admin') {
738
+            throw new OCSException('Cannot create subadmins for admin group', 103);
739
+        }
740
+
741
+        $subAdminManager = $this->groupManager->getSubAdmin();
742
+
743
+        // We cannot be subadmin twice
744
+        if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
745
+            return new DataResponse();
746
+        }
747
+        // Go
748
+        if($subAdminManager->createSubAdmin($user, $group)) {
749
+            return new DataResponse();
750
+        } else {
751
+            throw new OCSException('Unknown error occurred', 103);
752
+        }
753
+    }
754
+
755
+    /**
756
+     * Removes a subadmin from a group
757
+     *
758
+     * @PasswordConfirmationRequired
759
+     *
760
+     * @param string $userId
761
+     * @param string $groupid
762
+     * @return DataResponse
763
+     * @throws OCSException
764
+     */
765
+    public function removeSubAdmin(string $userId, string $groupid): DataResponse {
766
+        $group = $this->groupManager->get($groupid);
767
+        $user = $this->userManager->get($userId);
768
+        $subAdminManager = $this->groupManager->getSubAdmin();
769
+
770
+        // Check if the user exists
771
+        if($user === null) {
772
+            throw new OCSException('User does not exist', 101);
773
+        }
774
+        // Check if the group exists
775
+        if($group === null) {
776
+            throw new OCSException('Group does not exist', 101);
777
+        }
778
+        // Check if they are a subadmin of this said group
779
+        if(!$subAdminManager->isSubAdminOfGroup($user, $group)) {
780
+            throw new OCSException('User is not a subadmin of this group', 102);
781
+        }
782
+
783
+        // Go
784
+        if($subAdminManager->deleteSubAdmin($user, $group)) {
785
+            return new DataResponse();
786
+        } else {
787
+            throw new OCSException('Unknown error occurred', 103);
788
+        }
789
+    }
790
+
791
+    /**
792
+     * Get the groups a user is a subadmin of
793
+     *
794
+     * @param string $userId
795
+     * @return DataResponse
796
+     * @throws OCSException
797
+     */
798
+    public function getUserSubAdminGroups(string $userId): DataResponse {
799
+        $groups = $this->getUserSubAdminGroupsData($userId);
800
+        return new DataResponse($groups);
801
+    }
802
+
803
+    /**
804
+     * @NoAdminRequired
805
+     * @PasswordConfirmationRequired
806
+     *
807
+     * resend welcome message
808
+     *
809
+     * @param string $userId
810
+     * @return DataResponse
811
+     * @throws OCSException
812
+     */
813
+    public function resendWelcomeMessage(string $userId): DataResponse {
814
+        $currentLoggedInUser = $this->userSession->getUser();
815
+
816
+        $targetUser = $this->userManager->get($userId);
817
+        if($targetUser === null) {
818
+            throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND);
819
+        }
820
+
821
+        // Check if admin / subadmin
822
+        $subAdminManager = $this->groupManager->getSubAdmin();
823
+        if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
824
+            && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
825
+            // No rights
826
+            throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
827
+        }
828
+
829
+        $email = $targetUser->getEMailAddress();
830
+        if ($email === '' || $email === null) {
831
+            throw new OCSException('Email address not available', 101);
832
+        }
833
+        $username = $targetUser->getUID();
834
+        $lang = $this->config->getUserValue($username, 'core', 'lang', 'en');
835
+        if (!$this->l10nFactory->languageExists('settings', $lang)) {
836
+            $lang = 'en';
837
+        }
838
+
839
+        $l10n = $this->l10nFactory->get('settings', $lang);
840
+
841
+        try {
842
+            $this->newUserMailHelper->setL10N($l10n);
843
+            $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
844
+            $this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
845
+        } catch(\Exception $e) {
846
+            $this->logger->logException($e, [
847
+                'message' => "Can't send new user mail to $email",
848
+                'level' => \OCP\Util::ERROR,
849
+                'app' => 'settings',
850
+            ]);
851
+            throw new OCSException('Sending email failed', 102);
852
+        }
853
+
854
+        return new DataResponse();
855
+    }
856 856
 }
Please login to merge, or discard this patch.
apps/provisioning_api/lib/Controller/GroupsController.php 3 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 /**
4 4
  * @copyright Copyright (c) 2016, ownCloud, Inc.
5 5
  *
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
 		// Check the group exists
165 165
 		$group = $this->groupManager->get($groupId);
166 166
 		if ($group !== null) {
167
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
167
+			$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
168 168
 		} else {
169 169
 			throw new OCSNotFoundException('The requested group could not be found');
170 170
 		}
171 171
 
172 172
 		// Check subadmin has access to this group
173
-		if($this->groupManager->isAdmin($user->getUID())
173
+		if ($this->groupManager->isAdmin($user->getUID())
174 174
 		   || $isSubadminOfGroup) {
175 175
 			$users = $this->groupManager->get($groupId)->getUsers();
176
-			$users =  array_map(function($user) {
176
+			$users = array_map(function($user) {
177 177
 				/** @var IUser $user */
178 178
 				return $user->getUID();
179 179
 			}, $users);
@@ -202,13 +202,13 @@  discard block
 block discarded – undo
202 202
 		// Check the group exists
203 203
 		$group = $this->groupManager->get($groupId);
204 204
 		if ($group !== null) {
205
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
205
+			$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
206 206
 		} else {
207 207
 			throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
208 208
 		}
209 209
 
210 210
 		// Check subadmin has access to this group
211
-		if($this->groupManager->isAdmin($user->getUID())
211
+		if ($this->groupManager->isAdmin($user->getUID())
212 212
 		   || $isSubadminOfGroup) {
213 213
 			$users = $this->groupManager->get($groupId)->getUsers();
214 214
 			// Extract required number
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 			foreach ($users as $userId) {
219 219
 				$userData = $this->getUserData($userId);
220 220
 				// Do not insert empty entry
221
-				if(!empty($userData)) {
221
+				if (!empty($userData)) {
222 222
 					$usersDetails[$userId] = $userData;
223 223
 				}
224 224
 			}
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
 	 */
240 240
 	public function addGroup(string $groupid): DataResponse {
241 241
 		// Validate name
242
-		if(empty($groupid)) {
242
+		if (empty($groupid)) {
243 243
 			$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
244 244
 			throw new OCSException('Invalid group name', 101);
245 245
 		}
246 246
 		// Check if it exists
247
-		if($this->groupManager->groupExists($groupid)){
247
+		if ($this->groupManager->groupExists($groupid)) {
248 248
 			throw new OCSException('', 102);
249 249
 		}
250 250
 		$this->groupManager->createGroup($groupid);
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	 */
261 261
 	public function deleteGroup(string $groupId): DataResponse {
262 262
 		// Check it exists
263
-		if(!$this->groupManager->groupExists($groupId)){
263
+		if (!$this->groupManager->groupExists($groupId)) {
264 264
 			throw new OCSException('', 101);
265
-		} else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
265
+		} else if ($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()) {
266 266
 			// Cannot delete admin group
267 267
 			throw new OCSException('', 102);
268 268
 		}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	public function getSubAdminsOfGroup(string $groupId): DataResponse {
279 279
 		// Check group exists
280 280
 		$targetGroup = $this->groupManager->get($groupId);
281
-		if($targetGroup === null) {
281
+		if ($targetGroup === null) {
282 282
 			throw new OCSException('Group does not exist', 101);
283 283
 		}
284 284
 
Please login to merge, or discard this patch.
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,6 @@
 block discarded – undo
74 74
 	 * @param IUserSession $userSession
75 75
 	 * @param AccountManager $accountManager
76 76
 	 * @param ILogger $logger
77
-	 * @param UsersController $userController
78 77
 	 */
79 78
 	public function __construct(string $appName,
80 79
 								IRequest $request,
Please login to merge, or discard this patch.
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -45,235 +45,235 @@
 block discarded – undo
45 45
 
46 46
 class GroupsController extends AUserData {
47 47
 
48
-	/** @var ILogger */
49
-	private $logger;
48
+    /** @var ILogger */
49
+    private $logger;
50 50
 
51
-	/**
52
-	 * @param string $appName
53
-	 * @param IRequest $request
54
-	 * @param IUserManager $userManager
55
-	 * @param IConfig $config
56
-	 * @param IGroupManager $groupManager
57
-	 * @param IUserSession $userSession
58
-	 * @param AccountManager $accountManager
59
-	 * @param ILogger $logger
60
-	 * @param UsersController $userController
61
-	 */
62
-	public function __construct(string $appName,
63
-								IRequest $request,
64
-								IUserManager $userManager,
65
-								IConfig $config,
66
-								IGroupManager $groupManager,
67
-								IUserSession $userSession,
68
-								AccountManager $accountManager,
69
-								ILogger $logger) {
70
-		parent::__construct($appName,
71
-			$request,
72
-			$userManager,
73
-			$config,
74
-			$groupManager,
75
-			$userSession,
76
-			$accountManager);
51
+    /**
52
+     * @param string $appName
53
+     * @param IRequest $request
54
+     * @param IUserManager $userManager
55
+     * @param IConfig $config
56
+     * @param IGroupManager $groupManager
57
+     * @param IUserSession $userSession
58
+     * @param AccountManager $accountManager
59
+     * @param ILogger $logger
60
+     * @param UsersController $userController
61
+     */
62
+    public function __construct(string $appName,
63
+                                IRequest $request,
64
+                                IUserManager $userManager,
65
+                                IConfig $config,
66
+                                IGroupManager $groupManager,
67
+                                IUserSession $userSession,
68
+                                AccountManager $accountManager,
69
+                                ILogger $logger) {
70
+        parent::__construct($appName,
71
+            $request,
72
+            $userManager,
73
+            $config,
74
+            $groupManager,
75
+            $userSession,
76
+            $accountManager);
77 77
 
78
-		$this->logger = $logger;
79
-	}
78
+        $this->logger = $logger;
79
+    }
80 80
 
81
-	/**
82
-	 * returns a list of groups
83
-	 *
84
-	 * @NoAdminRequired
85
-	 *
86
-	 * @param string $search
87
-	 * @param int $limit
88
-	 * @param int $offset
89
-	 * @return DataResponse
90
-	 */
91
-	public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
92
-		$groups = $this->groupManager->search($search, $limit, $offset);
93
-		$groups = array_map(function($group) {
94
-			/** @var IGroup $group */
95
-			return $group->getGID();
96
-		}, $groups);
81
+    /**
82
+     * returns a list of groups
83
+     *
84
+     * @NoAdminRequired
85
+     *
86
+     * @param string $search
87
+     * @param int $limit
88
+     * @param int $offset
89
+     * @return DataResponse
90
+     */
91
+    public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
92
+        $groups = $this->groupManager->search($search, $limit, $offset);
93
+        $groups = array_map(function($group) {
94
+            /** @var IGroup $group */
95
+            return $group->getGID();
96
+        }, $groups);
97 97
 
98
-		return new DataResponse(['groups' => $groups]);
99
-	}
98
+        return new DataResponse(['groups' => $groups]);
99
+    }
100 100
 
101
-	/**
102
-	 * returns a list of groups details with ids and displaynames
103
-	 *
104
-	 * @NoAdminRequired
105
-	 *
106
-	 * @param string $search
107
-	 * @param int $limit
108
-	 * @param int $offset
109
-	 * @return DataResponse
110
-	 */
111
-	public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
112
-		$groups = $this->groupManager->search($search, $limit, $offset);
113
-		$groups = array_map(function($group) {
114
-			/** @var IGroup $group */
115
-			return ['id' => $group->getGID(), 'displayname' => $group->getDisplayName()];
116
-		}, $groups);
101
+    /**
102
+     * returns a list of groups details with ids and displaynames
103
+     *
104
+     * @NoAdminRequired
105
+     *
106
+     * @param string $search
107
+     * @param int $limit
108
+     * @param int $offset
109
+     * @return DataResponse
110
+     */
111
+    public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
112
+        $groups = $this->groupManager->search($search, $limit, $offset);
113
+        $groups = array_map(function($group) {
114
+            /** @var IGroup $group */
115
+            return ['id' => $group->getGID(), 'displayname' => $group->getDisplayName()];
116
+        }, $groups);
117 117
 
118
-		return new DataResponse(['groups' => $groups]);
119
-	}
118
+        return new DataResponse(['groups' => $groups]);
119
+    }
120 120
 
121
-	/**
122
-	 * @NoAdminRequired
123
-	 *
124
-	 * @param string $groupId
125
-	 * @return DataResponse
126
-	 * @throws OCSException	
127
-	 *
128
-	 * @deprecated 14 Use getGroupUsers
129
-	 */
130
-	public function getGroup(string $groupId): DataResponse {
131
-		return $this->getGroupUsers($groupId);
132
-	}
121
+    /**
122
+     * @NoAdminRequired
123
+     *
124
+     * @param string $groupId
125
+     * @return DataResponse
126
+     * @throws OCSException	
127
+     *
128
+     * @deprecated 14 Use getGroupUsers
129
+     */
130
+    public function getGroup(string $groupId): DataResponse {
131
+        return $this->getGroupUsers($groupId);
132
+    }
133 133
 
134
-	/**
135
-	 * returns an array of users in the specified group
136
-	 *
137
-	 * @NoAdminRequired
138
-	 *
139
-	 * @param string $groupId
140
-	 * @return DataResponse
141
-	 * @throws OCSException
142
-	 */
143
-	public function getGroupUsers(string $groupId): DataResponse {
144
-		$user = $this->userSession->getUser();
145
-		$isSubadminOfGroup = false;
134
+    /**
135
+     * returns an array of users in the specified group
136
+     *
137
+     * @NoAdminRequired
138
+     *
139
+     * @param string $groupId
140
+     * @return DataResponse
141
+     * @throws OCSException
142
+     */
143
+    public function getGroupUsers(string $groupId): DataResponse {
144
+        $user = $this->userSession->getUser();
145
+        $isSubadminOfGroup = false;
146 146
 
147
-		// Check the group exists
148
-		$group = $this->groupManager->get($groupId);
149
-		if ($group !== null) {
150
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
151
-		} else {
152
-			throw new OCSNotFoundException('The requested group could not be found');
153
-		}
147
+        // Check the group exists
148
+        $group = $this->groupManager->get($groupId);
149
+        if ($group !== null) {
150
+            $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
151
+        } else {
152
+            throw new OCSNotFoundException('The requested group could not be found');
153
+        }
154 154
 
155
-		// Check subadmin has access to this group
156
-		if($this->groupManager->isAdmin($user->getUID())
157
-		   || $isSubadminOfGroup) {
158
-			$users = $this->groupManager->get($groupId)->getUsers();
159
-			$users =  array_map(function($user) {
160
-				/** @var IUser $user */
161
-				return $user->getUID();
162
-			}, $users);
163
-			$users = array_values($users);
164
-			return new DataResponse(['users' => $users]);
165
-		}
155
+        // Check subadmin has access to this group
156
+        if($this->groupManager->isAdmin($user->getUID())
157
+           || $isSubadminOfGroup) {
158
+            $users = $this->groupManager->get($groupId)->getUsers();
159
+            $users =  array_map(function($user) {
160
+                /** @var IUser $user */
161
+                return $user->getUID();
162
+            }, $users);
163
+            $users = array_values($users);
164
+            return new DataResponse(['users' => $users]);
165
+        }
166 166
 
167
-		throw new OCSForbiddenException();
168
-	}
167
+        throw new OCSForbiddenException();
168
+    }
169 169
 
170
-	/**
171
-	 * returns an array of users details in the specified group
172
-	 *
173
-	 * @NoAdminRequired
174
-	 *
175
-	 * @param string $groupId
176
-	 * @param int $limit
177
-	 * @param int $offset
178
-	 * @return DataResponse
179
-	 * @throws OCSException
180
-	 */
181
-	public function getGroupUsersDetails(string $groupId, int $limit = null, int $offset = 0): DataResponse {
182
-		$user = $this->userSession->getUser();
183
-		$isSubadminOfGroup = false;
170
+    /**
171
+     * returns an array of users details in the specified group
172
+     *
173
+     * @NoAdminRequired
174
+     *
175
+     * @param string $groupId
176
+     * @param int $limit
177
+     * @param int $offset
178
+     * @return DataResponse
179
+     * @throws OCSException
180
+     */
181
+    public function getGroupUsersDetails(string $groupId, int $limit = null, int $offset = 0): DataResponse {
182
+        $user = $this->userSession->getUser();
183
+        $isSubadminOfGroup = false;
184 184
 
185
-		// Check the group exists
186
-		$group = $this->groupManager->get($groupId);
187
-		if ($group !== null) {
188
-			$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
189
-		} else {
190
-			throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
191
-		}
185
+        // Check the group exists
186
+        $group = $this->groupManager->get($groupId);
187
+        if ($group !== null) {
188
+            $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
189
+        } else {
190
+            throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
191
+        }
192 192
 
193
-		// Check subadmin has access to this group
194
-		if($this->groupManager->isAdmin($user->getUID())
195
-		   || $isSubadminOfGroup) {
196
-			$users = $this->groupManager->get($groupId)->getUsers();
197
-			// Extract required number
198
-			$users = array_slice($users, $offset, $limit);
199
-			$users = array_keys($users);
200
-			$usersDetails = [];
201
-			foreach ($users as $userId) {
202
-				$userData = $this->getUserData($userId);
203
-				// Do not insert empty entry
204
-				if(!empty($userData)) {
205
-					$usersDetails[$userId] = $userData;
206
-				}
207
-			}
208
-			return new DataResponse(['users' => $usersDetails]);
209
-		}
193
+        // Check subadmin has access to this group
194
+        if($this->groupManager->isAdmin($user->getUID())
195
+           || $isSubadminOfGroup) {
196
+            $users = $this->groupManager->get($groupId)->getUsers();
197
+            // Extract required number
198
+            $users = array_slice($users, $offset, $limit);
199
+            $users = array_keys($users);
200
+            $usersDetails = [];
201
+            foreach ($users as $userId) {
202
+                $userData = $this->getUserData($userId);
203
+                // Do not insert empty entry
204
+                if(!empty($userData)) {
205
+                    $usersDetails[$userId] = $userData;
206
+                }
207
+            }
208
+            return new DataResponse(['users' => $usersDetails]);
209
+        }
210 210
 
211
-		throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
212
-	}
211
+        throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
212
+    }
213 213
 
214
-	/**
215
-	 * creates a new group
216
-	 *
217
-	 * @PasswordConfirmationRequired
218
-	 *
219
-	 * @param string $groupid
220
-	 * @return DataResponse
221
-	 * @throws OCSException
222
-	 */
223
-	public function addGroup(string $groupid): DataResponse {
224
-		// Validate name
225
-		if(empty($groupid)) {
226
-			$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
227
-			throw new OCSException('Invalid group name', 101);
228
-		}
229
-		// Check if it exists
230
-		if($this->groupManager->groupExists($groupid)){
231
-			throw new OCSException('', 102);
232
-		}
233
-		$this->groupManager->createGroup($groupid);
234
-		return new DataResponse();
235
-	}
214
+    /**
215
+     * creates a new group
216
+     *
217
+     * @PasswordConfirmationRequired
218
+     *
219
+     * @param string $groupid
220
+     * @return DataResponse
221
+     * @throws OCSException
222
+     */
223
+    public function addGroup(string $groupid): DataResponse {
224
+        // Validate name
225
+        if(empty($groupid)) {
226
+            $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
227
+            throw new OCSException('Invalid group name', 101);
228
+        }
229
+        // Check if it exists
230
+        if($this->groupManager->groupExists($groupid)){
231
+            throw new OCSException('', 102);
232
+        }
233
+        $this->groupManager->createGroup($groupid);
234
+        return new DataResponse();
235
+    }
236 236
 
237
-	/**
238
-	 * @PasswordConfirmationRequired
239
-	 *
240
-	 * @param string $groupId
241
-	 * @return DataResponse
242
-	 * @throws OCSException
243
-	 */
244
-	public function deleteGroup(string $groupId): DataResponse {
245
-		// Check it exists
246
-		if(!$this->groupManager->groupExists($groupId)){
247
-			throw new OCSException('', 101);
248
-		} else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
249
-			// Cannot delete admin group
250
-			throw new OCSException('', 102);
251
-		}
237
+    /**
238
+     * @PasswordConfirmationRequired
239
+     *
240
+     * @param string $groupId
241
+     * @return DataResponse
242
+     * @throws OCSException
243
+     */
244
+    public function deleteGroup(string $groupId): DataResponse {
245
+        // Check it exists
246
+        if(!$this->groupManager->groupExists($groupId)){
247
+            throw new OCSException('', 101);
248
+        } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){
249
+            // Cannot delete admin group
250
+            throw new OCSException('', 102);
251
+        }
252 252
 
253
-		return new DataResponse();
254
-	}
253
+        return new DataResponse();
254
+    }
255 255
 
256
-	/**
257
-	 * @param string $groupId
258
-	 * @return DataResponse
259
-	 * @throws OCSException
260
-	 */
261
-	public function getSubAdminsOfGroup(string $groupId): DataResponse {
262
-		// Check group exists
263
-		$targetGroup = $this->groupManager->get($groupId);
264
-		if($targetGroup === null) {
265
-			throw new OCSException('Group does not exist', 101);
266
-		}
256
+    /**
257
+     * @param string $groupId
258
+     * @return DataResponse
259
+     * @throws OCSException
260
+     */
261
+    public function getSubAdminsOfGroup(string $groupId): DataResponse {
262
+        // Check group exists
263
+        $targetGroup = $this->groupManager->get($groupId);
264
+        if($targetGroup === null) {
265
+            throw new OCSException('Group does not exist', 101);
266
+        }
267 267
 
268
-		/** @var IUser[] $subadmins */
269
-		$subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
270
-		// New class returns IUser[] so convert back
271
-		$uids = [];
272
-		foreach ($subadmins as $user) {
273
-			$uids[] = $user->getUID();
274
-		}
268
+        /** @var IUser[] $subadmins */
269
+        $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
270
+        // New class returns IUser[] so convert back
271
+        $uids = [];
272
+        foreach ($subadmins as $user) {
273
+            $uids[] = $user->getUID();
274
+        }
275 275
 
276
-		return new DataResponse($uids);
277
-	}
276
+        return new DataResponse($uids);
277
+    }
278 278
 
279 279
 }
Please login to merge, or discard this patch.
apps/provisioning_api/composer/composer/autoload_static.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,35 +6,35 @@
 block discarded – undo
6 6
 
7 7
 class ComposerStaticInitProvisioning_API
8 8
 {
9
-    public static $prefixLengthsPsr4 = array (
9
+    public static $prefixLengthsPsr4 = array(
10 10
         'O' => 
11
-        array (
11
+        array(
12 12
             'OCA\\Provisioning_API\\' => 21,
13 13
         ),
14 14
     );
15 15
 
16
-    public static $prefixDirsPsr4 = array (
16
+    public static $prefixDirsPsr4 = array(
17 17
         'OCA\\Provisioning_API\\' => 
18
-        array (
19
-            0 => __DIR__ . '/..' . '/../lib',
18
+        array(
19
+            0 => __DIR__.'/..'.'/../lib',
20 20
         ),
21 21
     );
22 22
 
23
-    public static $classMap = array (
24
-        'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
25
-        'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__ . '/..' . '/../lib/Controller/AUserData.php',
26
-        'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__ . '/..' . '/../lib/Controller/AppConfigController.php',
27
-        'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php',
28
-        'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php',
29
-        'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php',
30
-        'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__ . '/..' . '/../lib/FederatedFileSharingFactory.php',
31
-        'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
32
-        'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ProvisioningApiMiddleware.php',
23
+    public static $classMap = array(
24
+        'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php',
25
+        'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__.'/..'.'/../lib/Controller/AUserData.php',
26
+        'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__.'/..'.'/../lib/Controller/AppConfigController.php',
27
+        'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__.'/..'.'/../lib/Controller/AppsController.php',
28
+        'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__.'/..'.'/../lib/Controller/GroupsController.php',
29
+        'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__.'/..'.'/../lib/Controller/UsersController.php',
30
+        'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__.'/..'.'/../lib/FederatedFileSharingFactory.php',
31
+        'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__.'/..'.'/../lib/Middleware/Exceptions/NotSubAdminException.php',
32
+        'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__.'/..'.'/../lib/Middleware/ProvisioningApiMiddleware.php',
33 33
     );
34 34
 
35 35
     public static function getInitializer(ClassLoader $loader)
36 36
     {
37
-        return \Closure::bind(function () use ($loader) {
37
+        return \Closure::bind(function() use ($loader) {
38 38
             $loader->prefixLengthsPsr4 = ComposerStaticInitProvisioning_API::$prefixLengthsPsr4;
39 39
             $loader->prefixDirsPsr4 = ComposerStaticInitProvisioning_API::$prefixDirsPsr4;
40 40
             $loader->classMap = ComposerStaticInitProvisioning_API::$classMap;
Please login to merge, or discard this patch.
apps/provisioning_api/composer/composer/autoload_classmap.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 $baseDir = $vendorDir;
7 7
 
8 8
 return array(
9
-    'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
10
-    'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir . '/../lib/Controller/AUserData.php',
11
-    'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir . '/../lib/Controller/AppConfigController.php',
12
-    'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php',
13
-    'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php',
14
-    'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php',
15
-    'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir . '/../lib/FederatedFileSharingFactory.php',
16
-    'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
17
-    'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir . '/../lib/Middleware/ProvisioningApiMiddleware.php',
9
+    'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php',
10
+    'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir.'/../lib/Controller/AUserData.php',
11
+    'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir.'/../lib/Controller/AppConfigController.php',
12
+    'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir.'/../lib/Controller/AppsController.php',
13
+    'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir.'/../lib/Controller/GroupsController.php',
14
+    'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir.'/../lib/Controller/UsersController.php',
15
+    'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir.'/../lib/FederatedFileSharingFactory.php',
16
+    'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir.'/../lib/Middleware/Exceptions/NotSubAdminException.php',
17
+    'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir.'/../lib/Middleware/ProvisioningApiMiddleware.php',
18 18
 );
Please login to merge, or discard this patch.
apps/provisioning_api/lib/Controller/AUserData.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -37,143 +37,143 @@
 block discarded – undo
37 37
 
38 38
 abstract class AUserData extends OCSController {
39 39
 
40
-	/** @var IUserManager */
41
-	protected $userManager;
42
-	/** @var IConfig */
43
-	protected $config;
44
-	/** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface
45
-	protected $groupManager;
46
-	/** @var IUserSession */
47
-	protected $userSession;
48
-	/** @var AccountManager */
49
-	protected $accountManager;
50
-
51
-	/**
52
-	 * @param string $appName
53
-	 * @param IRequest $request
54
-	 * @param IUserManager $userManager
55
-	 * @param IConfig $config
56
-	 * @param IGroupManager $groupManager
57
-	 * @param IUserSession $userSession
58
-	 * @param AccountManager $accountManager
59
-	 */
60
-	public function __construct(string $appName,
61
-								IRequest $request,
62
-								IUserManager $userManager,
63
-								IConfig $config,
64
-								IGroupManager $groupManager,
65
-								IUserSession $userSession,
66
-								AccountManager $accountManager) {
67
-		parent::__construct($appName, $request);
68
-
69
-		$this->userManager = $userManager;
70
-		$this->config = $config;
71
-		$this->groupManager = $groupManager;
72
-		$this->userSession = $userSession;
73
-		$this->accountManager = $accountManager;
74
-	}
75
-
76
-	/**
77
-	 * creates a array with all user data
78
-	 *
79
-	 * @param $userId
80
-	 * @return array
81
-	 * @throws OCSException
82
-	 */
83
-	protected function getUserData(string $userId): array {
84
-		$currentLoggedInUser = $this->userSession->getUser();
85
-
86
-		$data = [];
87
-
88
-		// Check if the target user exists
89
-		$targetUserObject = $this->userManager->get($userId);
90
-		if($targetUserObject === null) {
91
-			throw new OCSNotFoundException('User does not exist');
92
-		}
93
-
94
-		// Should be at least Admin Or SubAdmin!
95
-		if( $this->groupManager->isAdmin($currentLoggedInUser->getUID())
96
-			|| $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
97
-				$data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true');
98
-		} else {
99
-			// Check they are looking up themselves
100
-			if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
101
-				return $data;
102
-			}
103
-		}
104
-
105
-		// Get groups data
106
-		$userAccount = $this->accountManager->getUser($targetUserObject);
107
-		$groups = $this->groupManager->getUserGroups($targetUserObject);
108
-		$gids = [];
109
-		foreach ($groups as $group) {
110
-			$gids[] = $group->getDisplayName();
111
-		}
112
-
113
-		// Find the data
114
-		$data['id'] = $targetUserObject->getUID();
115
-		$data['storageLocation'] = $targetUserObject->getHome();
116
-		$data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
117
-		$data['backend'] = $targetUserObject->getBackendClassName();
118
-		$data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
119
-		$data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
120
-		$data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
121
-		$data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
122
-		$data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value'];
123
-		$data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value'];
124
-		$data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
125
-		$data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
126
-		$data['groups'] = $gids;
127
-		$data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang');
128
-
129
-		return $data;
40
+    /** @var IUserManager */
41
+    protected $userManager;
42
+    /** @var IConfig */
43
+    protected $config;
44
+    /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface
45
+    protected $groupManager;
46
+    /** @var IUserSession */
47
+    protected $userSession;
48
+    /** @var AccountManager */
49
+    protected $accountManager;
50
+
51
+    /**
52
+     * @param string $appName
53
+     * @param IRequest $request
54
+     * @param IUserManager $userManager
55
+     * @param IConfig $config
56
+     * @param IGroupManager $groupManager
57
+     * @param IUserSession $userSession
58
+     * @param AccountManager $accountManager
59
+     */
60
+    public function __construct(string $appName,
61
+                                IRequest $request,
62
+                                IUserManager $userManager,
63
+                                IConfig $config,
64
+                                IGroupManager $groupManager,
65
+                                IUserSession $userSession,
66
+                                AccountManager $accountManager) {
67
+        parent::__construct($appName, $request);
68
+
69
+        $this->userManager = $userManager;
70
+        $this->config = $config;
71
+        $this->groupManager = $groupManager;
72
+        $this->userSession = $userSession;
73
+        $this->accountManager = $accountManager;
130 74
     }
131 75
 
132
-	/**
133
-	 * Get the groups a user is a subadmin of
134
-	 *
135
-	 * @param string $userId
136
-	 * @return array
137
-	 * @throws OCSException
138
-	 */
139
-	protected function getUserSubAdminGroupsData(string $userId): array {
140
-		$user = $this->userManager->get($userId);
141
-		// Check if the user exists
142
-		if($user === null) {
143
-			throw new OCSNotFoundException('User does not exist');
144
-		}
145
-
146
-		// Get the subadmin groups
147
-		$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
148
-		$groups = [];
149
-		foreach ($subAdminGroups as $key => $group) {
150
-			$groups[] = $group->getGID();
151
-		}
152
-
153
-		return $groups;
154
-	}
155
-
156
-	/**
157
-	 * @param string $userId
158
-	 * @return array
159
-	 * @throws \OCP\Files\NotFoundException
160
-	 */
161
-	protected function fillStorageInfo(string $userId): array {
162
-		try {
163
-			\OC_Util::tearDownFS();
164
-			\OC_Util::setupFS($userId);
165
-			$storage = OC_Helper::getStorageInfo('/');
166
-			$data = [
167
-				'free' => $storage['free'],
168
-				'used' => $storage['used'],
169
-				'total' => $storage['total'],
170
-				'relative' => $storage['relative'],
171
-				'quota' => $storage['quota'],
172
-			];
173
-		} catch (NotFoundException $ex) {
174
-			$data = [];
175
-		}
176
-		return $data;
177
-	}
76
+    /**
77
+     * creates a array with all user data
78
+     *
79
+     * @param $userId
80
+     * @return array
81
+     * @throws OCSException
82
+     */
83
+    protected function getUserData(string $userId): array {
84
+        $currentLoggedInUser = $this->userSession->getUser();
85
+
86
+        $data = [];
87
+
88
+        // Check if the target user exists
89
+        $targetUserObject = $this->userManager->get($userId);
90
+        if($targetUserObject === null) {
91
+            throw new OCSNotFoundException('User does not exist');
92
+        }
93
+
94
+        // Should be at least Admin Or SubAdmin!
95
+        if( $this->groupManager->isAdmin($currentLoggedInUser->getUID())
96
+            || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
97
+                $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true');
98
+        } else {
99
+            // Check they are looking up themselves
100
+            if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
101
+                return $data;
102
+            }
103
+        }
104
+
105
+        // Get groups data
106
+        $userAccount = $this->accountManager->getUser($targetUserObject);
107
+        $groups = $this->groupManager->getUserGroups($targetUserObject);
108
+        $gids = [];
109
+        foreach ($groups as $group) {
110
+            $gids[] = $group->getDisplayName();
111
+        }
112
+
113
+        // Find the data
114
+        $data['id'] = $targetUserObject->getUID();
115
+        $data['storageLocation'] = $targetUserObject->getHome();
116
+        $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
117
+        $data['backend'] = $targetUserObject->getBackendClassName();
118
+        $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
119
+        $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
120
+        $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
121
+        $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
122
+        $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value'];
123
+        $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value'];
124
+        $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
125
+        $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
126
+        $data['groups'] = $gids;
127
+        $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang');
128
+
129
+        return $data;
130
+    }
131
+
132
+    /**
133
+     * Get the groups a user is a subadmin of
134
+     *
135
+     * @param string $userId
136
+     * @return array
137
+     * @throws OCSException
138
+     */
139
+    protected function getUserSubAdminGroupsData(string $userId): array {
140
+        $user = $this->userManager->get($userId);
141
+        // Check if the user exists
142
+        if($user === null) {
143
+            throw new OCSNotFoundException('User does not exist');
144
+        }
145
+
146
+        // Get the subadmin groups
147
+        $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
148
+        $groups = [];
149
+        foreach ($subAdminGroups as $key => $group) {
150
+            $groups[] = $group->getGID();
151
+        }
152
+
153
+        return $groups;
154
+    }
155
+
156
+    /**
157
+     * @param string $userId
158
+     * @return array
159
+     * @throws \OCP\Files\NotFoundException
160
+     */
161
+    protected function fillStorageInfo(string $userId): array {
162
+        try {
163
+            \OC_Util::tearDownFS();
164
+            \OC_Util::setupFS($userId);
165
+            $storage = OC_Helper::getStorageInfo('/');
166
+            $data = [
167
+                'free' => $storage['free'],
168
+                'used' => $storage['used'],
169
+                'total' => $storage['total'],
170
+                'relative' => $storage['relative'],
171
+                'quota' => $storage['quota'],
172
+            ];
173
+        } catch (NotFoundException $ex) {
174
+            $data = [];
175
+        }
176
+        return $data;
177
+    }
178 178
 
179 179
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 /**
4 4
  * @copyright Copyright (c) 2018 John Molakvoæ (skjnldsv) <[email protected]>
5 5
  *
@@ -45,17 +45,17 @@  discard block
 block discarded – undo
45 45
 
46 46
 		// Check if the target user exists
47 47
 		$targetUserObject = $this->userManager->get($userId);
48
-		if($targetUserObject === null) {
48
+		if ($targetUserObject === null) {
49 49
 			throw new OCSNotFoundException('User does not exist');
50 50
 		}
51 51
 
52 52
 		// Should be at least Admin Or SubAdmin!
53
-		if( $this->groupManager->isAdmin($currentLoggedInUser->getUID())
53
+		if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
54 54
 			|| $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
55 55
 				$data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true');
56 56
 		} else {
57 57
 			// Check they are looking up themselves
58
-			if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
58
+			if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
59 59
 				return $data;
60 60
 			}
61 61
 		}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	protected function getUserSubAdminGroupsData(string $userId): array {
98 98
 		$user = $this->userManager->get($userId);
99 99
 		// Check if the user exists
100
-		if($user === null) {
100
+		if ($user === null) {
101 101
 			throw new OCSNotFoundException('User does not exist');
102 102
 		}
103 103
 
Please login to merge, or discard this patch.