@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | // Admin? Or SubAdmin? |
123 | 123 | $uid = $user->getUID(); |
124 | 124 | $subAdminManager = $this->groupManager->getSubAdmin(); |
125 | - if($this->groupManager->isAdmin($uid)){ |
|
125 | + if ($this->groupManager->isAdmin($uid)) { |
|
126 | 126 | $users = $this->userManager->search($search, $limit, $offset); |
127 | 127 | } else if ($subAdminManager->isSubAdmin($user)) { |
128 | 128 | $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $subAdminOfGroups[$key] = $group->getGID(); |
131 | 131 | } |
132 | 132 | |
133 | - if($offset === null) { |
|
133 | + if ($offset === null) { |
|
134 | 134 | $offset = 0; |
135 | 135 | } |
136 | 136 | |
@@ -164,22 +164,22 @@ discard block |
||
164 | 164 | $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
165 | 165 | $subAdminManager = $this->groupManager->getSubAdmin(); |
166 | 166 | |
167 | - if($this->userManager->userExists($userid)) { |
|
167 | + if ($this->userManager->userExists($userid)) { |
|
168 | 168 | $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
169 | 169 | throw new OCSException('User already exists', 102); |
170 | 170 | } |
171 | 171 | |
172 | - if(is_array($groups)) { |
|
172 | + if (is_array($groups)) { |
|
173 | 173 | foreach ($groups as $group) { |
174 | - if(!$this->groupManager->groupExists($group)) { |
|
174 | + if (!$this->groupManager->groupExists($group)) { |
|
175 | 175 | throw new OCSException('group '.$group.' does not exist', 104); |
176 | 176 | } |
177 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
178 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
177 | + if (!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
178 | + throw new OCSException('insufficient privileges for group '.$group, 105); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | } else { |
182 | - if(!$isAdmin) { |
|
182 | + if (!$isAdmin) { |
|
183 | 183 | throw new OCSException('no group specified (required for subadmins)', 106); |
184 | 184 | } |
185 | 185 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | public function getCurrentUser() { |
229 | 229 | $user = $this->userSession->getUser(); |
230 | 230 | if ($user) { |
231 | - $data = $this->getUserData($user->getUID()); |
|
231 | + $data = $this->getUserData($user->getUID()); |
|
232 | 232 | // rename "displayname" to "display-name" only for this call to keep |
233 | 233 | // the API stable. |
234 | 234 | $data['display-name'] = $data['displayname']; |
@@ -254,17 +254,17 @@ discard block |
||
254 | 254 | |
255 | 255 | // Check if the target user exists |
256 | 256 | $targetUserObject = $this->userManager->get($userId); |
257 | - if($targetUserObject === null) { |
|
257 | + if ($targetUserObject === null) { |
|
258 | 258 | throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
259 | 259 | } |
260 | 260 | |
261 | 261 | // Admin? Or SubAdmin? |
262 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
262 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
263 | 263 | || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
264 | 264 | $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
265 | 265 | } else { |
266 | 266 | // Check they are looking up themselves |
267 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
267 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
268 | 268 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
269 | 269 | } |
270 | 270 | } |
@@ -309,12 +309,12 @@ discard block |
||
309 | 309 | $currentLoggedInUser = $this->userSession->getUser(); |
310 | 310 | |
311 | 311 | $targetUser = $this->userManager->get($userId); |
312 | - if($targetUser === null) { |
|
312 | + if ($targetUser === null) { |
|
313 | 313 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
314 | 314 | } |
315 | 315 | |
316 | 316 | $permittedFields = []; |
317 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
317 | + if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
318 | 318 | // Editing self (display, email) |
319 | 319 | if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
320 | 320 | $permittedFields[] = 'display'; |
@@ -340,13 +340,13 @@ discard block |
||
340 | 340 | } |
341 | 341 | |
342 | 342 | // If admin they can edit their own quota |
343 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
343 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
344 | 344 | $permittedFields[] = 'quota'; |
345 | 345 | } |
346 | 346 | } else { |
347 | 347 | // Check if admin / subadmin |
348 | 348 | $subAdminManager = $this->groupManager->getSubAdmin(); |
349 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
349 | + if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
350 | 350 | || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
351 | 351 | // They have permissions over the user |
352 | 352 | $permittedFields[] = 'display'; |
@@ -365,18 +365,18 @@ discard block |
||
365 | 365 | } |
366 | 366 | } |
367 | 367 | // Check if permitted to edit this field |
368 | - if(!in_array($key, $permittedFields)) { |
|
368 | + if (!in_array($key, $permittedFields)) { |
|
369 | 369 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
370 | 370 | } |
371 | 371 | // Process the edit |
372 | - switch($key) { |
|
372 | + switch ($key) { |
|
373 | 373 | case 'display': |
374 | 374 | case AccountManager::PROPERTY_DISPLAYNAME: |
375 | 375 | $targetUser->setDisplayName($value); |
376 | 376 | break; |
377 | 377 | case 'quota': |
378 | 378 | $quota = $value; |
379 | - if($quota !== 'none' && $quota !== 'default') { |
|
379 | + if ($quota !== 'none' && $quota !== 'default') { |
|
380 | 380 | if (is_numeric($quota)) { |
381 | 381 | $quota = (float) $quota; |
382 | 382 | } else { |
@@ -385,9 +385,9 @@ discard block |
||
385 | 385 | if ($quota === false) { |
386 | 386 | throw new OCSException('Invalid quota value '.$value, 103); |
387 | 387 | } |
388 | - if($quota === 0) { |
|
388 | + if ($quota === 0) { |
|
389 | 389 | $quota = 'default'; |
390 | - }else if($quota === -1) { |
|
390 | + } else if ($quota === -1) { |
|
391 | 391 | $quota = 'none'; |
392 | 392 | } else { |
393 | 393 | $quota = \OCP\Util::humanFileSize($quota); |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value); |
407 | 407 | break; |
408 | 408 | case AccountManager::PROPERTY_EMAIL: |
409 | - if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
409 | + if (filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
410 | 410 | $targetUser->setEMailAddress($value); |
411 | 411 | } else { |
412 | 412 | throw new OCSException('', 102); |
@@ -442,18 +442,18 @@ discard block |
||
442 | 442 | |
443 | 443 | $targetUser = $this->userManager->get($userId); |
444 | 444 | |
445 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
445 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
446 | 446 | throw new OCSException('', 101); |
447 | 447 | } |
448 | 448 | |
449 | 449 | // If not permitted |
450 | 450 | $subAdminManager = $this->groupManager->getSubAdmin(); |
451 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
451 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
452 | 452 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
453 | 453 | } |
454 | 454 | |
455 | 455 | // Go ahead with the delete |
456 | - if($targetUser->delete()) { |
|
456 | + if ($targetUser->delete()) { |
|
457 | 457 | return new DataResponse(); |
458 | 458 | } else { |
459 | 459 | throw new OCSException('', 101); |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | $currentLoggedInUser = $this->userSession->getUser(); |
498 | 498 | |
499 | 499 | $targetUser = $this->userManager->get($userId); |
500 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
500 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
501 | 501 | throw new OCSException('', 101); |
502 | 502 | } |
503 | 503 | |
504 | 504 | // If not permitted |
505 | 505 | $subAdminManager = $this->groupManager->getSubAdmin(); |
506 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
506 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
507 | 507 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
508 | 508 | } |
509 | 509 | |
@@ -524,11 +524,11 @@ discard block |
||
524 | 524 | $loggedInUser = $this->userSession->getUser(); |
525 | 525 | |
526 | 526 | $targetUser = $this->userManager->get($userId); |
527 | - if($targetUser === null) { |
|
527 | + if ($targetUser === null) { |
|
528 | 528 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
529 | 529 | } |
530 | 530 | |
531 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
531 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
532 | 532 | // Self lookup or admin lookup |
533 | 533 | return new DataResponse([ |
534 | 534 | 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | $subAdminManager = $this->groupManager->getSubAdmin(); |
538 | 538 | |
539 | 539 | // Looking up someone else |
540 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
540 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
541 | 541 | // Return the group that the method caller is subadmin of for the user in question |
542 | 542 | /** @var IGroup[] $getSubAdminsGroups */ |
543 | 543 | $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
@@ -567,16 +567,16 @@ discard block |
||
567 | 567 | * @throws OCSException |
568 | 568 | */ |
569 | 569 | public function addToGroup($userId, $groupid = '') { |
570 | - if($groupid === '') { |
|
570 | + if ($groupid === '') { |
|
571 | 571 | throw new OCSException('', 101); |
572 | 572 | } |
573 | 573 | |
574 | 574 | $group = $this->groupManager->get($groupid); |
575 | 575 | $targetUser = $this->userManager->get($userId); |
576 | - if($group === null) { |
|
576 | + if ($group === null) { |
|
577 | 577 | throw new OCSException('', 102); |
578 | 578 | } |
579 | - if($targetUser === null) { |
|
579 | + if ($targetUser === null) { |
|
580 | 580 | throw new OCSException('', 103); |
581 | 581 | } |
582 | 582 | |
@@ -604,17 +604,17 @@ discard block |
||
604 | 604 | public function removeFromGroup($userId, $groupid) { |
605 | 605 | $loggedInUser = $this->userSession->getUser(); |
606 | 606 | |
607 | - if($groupid === null || trim($groupid) === '') { |
|
607 | + if ($groupid === null || trim($groupid) === '') { |
|
608 | 608 | throw new OCSException('', 101); |
609 | 609 | } |
610 | 610 | |
611 | 611 | $group = $this->groupManager->get($groupid); |
612 | - if($group === null) { |
|
612 | + if ($group === null) { |
|
613 | 613 | throw new OCSException('', 102); |
614 | 614 | } |
615 | 615 | |
616 | 616 | $targetUser = $this->userManager->get($userId); |
617 | - if($targetUser === null) { |
|
617 | + if ($targetUser === null) { |
|
618 | 618 | throw new OCSException('', 103); |
619 | 619 | } |
620 | 620 | |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
639 | 639 | /** @var IGroup[] $subAdminGroups */ |
640 | 640 | $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
641 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
641 | + $subAdminGroups = array_map(function(IGroup $subAdminGroup) { |
|
642 | 642 | return $subAdminGroup->getGID(); |
643 | 643 | }, $subAdminGroups); |
644 | 644 | $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
@@ -670,15 +670,15 @@ discard block |
||
670 | 670 | $user = $this->userManager->get($userId); |
671 | 671 | |
672 | 672 | // Check if the user exists |
673 | - if($user === null) { |
|
673 | + if ($user === null) { |
|
674 | 674 | throw new OCSException('User does not exist', 101); |
675 | 675 | } |
676 | 676 | // Check if group exists |
677 | - if($group === null) { |
|
678 | - throw new OCSException('Group does not exist', 102); |
|
677 | + if ($group === null) { |
|
678 | + throw new OCSException('Group does not exist', 102); |
|
679 | 679 | } |
680 | 680 | // Check if trying to make subadmin of admin group |
681 | - if($group->getGID() === 'admin') { |
|
681 | + if ($group->getGID() === 'admin') { |
|
682 | 682 | throw new OCSException('Cannot create subadmins for admin group', 103); |
683 | 683 | } |
684 | 684 | |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | return new DataResponse(); |
690 | 690 | } |
691 | 691 | // Go |
692 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
692 | + if ($subAdminManager->createSubAdmin($user, $group)) { |
|
693 | 693 | return new DataResponse(); |
694 | 694 | } else { |
695 | 695 | throw new OCSException('Unknown error occurred', 103); |
@@ -712,20 +712,20 @@ discard block |
||
712 | 712 | $subAdminManager = $this->groupManager->getSubAdmin(); |
713 | 713 | |
714 | 714 | // Check if the user exists |
715 | - if($user === null) { |
|
715 | + if ($user === null) { |
|
716 | 716 | throw new OCSException('User does not exist', 101); |
717 | 717 | } |
718 | 718 | // Check if the group exists |
719 | - if($group === null) { |
|
719 | + if ($group === null) { |
|
720 | 720 | throw new OCSException('Group does not exist', 101); |
721 | 721 | } |
722 | 722 | // Check if they are a subadmin of this said group |
723 | - if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
723 | + if (!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
|
724 | 724 | throw new OCSException('User is not a subadmin of this group', 102); |
725 | 725 | } |
726 | 726 | |
727 | 727 | // Go |
728 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
728 | + if ($subAdminManager->deleteSubAdmin($user, $group)) { |
|
729 | 729 | return new DataResponse(); |
730 | 730 | } else { |
731 | 731 | throw new OCSException('Unknown error occurred', 103); |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | public function getUserSubAdminGroups($userId) { |
743 | 743 | $user = $this->userManager->get($userId); |
744 | 744 | // Check if the user exists |
745 | - if($user === null) { |
|
745 | + if ($user === null) { |
|
746 | 746 | throw new OCSException('User does not exist', 101); |
747 | 747 | } |
748 | 748 | |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | $groups[$key] = $group->getGID(); |
753 | 753 | } |
754 | 754 | |
755 | - if(!$groups) { |
|
755 | + if (!$groups) { |
|
756 | 756 | throw new OCSException('Unknown error occurred', 102); |
757 | 757 | } else { |
758 | 758 | return new DataResponse($groups); |
@@ -796,13 +796,13 @@ discard block |
||
796 | 796 | $currentLoggedInUser = $this->userSession->getUser(); |
797 | 797 | |
798 | 798 | $targetUser = $this->userManager->get($userId); |
799 | - if($targetUser === null) { |
|
799 | + if ($targetUser === null) { |
|
800 | 800 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
801 | 801 | } |
802 | 802 | |
803 | 803 | // Check if admin / subadmin |
804 | 804 | $subAdminManager = $this->groupManager->getSubAdmin(); |
805 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
805 | + if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
806 | 806 | && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
807 | 807 | // No rights |
808 | 808 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
@@ -824,8 +824,8 @@ discard block |
||
824 | 824 | $this->newUserMailHelper->setL10N($l10n); |
825 | 825 | $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
826 | 826 | $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
827 | - } catch(\Exception $e) { |
|
828 | - $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
827 | + } catch (\Exception $e) { |
|
828 | + $this->logger->error("Can't send new user mail to $email: ".$e->getMessage(), array('app' => 'settings')); |
|
829 | 829 | throw new OCSException('Sending email failed', 102); |
830 | 830 | } |
831 | 831 |