Added total count for subadmins
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
ddd1c8bc86
commit
c55cf79453
|
@ -188,7 +188,7 @@ class MetaData {
|
||||||
* @param string $search a search string
|
* @param string $search a search string
|
||||||
* @return \OCP\IGroup[]
|
* @return \OCP\IGroup[]
|
||||||
*/
|
*/
|
||||||
protected function getGroups($search = '') {
|
public function getGroups($search = '') {
|
||||||
if($this->isAdmin) {
|
if($this->isAdmin) {
|
||||||
return $this->groupManager->search($search);
|
return $this->groupManager->search($search);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace OC\User;
|
||||||
use OC\Hooks\PublicEmitter;
|
use OC\Hooks\PublicEmitter;
|
||||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
|
use OCP\IGroup;
|
||||||
use OCP\IUserBackend;
|
use OCP\IUserBackend;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
@ -384,6 +385,24 @@ class Manager extends PublicEmitter implements IUserManager {
|
||||||
return $userCountStatistics;
|
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.
|
* The callback is executed for each user on each backend.
|
||||||
* If the callback returns false no further users will be retrieved.
|
* If the callback returns false no further users will be retrieved.
|
||||||
|
|
|
@ -193,21 +193,22 @@ class UsersController extends Controller {
|
||||||
}, 0);
|
}, 0);
|
||||||
} else {
|
} else {
|
||||||
// User is subadmin !
|
// 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
|
// 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) {
|
foreach($groups as $key => $group) {
|
||||||
// $userCount += (int)$group['usercount'];
|
// $userCount += (int)$group['usercount'];
|
||||||
array_push($groupsNames, $group['name']);
|
array_push($groupsNames, $group['name']);
|
||||||
// we prevent subadmins from looking up themselves
|
// we prevent subadmins from looking up themselves
|
||||||
// so we lower the count of the groups he belongs to
|
// 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']--;
|
$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);
|
$disabledUsers = $isLDAPUsed ? 0 : $this->userManager->countDisabledUsersOfGroups($groupsNames);
|
||||||
}
|
}
|
||||||
$disabledUsersGroup = [
|
$disabledUsersGroup = [
|
||||||
|
@ -238,7 +239,7 @@ class UsersController extends Controller {
|
||||||
$serverData['isAdmin'] = $this->isAdmin;
|
$serverData['isAdmin'] = $this->isAdmin;
|
||||||
$serverData['sortGroups'] = $sortGroupsBy;
|
$serverData['sortGroups'] = $sortGroupsBy;
|
||||||
$serverData['quotaPreset'] = $quotaPreset;
|
$serverData['quotaPreset'] = $quotaPreset;
|
||||||
$serverData['userCount'] = $userCount === false ? false : $userCount - $disabledUsers;
|
$serverData['userCount'] = $userCount - $disabledUsers;
|
||||||
$serverData['languages'] = $languages;
|
$serverData['languages'] = $languages;
|
||||||
$serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
|
$serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
|
||||||
// Settings
|
// Settings
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -179,6 +179,10 @@ export default {
|
||||||
}
|
}
|
||||||
return disabledUsers;
|
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);
|
return this.users.filter(user => user.enabled !== false);
|
||||||
},
|
},
|
||||||
groups() {
|
groups() {
|
||||||
|
|
|
@ -12,6 +12,7 @@ sync(store, router);
|
||||||
Vue.prototype.t = t;
|
Vue.prototype.t = t;
|
||||||
Vue.prototype.OC = OC;
|
Vue.prototype.OC = OC;
|
||||||
Vue.prototype.oc_userconfig = oc_userconfig;
|
Vue.prototype.oc_userconfig = oc_userconfig;
|
||||||
|
Vue.prototype.oc_current_user = oc_current_user;
|
||||||
|
|
||||||
const app = new Vue({
|
const app = new Vue({
|
||||||
router,
|
router,
|
||||||
|
|
Loading…
Reference in New Issue