aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGit'Fellow <12234510+solracsf@users.noreply.github.com>2024-10-31 08:09:41 +0100
committerGitHub <noreply@github.com>2024-10-31 08:09:41 +0100
commit738ddd289c945ac133067274d0118fc862fd169b (patch)
tree9c60ffe739bbc43085fb28d35a50045067237bc4
parent979b91720de89bb94638dc6e358b25a33ff26a2e (diff)
parentd07a92d85993c03a318a4fc9a399b54d4077ea80 (diff)
downloadnextcloud-server-738ddd289c945ac133067274d0118fc862fd169b.tar.gz
nextcloud-server-738ddd289c945ac133067274d0118fc862fd169b.zip
Merge pull request #48969 from nextcloud/backport/48766/stable29
[stable29] Fix disabled user list for subadmins
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php8
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php125
2 files changed, 129 insertions, 4 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index d003361d8f9..95b8840509a 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -259,21 +259,21 @@ class UsersController extends AUserData {
/* We have to handle offset ourselve for correctness */
$tempLimit = ($limit === null ? null : $limit + $offset);
foreach ($subAdminOfGroups as $group) {
- $users = array_merge(
+ $users = array_unique(array_merge(
$users,
array_map(
fn (IUser $user): string => $user->getUID(),
array_filter(
- $group->searchUsers($search, ($tempLimit === null ? null : $tempLimit - count($users))),
+ $group->searchUsers($search),
fn (IUser $user): bool => !$user->isEnabled()
)
)
- );
+ ));
if (($tempLimit !== null) && (count($users) >= $tempLimit)) {
break;
}
}
- $users = array_slice($users, $offset);
+ $users = array_slice($users, $offset, $limit);
}
$usersDetails = [];
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 92f28c6b39a..3bfea4a1194 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -248,6 +248,131 @@ class UsersControllerTest extends TestCase {
$this->assertEquals($expected, $this->api->getUsers('MyCustomSearch')->getData());
}
+ private function createUserMock(string $uid, bool $enabled): MockObject|IUser {
+ $mockUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockUser
+ ->method('getUID')
+ ->willReturn($uid);
+ $mockUser
+ ->method('isEnabled')
+ ->willReturn($enabled);
+ return $mockUser;
+ }
+
+ public function testGetDisabledUsersAsAdmin(): void {
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->willReturn('admin');
+ $this->userSession
+ ->expects($this->atLeastOnce())
+ ->method('getUser')
+ ->willReturn($loggedInUser);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->willReturn(true);
+ $this->userManager
+ ->expects($this->once())
+ ->method('getDisabledUsers')
+ ->with(3, 0, 'MyCustomSearch')
+ ->willReturn([
+ $this->createUserMock('admin', false),
+ $this->createUserMock('foo', false),
+ $this->createUserMock('bar', false),
+ ]);
+
+ $expected = [
+ 'users' => [
+ 'admin' => ['id' => 'admin'],
+ 'foo' => ['id' => 'foo'],
+ 'bar' => ['id' => 'bar'],
+ ],
+ ];
+ $this->assertEquals($expected, $this->api->getDisabledUsersDetails('MyCustomSearch', 3)->getData());
+ }
+
+ public function testGetDisabledUsersAsSubAdmin(): void {
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->willReturn('subadmin');
+ $this->userSession
+ ->expects($this->atLeastOnce())
+ ->method('getUser')
+ ->willReturn($loggedInUser);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->willReturn(false);
+ $firstGroup = $this->getMockBuilder('OCP\IGroup')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $secondGroup = $this->getMockBuilder('OCP\IGroup')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $subAdminManager = $this->getMockBuilder('OC\SubAdmin')
+ ->disableOriginalConstructor()->getMock();
+ $subAdminManager
+ ->expects($this->once())
+ ->method('isSubAdmin')
+ ->with($loggedInUser)
+ ->willReturn(true);
+ $subAdminManager
+ ->expects($this->once())
+ ->method('getSubAdminsGroups')
+ ->with($loggedInUser)
+ ->willReturn([$firstGroup, $secondGroup]);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('getSubAdmin')
+ ->willReturn($subAdminManager);
+ $this->groupManager
+ ->expects($this->never())
+ ->method('displayNamesInGroup');
+
+ $firstGroup
+ ->expects($this->once())
+ ->method('searchUsers')
+ ->with('MyCustomSearch')
+ ->willReturn([
+ $this->createUserMock('user1', false),
+ $this->createUserMock('bob', true),
+ $this->createUserMock('user2', false),
+ $this->createUserMock('alice', true),
+ ]);
+
+ $secondGroup
+ ->expects($this->once())
+ ->method('searchUsers')
+ ->with('MyCustomSearch')
+ ->willReturn([
+ $this->createUserMock('user2', false),
+ $this->createUserMock('joe', true),
+ $this->createUserMock('user3', false),
+ $this->createUserMock('jim', true),
+ $this->createUserMock('john', true),
+ ]);
+
+
+ $expected = [
+ 'users' => [
+ 'user1' => ['id' => 'user1'],
+ 'user2' => ['id' => 'user2'],
+ 'user3' => ['id' => 'user3'],
+ ],
+ ];
+ $this->assertEquals($expected, $this->api->getDisabledUsersDetails('MyCustomSearch', 3)->getData());
+ }
+
public function testAddUserAlreadyExisting() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);