summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-01-18 11:56:24 +0100
committerJoas Schilling <coding@schilljs.com>2017-01-18 11:56:24 +0100
commitd80a4453af8271040026b781edb3c915468f6d52 (patch)
tree2eb69052cab1ef145d29db297c9f9d886334dd63 /apps/provisioning_api/lib
parent55db07a20b0e195c9a8295c06b69f7e0debdd30b (diff)
downloadnextcloud-server-d80a4453af8271040026b781edb3c915468f6d52.tar.gz
nextcloud-server-d80a4453af8271040026b781edb3c915468f6d52.zip
Make sure subadmins can not delete users from their last subadmin group
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/provisioning_api/lib')
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index eb09210275d..022cbf92814 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -507,6 +507,20 @@ class UsersController extends OCSController {
// Not an admin, so the user must be a subadmin of this group, but that is not allowed.
throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105);
}
+
+ } else if (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
+ /** @var IGroup[] $subAdminGroups */
+ $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
+ $subAdminGroups = array_map(function (IGroup $subAdminGroup) {
+ return $subAdminGroup->getGID();
+ }, $subAdminGroups);
+ $userGroups = $this->groupManager->getUserGroupIds($targetUser);
+ $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups);
+
+ if (count($userSubAdminGroups) <= 1) {
+ // Subadmin must not be able to remove a user from all their subadmin groups.
+ throw new OCSException('Cannot remove user from this group as this is the only remaining group you are a SubAdmin of', 105);
+ }
}
// Remove user from group