Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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>
  • Loading branch information
come-nc committed Mar 31, 2025
commit d3bc8b771c78ca881c127b6f614eb3fc9c4107ef
16 changes: 4 additions & 12 deletions apps/settings/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,12 @@ public function usersList(): TemplateResponse {
}, 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 = [
Expand Down
27 changes: 25 additions & 2 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,7 @@ public function countUsers() {
* 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 = [];
Expand All @@ -506,6 +505,30 @@ public function countUsersOfGroups(array $groups) {
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.
Expand Down