|
@@ 655-684 (lines=30) @@
|
| 652 |
|
* @return DataResponse |
| 653 |
|
* @throws OCSException |
| 654 |
|
*/ |
| 655 |
|
public function addSubAdmin($userId, $groupid) { |
| 656 |
|
$group = $this->groupManager->get($groupid); |
| 657 |
|
$user = $this->userManager->get($userId); |
| 658 |
|
|
| 659 |
|
// Check if the user exists |
| 660 |
|
if($user === null) { |
| 661 |
|
throw new OCSException('User does not exist', 101); |
| 662 |
|
} |
| 663 |
|
// Check if group exists |
| 664 |
|
if($group === null) { |
| 665 |
|
throw new OCSException('Group does not exist', 102); |
| 666 |
|
} |
| 667 |
|
// Check if trying to make subadmin of admin group |
| 668 |
|
if($group->getGID() === 'admin') { |
| 669 |
|
throw new OCSException('Cannot create subadmins for admin group', 103); |
| 670 |
|
} |
| 671 |
|
|
| 672 |
|
$subAdminManager = $this->groupManager->getSubAdmin(); |
| 673 |
|
|
| 674 |
|
// We cannot be subadmin twice |
| 675 |
|
if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
| 676 |
|
return new DataResponse(); |
| 677 |
|
} |
| 678 |
|
// Go |
| 679 |
|
if($subAdminManager->createSubAdmin($user, $group)) { |
| 680 |
|
return new DataResponse(); |
| 681 |
|
} else { |
| 682 |
|
throw new OCSException('Unknown error occurred', 103); |
| 683 |
|
} |
| 684 |
|
} |
| 685 |
|
|
| 686 |
|
/** |
| 687 |
|
* Removes a subadmin from a group |
|
@@ 696-720 (lines=25) @@
|
| 693 |
|
* @return DataResponse |
| 694 |
|
* @throws OCSException |
| 695 |
|
*/ |
| 696 |
|
public function removeSubAdmin($userId, $groupid) { |
| 697 |
|
$group = $this->groupManager->get($groupid); |
| 698 |
|
$user = $this->userManager->get($userId); |
| 699 |
|
$subAdminManager = $this->groupManager->getSubAdmin(); |
| 700 |
|
|
| 701 |
|
// Check if the user exists |
| 702 |
|
if($user === null) { |
| 703 |
|
throw new OCSException('User does not exist', 101); |
| 704 |
|
} |
| 705 |
|
// Check if the group exists |
| 706 |
|
if($group === null) { |
| 707 |
|
throw new OCSException('Group does not exist', 101); |
| 708 |
|
} |
| 709 |
|
// Check if they are a subadmin of this said group |
| 710 |
|
if(!$subAdminManager->isSubAdminOfGroup($user, $group)) { |
| 711 |
|
throw new OCSException('User is not a subadmin of this group', 102); |
| 712 |
|
} |
| 713 |
|
|
| 714 |
|
// Go |
| 715 |
|
if($subAdminManager->deleteSubAdmin($user, $group)) { |
| 716 |
|
return new DataResponse(); |
| 717 |
|
} else { |
| 718 |
|
throw new OCSException('Unknown error occurred', 103); |
| 719 |
|
} |
| 720 |
|
} |
| 721 |
|
|
| 722 |
|
/** |
| 723 |
|
* Get the groups a user is a subadmin of |