mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #51376 from nextcloud/backport/51108/stable31
[stable31] Fix disabled user list for SAML group subadmin
This commit is contained in:
commit
911830df8a
2 changed files with 21 additions and 51 deletions
|
|
@ -53,6 +53,8 @@ use function in_array;
|
|||
|
||||
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
||||
class UsersController extends Controller {
|
||||
/** Limit for counting users for subadmins, to avoid spending too much time */
|
||||
private const COUNT_LIMIT_FOR_SUBADMINS = 999;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
|
|
@ -150,20 +152,12 @@ class UsersController extends Controller {
|
|||
}, 0);
|
||||
} else {
|
||||
// User is subadmin !
|
||||
// Map group list to ids to retrieve the countDisabledUsersOfGroups
|
||||
$userGroups = $this->groupManager->getUserGroups($user);
|
||||
$groupsIds = [];
|
||||
|
||||
foreach ($groups as $key => $group) {
|
||||
// $userCount += (int)$group['usercount'];
|
||||
$groupsIds[] = $group['id'];
|
||||
}
|
||||
|
||||
$userCount += $this->userManager->countUsersOfGroups($groupsInfo->getGroups());
|
||||
$disabledUsers = $this->userManager->countDisabledUsersOfGroups($groupsIds);
|
||||
[$userCount,$disabledUsers] = $this->userManager->countUsersAndDisabledUsersOfGroups($groupsInfo->getGroups(), self::COUNT_LIMIT_FOR_SUBADMINS);
|
||||
}
|
||||
|
||||
$userCount -= $disabledUsers;
|
||||
if ($disabledUsers > 0) {
|
||||
$userCount -= $disabledUsers;
|
||||
}
|
||||
}
|
||||
|
||||
$recentUsersGroup = [
|
||||
|
|
|
|||
|
|
@ -523,19 +523,25 @@ 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
|
||||
* @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 countUsersOfGroups(array $groups) {
|
||||
public function countUsersAndDisabledUsersOfGroups(array $groups, int $limit): array {
|
||||
$users = [];
|
||||
$disabled = [];
|
||||
foreach ($groups as $group) {
|
||||
$usersIds = array_map(function ($user) {
|
||||
return $user->getUID();
|
||||
}, $group->getUsers());
|
||||
$users = array_merge($users, $usersIds);
|
||||
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(array_unique($users));
|
||||
return [count($users),count($disabled)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -601,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
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue