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
15 changes: 15 additions & 0 deletions lib/Space/SpaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,20 @@ public function removeUsersFromWorkspace(int $id, array $uids): void {
throw new OCSBadRequestException('uids params must contain an array of strings');
}

$userGid = UserGroup::get($id);
$userGroup = $this->groupManager->get($userGid);

$usersNotExist = [];
$usersAreNotPresentInWorkspace = [];
foreach ($uids as $uid) {
$user = $this->userManager->get($uid);
if (is_null($user)) {
$usersNotExist[] = $uid;
continue;
}

if (!$userGroup->inGroup($user)) {
$usersAreNotPresentInWorkspace[] = $uid;
}
}

Expand All @@ -444,6 +453,12 @@ public function removeUsersFromWorkspace(int $id, array $uids): void {
throw new OCSBadRequestException('These users not exist on your Nextcloud instance : ' . PHP_EOL . $formattedUsers);
}

if (!empty($usersAreNotPresentInWorkspace)) {
$formattedUsers = implode(array_map(fn ($user) => "- {$user}\n", $usersAreNotPresentInWorkspace));
throw new NotFoundException("These users were not found in the workspace {$space['name']}: {$formattedUsers}");

}

$managerGid = WorkspaceManagerGroup::get($id);
$managerGroup = $this->groupManager->get($managerGid);

Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Space/SpaceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,15 @@ public function testRemoveUsersFromWorkspace(): void {
})
;

$userGroup
->expects($this->any())
->method('inGroup')
->with(
$this->logicalOr($user1, $user2)
)
->willReturnOnConsecutiveCalls(true, true)
;

$userGroup
->expects($this->any())
->method('removeUser')
Expand Down
Loading