Skip to content

Commit 6cfc948

Browse files
committed
fix(provisioning_api): group admins can't add all users to groups
Group admins can't add users they are not supposed to see to their groups Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
1 parent ebdc8ec commit 6cfc948

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎apps/provisioning_api/lib/Controller/UsersController.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,10 @@ public function addToGroup(string $userId, string $groupid = ''): DataResponse {
13681368
// If they're not an admin, check they are a subadmin of the group in question
13691369
$loggedInUser = $this->userSession->getUser();
13701370
$subAdminManager = $this->groupManager->getSubAdmin();
1371-
if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
1371+
if (
1372+
!$this->groupManager->isAdmin($loggedInUser->getUID())
1373+
&& !($subAdminManager->isSubAdminOfGroup($loggedInUser, $group) && $subAdminManager->isUserAccessible($loggedInUser, $targetUser))
1374+
) {
13721375
throw new OCSException('', 104);
13731376
}
13741377

‎apps/provisioning_api/tests/Controller/UsersControllerTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,6 +3102,11 @@ public function testAddToGroupSuccessAsSubadmin() {
31023102
->with($loggedInUser, $targetGroup)
31033103
->willReturn(true);
31043104

3105+
$subAdminManager->expects($this->once())
3106+
->method('isUserAccessible')
3107+
->with($loggedInUser, $targetUser)
3108+
->willReturn(true);
3109+
31053110
$this->groupManager->expects($this->once())
31063111
->method('getSubAdmin')
31073112
->willReturn($subAdminManager);

0 commit comments

Comments
 (0)