diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 7dfdea991e5f2..4ecca2684d1fe 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -1234,7 +1234,10 @@ public function addToGroup(string $userId, string $groupid = ''): DataResponse { // If they're not an admin, check they are a subadmin of the group in question $loggedInUser = $this->userSession->getUser(); $subAdminManager = $this->groupManager->getSubAdmin(); - if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { + if ( + !$this->groupManager->isAdmin($loggedInUser->getUID()) + && !($subAdminManager->isSubAdminOfGroup($loggedInUser, $group) && $subAdminManager->isUserAccessible($loggedInUser, $targetUser)) + ) { throw new OCSException('', 104); } diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 56a47f23a5cc4..d6d80aeda6a03 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -2964,6 +2964,11 @@ public function testAddToGroupSuccessAsSubadmin() { ->with($loggedInUser, $targetGroup) ->willReturn(true); + $subAdminManager->expects($this->once()) + ->method('isUserAccessible') + ->with($loggedInUser, $targetUser) + ->willReturn(true); + $this->groupManager->expects($this->once()) ->method('getSubAdmin') ->willReturn($subAdminManager);