Added total count for subadmins

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-05-24 11:29:48 +02:00
parent ddd1c8bc86
commit c55cf79453
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
7 changed files with 39 additions and 14 deletions

View File

@ -188,7 +188,7 @@ class MetaData {
* @param string $search a search string
* @return \OCP\IGroup[]
*/
protected function getGroups($search = '') {
public function getGroups($search = '') {
if($this->isAdmin) {
return $this->groupManager->search($search);
} else {

View File

@ -34,6 +34,7 @@ namespace OC\User;
use OC\Hooks\PublicEmitter;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IUser;
use OCP\IGroup;
use OCP\IUserBackend;
use OCP\IUserManager;
use OCP\IConfig;
@ -384,6 +385,24 @@ class Manager extends PublicEmitter implements IUserManager {
return $userCountStatistics;
}
/**
* 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
*/
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));
}
/**
* The callback is executed for each user on each backend.
* If the callback returns false no further users will be retrieved.

View File

@ -193,21 +193,22 @@ class UsersController extends Controller {
}, 0);
} else {
// User is subadmin !
// TODO We can't have the total user count per groups, disabling it
$userCount = false;
$groupsNames = [];
// Map group list to names to retrieve the countDisabledUsersOfGroups
$userGroups = $this->groupManager->getUserGroupIds($user);
$userGroups = $this->groupManager->getUserGroups($user);
$groupsNames = [];
$userCount = 0;
foreach($groups as $key => $group) {
// $userCount += (int)$group['usercount'];
array_push($groupsNames, $group['name']);
// we prevent subadmins from looking up themselves
// so we lower the count of the groups he belongs to
if (in_array($group['id'], $userGroups)) {
if (array_key_exists($group['id'], $userGroups)) {
$groups[$key]['usercount']--;
$userCount = -1; // we also lower from one the total count
}
};
$userCount += $this->userManager->countUsersOfGroups($groupsInfo->getGroups());
$disabledUsers = $isLDAPUsed ? 0 : $this->userManager->countDisabledUsersOfGroups($groupsNames);
}
$disabledUsersGroup = [
@ -238,7 +239,7 @@ class UsersController extends Controller {
$serverData['isAdmin'] = $this->isAdmin;
$serverData['sortGroups'] = $sortGroupsBy;
$serverData['quotaPreset'] = $quotaPreset;
$serverData['userCount'] = $userCount === false ? false : $userCount - $disabledUsers;
$serverData['userCount'] = $userCount - $disabledUsers;
$serverData['languages'] = $languages;
$serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
// Settings

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -179,6 +179,10 @@ export default {
}
return disabledUsers;
}
if (!settings.isAdmin) {
// We don't want subadmins to edit themselves
return this.users.filter(user => user.enabled !== false && user.id !== oc_current_user);
}
return this.users.filter(user => user.enabled !== false);
},
groups() {

View File

@ -12,6 +12,7 @@ sync(store, router);
Vue.prototype.t = t;
Vue.prototype.OC = OC;
Vue.prototype.oc_userconfig = oc_userconfig;
Vue.prototype.oc_current_user = oc_current_user;
const app = new Vue({
router,