Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,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);
}

Expand Down
60 changes: 60 additions & 0 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3502,6 +3502,11 @@ public function testAddToGroupSuccessAsSubadmin(): void {
->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);
Expand All @@ -3522,6 +3527,61 @@ public function testAddToGroupSuccessAsSubadmin(): void {
$this->assertEquals(new DataResponse(), $this->api->addToGroup('TargetUser', 'GroupToAddTo'));
}

public function testAddInvisibleUserToGroupFailAsSubadmin(): void {
$targetUser = $this->createMock(IUser::class);
$loggedInUser = $this->createMock(IUser::class);
$loggedInUser
->expects($this->exactly(2))
->method('getUID')
->willReturn('subadmin');

$targetGroup = $this->createMock(IGroup::class);

$this->groupManager
->expects($this->once())
->method('get')
->with('GroupToAddTo')
->willReturn($targetGroup);

$subAdminManager = $this->createMock(SubAdmin::class);
$subAdminManager
->expects($this->once())
->method('isSubAdminOfGroup')
->with($loggedInUser, $targetGroup)
->willReturn(true);

$subAdminManager
->expects($this->once())
->method('isUserAccessible')
->with($loggedInUser, $targetUser)
->willReturn(false);

$this->groupManager
->expects($this->once())
->method('getSubAdmin')
->willReturn($subAdminManager);
$this->groupManager
->expects($this->once())
->method('isAdmin')
->with('subadmin')
->willReturn(false);

$this->userManager
->expects($this->once())
->method('get')
->with('TargetUser')
->willReturn($targetUser);

$this->userSession
->expects($this->once())
->method('getUser')
->willReturn($loggedInUser);

$this->expectException(OCSException::class);
$this->expectExceptionCode(104);
$this->api->addToGroup('TargetUser', 'GroupToAddTo');
}

public function testAddToGroupSuccessAsAdmin(): void {
$targetUser = $this->createMock(IUser::class);
$loggedInUser = $this->createMock(IUser::class);
Expand Down
Loading