diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-02-27 16:21:30 +0100 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2025-03-10 11:30:18 +0100 |
commit | 0b449f302bbec93beaf85f2786c73c1b84710c6c (patch) | |
tree | a803fabb6dd6008da51b47de892b5798098e0a95 /lib | |
parent | 78b31ca00f31cea436c6ae00e7161deb95840a31 (diff) | |
download | nextcloud-server-0b449f302bbec93beaf85f2786c73c1b84710c6c.tar.gz nextcloud-server-0b449f302bbec93beaf85f2786c73c1b84710c6c.zip |
fix: Correctly count disabled users for SAML groups subadmins
If too many users return -1 as for LDAP so that link is shown
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/User/Manager.php | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index aa2acb55782..85e0adf15d8 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -524,8 +524,7 @@ class Manager extends PublicEmitter implements IUserManager { * returns how many users per backend exist in the requested groups (if supported by backend) * * @param IGroup[] $groups an array of gid to search in - * @return array|int an array of backend class as key and count number as value - * if $hasLoggedIn is true only an int is returned + * @return int */ public function countUsersOfGroups(array $groups) { $users = []; @@ -539,6 +538,30 @@ class Manager extends PublicEmitter implements IUserManager { } /** + * returns how many users per backend exist in the requested groups (if supported by backend) + * + * @param IGroup[] $groups an array of groups to search in + * @param int $limit limit to stop counting + * @return array{int,int} total number of users, and number of disabled users in the given groups, below $limit. If limit is reached, -1 is returned for number of disabled users + */ + public function countUsersAndDisabledUsersOfGroups(array $groups, int $limit): array { + $users = []; + $disabled = []; + foreach ($groups as $group) { + foreach ($group->getUsers() as $user) { + $users[$user->getUID()] = 1; + if (!$user->isEnabled()) { + $disabled[$user->getUID()] = 1; + } + if (count($users) >= $limit) { + return [count($users),-1]; + } + } + } + return [count($users),count($disabled)]; + } + + /** * The callback is executed for each user on each backend. * If the callback returns false no further users will be retrieved. * |