diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-11 17:57:00 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-16 11:10:00 +0200 |
commit | 171f86ca2e71918809930e823062d93c03833921 (patch) | |
tree | f605b2fa0d94a78c44d9781c595331f1e8a34b52 /settings | |
parent | fee62ac61c1cecb37e283fc6f9faf0251389226f (diff) | |
download | nextcloud-server-171f86ca2e71918809930e823062d93c03833921.tar.gz nextcloud-server-171f86ca2e71918809930e823062d93c03833921.zip |
Only sort by group name when LDAP is involved
Diffstat (limited to 'settings')
-rw-r--r-- | settings/controller/groupscontroller.php | 10 | ||||
-rw-r--r-- | settings/js/users/groups.js | 31 | ||||
-rw-r--r-- | settings/templates/users/part.grouplist.php | 2 | ||||
-rw-r--r-- | settings/users.php | 16 |
4 files changed, 49 insertions, 10 deletions
diff --git a/settings/controller/groupscontroller.php b/settings/controller/groupscontroller.php index c3c0ea5ff20..6cb0cd3e008 100644 --- a/settings/controller/groupscontroller.php +++ b/settings/controller/groupscontroller.php @@ -23,7 +23,8 @@ namespace OC\Settings\Controller; use OC\AppFramework\Http; -use \OCP\AppFramework\Controller; +use OC\Group\MetaData; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\IGroupManager; use OCP\IL10N; @@ -69,14 +70,15 @@ class GroupsController extends Controller { * * @param string $pattern * @param bool $filterGroups + * @param int $sortGroups * @return DataResponse */ - public function index($pattern = '', $filterGroups = false) { + public function index($pattern = '', $filterGroups = false, $sortGroups = MetaData::SORT_USERCOUNT) { $groupPattern = $filterGroups ? $pattern : ''; - $groupsInfo = new \OC\Group\MetaData($this->userSession->getUser()->getUID(), + $groupsInfo = new MetaData($this->userSession->getUser()->getUID(), $this->isAdmin, $this->groupManager); - $groupsInfo->setSorting($groupsInfo::SORT_GROUPNAME); + $groupsInfo->setSorting($sortGroups); list($adminGroups, $groups) = $groupsInfo->get($groupPattern, $pattern); return new DataResponse( diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js index d5e37ff8d63..d205e915508 100644 --- a/settings/js/users/groups.js +++ b/settings/js/users/groups.js @@ -5,7 +5,8 @@ * See the COPYING-README file. */ -var $userGroupList; +var $userGroupList, + $sortGroupBy; var GroupList; GroupList = { @@ -27,6 +28,11 @@ GroupList = { }, setUserCount: function (groupLiElement, usercount) { + if ($sortGroupBy !== 1) { + // If we don't sort by group count we dont display them either + return; + } + var $groupLiElement = $(groupLiElement); if (usercount === undefined || usercount === 0 || usercount < 0) { usercount = ''; @@ -77,6 +83,19 @@ GroupList = { return 1; } + if ($sortGroupBy === 1) { + // Sort by user count first + var $usersGroupA = $(a).data('usercount'), + $usersGroupB = $(b).data('usercount'); + if ($usersGroupA > 0 && $usersGroupA > $usersGroupB) { + return -1; + } + if ($usersGroupB > 0 && $usersGroupB > $usersGroupA) { + return 1; + } + } + + // Fallback or sort by group name return UserList.alphanum( $(a).find('a span').text(), $(b).find('a span').text() @@ -127,7 +146,8 @@ GroupList = { OC.generateUrl('/settings/users/groups'), { pattern: filter.getPattern(), - filterGroups: filter.filterGroups ? 1 : 0 + filterGroups: filter.filterGroups ? 1 : 0, + sortGroups: $sortGroupBy }, function (result) { @@ -285,8 +305,11 @@ GroupList = { $(document).ready( function () { $userGroupList = $('#usergrouplist'); GroupList.initDeleteHandling(); - // TODO: disabled due to performance issues - // GroupList.getEveryoneCount(); + $sortGroupBy = $userGroupList.data('sort-groups'); + if ($sortGroupBy === 1) { + // Disabled due to performance issues, when we don't need it for sorting + GroupList.getEveryoneCount(); + } // Display or hide of Create Group List Element $('#newgroup-form').hide(); diff --git a/settings/templates/users/part.grouplist.php b/settings/templates/users/part.grouplist.php index 5b516bc0e16..51638c7bcce 100644 --- a/settings/templates/users/part.grouplist.php +++ b/settings/templates/users/part.grouplist.php @@ -1,4 +1,4 @@ -<ul id="usergrouplist"> +<ul id="usergrouplist" data-sort-groups="<?php p($_['sortGroups']); ?>"> <!-- Add new group --> <li id="newgroup-init"> <a href="#"> diff --git a/settings/users.php b/settings/users.php index 44e2548be72..5da6902b8fa 100644 --- a/settings/users.php +++ b/settings/users.php @@ -37,12 +37,25 @@ OC_App::setActiveNavigationEntry( 'core_users' ); $userManager = \OC_User::getManager(); $groupManager = \OC_Group::getManager(); +// Set the sort option: SORT_USERCOUNT or SORT_GROUPNAME +$sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT; + +if (class_exists('\OCA\user_ldap\GROUP_LDAP')) { + $backends = $groupManager->getBackends(); + foreach ($backends as $backend) { + if ($backend instanceof \OCA\user_ldap\GROUP_LDAP) { + // LDAP user count can be slow, so we sort by gorup name here + $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME; + } + } +} + $config = \OC::$server->getConfig(); $isAdmin = OC_User::isAdminUser(OC_User::getUser()); $groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), $isAdmin, $groupManager); -$groupsInfo->setSorting($groupsInfo::SORT_GROUPNAME); +$groupsInfo->setSorting($sortGroupsBy); list($adminGroup, $groups) = $groupsInfo->get(); $recoveryAdminEnabled = OC_App::isEnabled('encryption') && @@ -75,6 +88,7 @@ $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false $tmpl = new OC_Template("settings", "users/main", "user"); $tmpl->assign('groups', $groups); +$tmpl->assign('sortGroups', $sortGroupsBy); $tmpl->assign('adminGroup', $adminGroup); $tmpl->assign('isAdmin', (int)$isAdmin); $tmpl->assign('subadmins', $subadmins); |