diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index b0e035531f434..fba7297806a3b 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -1566,7 +1566,12 @@ public function addToGroup(string $userId, string $groupid = ''): DataResponse { $subAdminManager = $this->groupManager->getSubAdmin(); $isAdmin = $this->groupManager->isAdmin($loggedInUser->getUID()); $isDelegatedAdmin = $this->groupManager->isDelegatedAdmin($loggedInUser->getUID()); - if (!$isAdmin && !($isDelegatedAdmin && $groupid !== 'admin') && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) { + if ( + !$isAdmin + && !($isDelegatedAdmin && $groupid !== 'admin') + // Group admin can add users to its groups only if it can see them + && !($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 05553d6b3e9aa..30b73b0f860f1 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -3110,6 +3110,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);