mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
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>
This commit is contained in:
parent
dde95a7718
commit
d3bc8b771c
2 changed files with 29 additions and 14 deletions
|
|
@ -148,20 +148,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(), 999);
|
||||
}
|
||||
|
||||
$userCount -= $disabledUsers;
|
||||
if ($disabledUsers > 0) {
|
||||
$userCount -= $disabledUsers;
|
||||
}
|
||||
}
|
||||
|
||||
$recentUsersGroup = [
|
||||
|
|
|
|||
|
|
@ -492,8 +492,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 = [];
|
||||
|
|
@ -506,6 +505,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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue