diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 6a7bf6681293d..ca7d7fac63e8b 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -1221,7 +1221,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 9e2da244f7bb1..24bdfbcaa15e3 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -2801,6 +2801,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);