From 0b449f302bbec93beaf85f2786c73c1b84710c6c Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 27 Feb 2025 16:21:30 +0100 Subject: fix: Correctly count disabled users for SAML groups subadmins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If too many users return -1 as for LDAP so that link is shown Signed-off-by: Côme Chilliet --- lib/private/User/Manager.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'lib') 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 = []; @@ -538,6 +537,30 @@ class Manager extends PublicEmitter implements IUserManager { return count(array_unique($users)); } + /** + * 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. -- cgit v1.2.3 From 30382a5d8d14569cd217f19e92471da1925ea9de Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 27 Feb 2025 16:23:01 +0100 Subject: chore: Remove now unused methods from User manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/User/Manager.php | 47 -------------------------------------------- 1 file changed, 47 deletions(-) (limited to 'lib') diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 85e0adf15d8..62a7b39be16 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -520,23 +520,6 @@ class Manager extends PublicEmitter implements IUserManager { return $userCount; } - /** - * 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 int - */ - public function countUsersOfGroups(array $groups) { - $users = []; - foreach ($groups as $group) { - $usersIds = array_map(function ($user) { - return $user->getUID(); - }, $group->getUsers()); - $users = array_merge($users, $usersIds); - } - return count(array_unique($users)); - } - /** * returns how many users per backend exist in the requested groups (if supported by backend) * @@ -624,36 +607,6 @@ class Manager extends PublicEmitter implements IUserManager { return $count; } - /** - * returns how many users are disabled in the requested groups - * - * @param array $groups groupids to search - * @return int - * @since 14.0.0 - */ - public function countDisabledUsersOfGroups(array $groups): int { - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); - $queryBuilder->select($queryBuilder->createFunction('COUNT(DISTINCT ' . $queryBuilder->getColumnName('uid') . ')')) - ->from('preferences', 'p') - ->innerJoin('p', 'group_user', 'g', $queryBuilder->expr()->eq('p.userid', 'g.uid')) - ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) - ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) - ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)) - ->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY))); - - $result = $queryBuilder->execute(); - $count = $result->fetchOne(); - $result->closeCursor(); - - if ($count !== false) { - $count = (int)$count; - } else { - $count = 0; - } - - return $count; - } - /** * returns how many users have logged in once * -- cgit v1.2.3