@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | // Admin? Or SubAdmin? |
140 | 140 | $uid = $user->getUID(); |
141 | 141 | $subAdminManager = $this->groupManager->getSubAdmin(); |
142 | - if($this->groupManager->isAdmin($uid)){ |
|
142 | + if ($this->groupManager->isAdmin($uid)) { |
|
143 | 143 | $users = $this->userManager->search($search, $limit, $offset); |
144 | 144 | } else if ($subAdminManager->isSubAdmin($user)) { |
145 | 145 | $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $subAdminOfGroups[$key] = $group->getGID(); |
148 | 148 | } |
149 | 149 | |
150 | - if($offset === null) { |
|
150 | + if ($offset === null) { |
|
151 | 151 | $offset = 0; |
152 | 152 | } |
153 | 153 | |
@@ -181,22 +181,22 @@ discard block |
||
181 | 181 | $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
182 | 182 | $subAdminManager = $this->groupManager->getSubAdmin(); |
183 | 183 | |
184 | - if($this->userManager->userExists($userid)) { |
|
184 | + if ($this->userManager->userExists($userid)) { |
|
185 | 185 | $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
186 | 186 | throw new OCSException('User already exists', 102); |
187 | 187 | } |
188 | 188 | |
189 | - if(is_array($groups)) { |
|
189 | + if (is_array($groups)) { |
|
190 | 190 | foreach ($groups as $group) { |
191 | - if(!$this->groupManager->groupExists($group)) { |
|
191 | + if (!$this->groupManager->groupExists($group)) { |
|
192 | 192 | throw new OCSException('group '.$group.' does not exist', 104); |
193 | 193 | } |
194 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
195 | - throw new OCSException('insufficient privileges for group '. $group, 105); |
|
194 | + if (!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
195 | + throw new OCSException('insufficient privileges for group '.$group, 105); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } else { |
199 | - if(!$isAdmin) { |
|
199 | + if (!$isAdmin) { |
|
200 | 200 | throw new OCSException('no group specified (required for subadmins)', 106); |
201 | 201 | } |
202 | 202 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | public function getCurrentUser() { |
246 | 246 | $user = $this->userSession->getUser(); |
247 | 247 | if ($user) { |
248 | - $data = $this->getUserData($user->getUID()); |
|
248 | + $data = $this->getUserData($user->getUID()); |
|
249 | 249 | // rename "displayname" to "display-name" only for this call to keep |
250 | 250 | // the API stable. |
251 | 251 | $data['display-name'] = $data['displayname']; |
@@ -271,17 +271,17 @@ discard block |
||
271 | 271 | |
272 | 272 | // Check if the target user exists |
273 | 273 | $targetUserObject = $this->userManager->get($userId); |
274 | - if($targetUserObject === null) { |
|
274 | + if ($targetUserObject === null) { |
|
275 | 275 | throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND); |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Admin? Or SubAdmin? |
279 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
279 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
280 | 280 | || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
281 | 281 | $data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true'); |
282 | 282 | } else { |
283 | 283 | // Check they are looking up themselves |
284 | - if($currentLoggedInUser->getUID() !== $userId) { |
|
284 | + if ($currentLoggedInUser->getUID() !== $userId) { |
|
285 | 285 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
286 | 286 | } |
287 | 287 | } |
@@ -325,12 +325,12 @@ discard block |
||
325 | 325 | $currentLoggedInUser = $this->userSession->getUser(); |
326 | 326 | |
327 | 327 | $targetUser = $this->userManager->get($userId); |
328 | - if($targetUser === null) { |
|
328 | + if ($targetUser === null) { |
|
329 | 329 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
330 | 330 | } |
331 | 331 | |
332 | 332 | $permittedFields = []; |
333 | - if($userId === $currentLoggedInUser->getUID()) { |
|
333 | + if ($userId === $currentLoggedInUser->getUID()) { |
|
334 | 334 | // Editing self (display, email) |
335 | 335 | $permittedFields[] = 'display'; |
336 | 336 | $permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME; |
@@ -341,13 +341,13 @@ discard block |
||
341 | 341 | $permittedFields[] = AccountManager::PROPERTY_WEBSITE; |
342 | 342 | $permittedFields[] = AccountManager::PROPERTY_TWITTER; |
343 | 343 | // If admin they can edit their own quota |
344 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
344 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
345 | 345 | $permittedFields[] = 'quota'; |
346 | 346 | } |
347 | 347 | } else { |
348 | 348 | // Check if admin / subadmin |
349 | 349 | $subAdminManager = $this->groupManager->getSubAdmin(); |
350 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
350 | + if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
351 | 351 | || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
352 | 352 | // They have permissions over the user |
353 | 353 | $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); |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | $targetUser->setPassword($value); |
400 | 400 | break; |
401 | 401 | case AccountManager::PROPERTY_EMAIL: |
402 | - if(filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
402 | + if (filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
403 | 403 | $targetUser->setEMailAddress($value); |
404 | 404 | } else { |
405 | 405 | throw new OCSException('', 102); |
@@ -435,18 +435,18 @@ discard block |
||
435 | 435 | |
436 | 436 | $targetUser = $this->userManager->get($userId); |
437 | 437 | |
438 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
438 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
439 | 439 | throw new OCSException('', 101); |
440 | 440 | } |
441 | 441 | |
442 | 442 | // If not permitted |
443 | 443 | $subAdminManager = $this->groupManager->getSubAdmin(); |
444 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
444 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
445 | 445 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
446 | 446 | } |
447 | 447 | |
448 | 448 | // Go ahead with the delete |
449 | - if($targetUser->delete()) { |
|
449 | + if ($targetUser->delete()) { |
|
450 | 450 | return new DataResponse(); |
451 | 451 | } else { |
452 | 452 | throw new OCSException('', 101); |
@@ -490,13 +490,13 @@ discard block |
||
490 | 490 | $currentLoggedInUser = $this->userSession->getUser(); |
491 | 491 | |
492 | 492 | $targetUser = $this->userManager->get($userId); |
493 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
493 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
494 | 494 | throw new OCSException('', 101); |
495 | 495 | } |
496 | 496 | |
497 | 497 | // If not permitted |
498 | 498 | $subAdminManager = $this->groupManager->getSubAdmin(); |
499 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
499 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
500 | 500 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
501 | 501 | } |
502 | 502 | |
@@ -517,11 +517,11 @@ discard block |
||
517 | 517 | $loggedInUser = $this->userSession->getUser(); |
518 | 518 | |
519 | 519 | $targetUser = $this->userManager->get($userId); |
520 | - if($targetUser === null) { |
|
520 | + if ($targetUser === null) { |
|
521 | 521 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
522 | 522 | } |
523 | 523 | |
524 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
524 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
525 | 525 | // Self lookup or admin lookup |
526 | 526 | return new DataResponse([ |
527 | 527 | 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | $subAdminManager = $this->groupManager->getSubAdmin(); |
531 | 531 | |
532 | 532 | // Looking up someone else |
533 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
533 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
534 | 534 | // Return the group that the method caller is subadmin of for the user in question |
535 | 535 | /** @var IGroup[] $getSubAdminsGroups */ |
536 | 536 | $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
@@ -560,16 +560,16 @@ discard block |
||
560 | 560 | * @throws OCSException |
561 | 561 | */ |
562 | 562 | public function addToGroup($userId, $groupid = '') { |
563 | - if($groupid === '') { |
|
563 | + if ($groupid === '') { |
|
564 | 564 | throw new OCSException('', 101); |
565 | 565 | } |
566 | 566 | |
567 | 567 | $group = $this->groupManager->get($groupid); |
568 | 568 | $targetUser = $this->userManager->get($userId); |
569 | - if($group === null) { |
|
569 | + if ($group === null) { |
|
570 | 570 | throw new OCSException('', 102); |
571 | 571 | } |
572 | - if($targetUser === null) { |
|
572 | + if ($targetUser === null) { |
|
573 | 573 | throw new OCSException('', 103); |
574 | 574 | } |
575 | 575 | |
@@ -597,17 +597,17 @@ discard block |
||
597 | 597 | public function removeFromGroup($userId, $groupid) { |
598 | 598 | $loggedInUser = $this->userSession->getUser(); |
599 | 599 | |
600 | - if($groupid === null) { |
|
600 | + if ($groupid === null) { |
|
601 | 601 | throw new OCSException('', 101); |
602 | 602 | } |
603 | 603 | |
604 | 604 | $group = $this->groupManager->get($groupid); |
605 | - if($group === null) { |
|
605 | + if ($group === null) { |
|
606 | 606 | throw new OCSException('', 102); |
607 | 607 | } |
608 | 608 | |
609 | 609 | $targetUser = $this->userManager->get($userId); |
610 | - if($targetUser === null) { |
|
610 | + if ($targetUser === null) { |
|
611 | 611 | throw new OCSException('', 103); |
612 | 612 | } |
613 | 613 | |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) { |
632 | 632 | /** @var IGroup[] $subAdminGroups */ |
633 | 633 | $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
634 | - $subAdminGroups = array_map(function (IGroup $subAdminGroup) { |
|
634 | + $subAdminGroups = array_map(function(IGroup $subAdminGroup) { |
|
635 | 635 | return $subAdminGroup->getGID(); |
636 | 636 | }, $subAdminGroups); |
637 | 637 | $userGroups = $this->groupManager->getUserGroupIds($targetUser); |
@@ -663,15 +663,15 @@ discard block |
||
663 | 663 | $user = $this->userManager->get($userId); |
664 | 664 | |
665 | 665 | // Check if the user exists |
666 | - if($user === null) { |
|
666 | + if ($user === null) { |
|
667 | 667 | throw new OCSException('User does not exist', 101); |
668 | 668 | } |
669 | 669 | // Check if group exists |
670 | - if($group === null) { |
|
671 | - throw new OCSException('Group:'.$groupid.' does not exist', 102); |
|
670 | + if ($group === null) { |
|
671 | + throw new OCSException('Group:'.$groupid.' does not exist', 102); |
|
672 | 672 | } |
673 | 673 | // Check if trying to make subadmin of admin group |
674 | - if(strtolower($groupid) === 'admin') { |
|
674 | + if (strtolower($groupid) === 'admin') { |
|
675 | 675 | throw new OCSException('Cannot create subadmins for admin group', 103); |
676 | 676 | } |
677 | 677 | |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | return new DataResponse(); |
683 | 683 | } |
684 | 684 | // Go |
685 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
685 | + if ($subAdminManager->createSubAdmin($user, $group)) { |
|
686 | 686 | return new DataResponse(); |
687 | 687 | } else { |
688 | 688 | throw new OCSException('Unknown error occurred', 103); |
@@ -705,20 +705,20 @@ discard block |
||
705 | 705 | $subAdminManager = $this->groupManager->getSubAdmin(); |
706 | 706 | |
707 | 707 | // Check if the user exists |
708 | - if($user === null) { |
|
708 | + if ($user === null) { |
|
709 | 709 | throw new OCSException('User does not exist', 101); |
710 | 710 | } |
711 | 711 | // Check if the group exists |
712 | - if($group === null) { |
|
712 | + if ($group === null) { |
|
713 | 713 | throw new OCSException('Group does not exist', 101); |
714 | 714 | } |
715 | 715 | // Check if they are a subadmin of this said group |
716 | - if(!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
716 | + if (!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
717 | 717 | throw new OCSException('User is not a subadmin of this group', 102); |
718 | 718 | } |
719 | 719 | |
720 | 720 | // Go |
721 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
721 | + if ($subAdminManager->deleteSubAdmin($user, $group)) { |
|
722 | 722 | return new DataResponse(); |
723 | 723 | } else { |
724 | 724 | throw new OCSException('Unknown error occurred', 103); |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | public function getUserSubAdminGroups($userId) { |
736 | 736 | $user = $this->userManager->get($userId); |
737 | 737 | // Check if the user exists |
738 | - if($user === null) { |
|
738 | + if ($user === null) { |
|
739 | 739 | throw new OCSException('User does not exist', 101); |
740 | 740 | } |
741 | 741 | |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | $groups[$key] = $group->getGID(); |
746 | 746 | } |
747 | 747 | |
748 | - if(!$groups) { |
|
748 | + if (!$groups) { |
|
749 | 749 | throw new OCSException('Unknown error occurred', 102); |
750 | 750 | } else { |
751 | 751 | return new DataResponse($groups); |
@@ -789,13 +789,13 @@ discard block |
||
789 | 789 | $currentLoggedInUser = $this->userSession->getUser(); |
790 | 790 | |
791 | 791 | $targetUser = $this->userManager->get($userId); |
792 | - if($targetUser === null) { |
|
792 | + if ($targetUser === null) { |
|
793 | 793 | throw new OCSException('', \OCP\API::RESPOND_NOT_FOUND); |
794 | 794 | } |
795 | 795 | |
796 | 796 | // Check if admin / subadmin |
797 | 797 | $subAdminManager = $this->groupManager->getSubAdmin(); |
798 | - if(!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
798 | + if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
799 | 799 | && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
800 | 800 | // No rights |
801 | 801 | throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); |
@@ -817,8 +817,8 @@ discard block |
||
817 | 817 | $this->newUserMailHelper->setL10N($l10n); |
818 | 818 | $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); |
819 | 819 | $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); |
820 | - } catch(\Exception $e) { |
|
821 | - $this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
820 | + } catch (\Exception $e) { |
|
821 | + $this->logger->error("Can't send new user mail to $email: ".$e->getMessage(), array('app' => 'settings')); |
|
822 | 822 | throw new OCSException('Sending email failed', 102); |
823 | 823 | } |
824 | 824 |