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
23 changes: 19 additions & 4 deletions lib/private/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@
return $this->users;
}

$this->users = $this->getVerifiedUsers($this->getBackendUserIds());
$this->usersLoaded = true;
return $this->users;
}

#[\Override]
public function getUserIds(): array {
if ($this->usersLoaded) {
return array_keys($this->users);
}

return $this->getBackendUserIds();
}

/**
* @return list<string>
*/
private function getBackendUserIds(): array {
$userIds = [];
foreach ($this->backends as $backend) {
$diff = array_diff(
Expand All @@ -114,10 +132,7 @@
$userIds = array_merge($userIds, $diff);
}
}

$this->users = $this->getVerifiedUsers($userIds);
$this->usersLoaded = true;
return $this->users;
return array_values($userIds);

Check failure on line 135 in lib/private/Group/Group.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantFunctionCall

lib/private/Group/Group.php:135:10: RedundantFunctionCall: The call to array_values is unnecessary, list<string> is already a list (see https://psalm.dev/280)
}

/**
Expand Down
4 changes: 1 addition & 3 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1472,9 +1472,7 @@ public function getAccessList($nodes, $currentAccess) {
continue;
}

$userList = $group->getUsers();
foreach ($userList as $user) {
$uid = $user->getUID();
foreach ($group->getUserIds() as $uid) {
$users[$uid] = $users[$uid] ?? [];
$users[$uid][$row['id']] = $row;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/public/IGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public function setDisplayName(string $displayName): bool;
*/
public function getUsers(): array;

/**
* Get the ids of all users in the group
*
* Unlike {@see self::getUsers()} the ids are not checked against the user
* backends, so they can contain users that no longer exist.
*
* @return list<string>
* @since 36.0.0
*/
public function getUserIds(): array;

/**
* check if a user is in the group
*
Expand Down
36 changes: 36 additions & 0 deletions tests/lib/Group/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace Test\Group;

use OC\Group\Database;
use OC\Group\Group;
use OC\User\Manager;
use OC\User\User;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\BeforeGroupChangedEvent;
Expand Down Expand Up @@ -116,6 +118,40 @@ public function testGetUsersMultipleBackends(): void {
$this->assertEquals('user3', $user3->getUID());
}

public function testGetUserIdsMultipleBackends(): void {
$backend1 = $this->createMock(Database::class);
$backend2 = $this->createMock(Database::class);
$userManager = $this->createMock(Manager::class);
$userManager->expects($this->never())
->method('get');
$group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);

$backend1->expects($this->once())
->method('usersInGroup')
->with('group1')
->willReturn(['user1', 'user2']);
$backend2->expects($this->once())
->method('usersInGroup')
->with('group1')
->willReturn(['user2', '3']);

$this->assertSame(['user1', 'user2', '3'], $group->getUserIds());
}

public function testGetUserIdsReusesLoadedUsers(): void {
$backend = $this->createMock(Database::class);
$userManager = $this->getUserManager();
$group = new Group('group1', [$backend], $this->dispatcher, $userManager);

$backend->expects($this->once())
->method('usersInGroup')
->with('group1')
->willReturn(['user1', 'user2']);

$group->getUsers();
$this->assertSame(['user1', 'user2'], $group->getUserIds());
}

public function testInGroupSingleBackend(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
Expand Down
Loading