diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-04-15 00:13:23 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-06-02 12:53:55 +0200 |
commit | 249e42c4cdf81c2d1c294a5535c055cdfee992b4 (patch) | |
tree | 07d884e082eb686aa93de67693a3296a4c8c08d8 /settings | |
parent | dbc854d8b8cb0a187859fae174a41de5b296595c (diff) | |
download | nextcloud-server-249e42c4cdf81c2d1c294a5535c055cdfee992b4.tar.gz nextcloud-server-249e42c4cdf81c2d1c294a5535c055cdfee992b4.zip |
enable group filtering
Diffstat (limited to 'settings')
-rw-r--r-- | settings/ajax/grouplist.php | 75 | ||||
-rw-r--r-- | settings/js/users/filter.js | 7 | ||||
-rw-r--r-- | settings/js/users/groups.js | 49 | ||||
-rw-r--r-- | settings/js/users/users.js | 5 | ||||
-rw-r--r-- | settings/routes.php | 2 | ||||
-rw-r--r-- | settings/templates/users/part.grouplist.php | 9 | ||||
-rw-r--r-- | settings/users.php | 11 |
7 files changed, 143 insertions, 15 deletions
diff --git a/settings/ajax/grouplist.php b/settings/ajax/grouplist.php new file mode 100644 index 00000000000..1041d7374e7 --- /dev/null +++ b/settings/ajax/grouplist.php @@ -0,0 +1,75 @@ +<?php +/** + * ownCloud + * + * @author Arthur Schiwon + * @copyright 2014 Arthur Schiwon <blizzz@owncloud.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +OC_JSON::callCheck(); +OC_JSON::checkSubAdminUser(); +if (isset($_GET['pattern']) && !empty($_GET['pattern'])) { + $pattern = $_GET['pattern']; +} else { + $pattern = ''; +} +$groups = array(); +$adminGroups = array(); +$groupManager = \OC_Group::getManager(); + +$accessiblegroups = $groupManager->search($pattern); +if (!OC_User::isAdminUser(OC_User::getUser())) { + $subadminGroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); + $accessiblegroups = array_intersect($accessiblegroups, $subadminGroups); +} + +$sortGroupsIndex = 0; +$sortGroupsKeys = array(); +$sortAdminGroupsIndex = 0; +$sortAdminGroupsKeys = array(); + +foreach($accessiblegroups as $group) { + $gid = $group->getGID(); + $usersInGroup = OC_Group::usersInGroup($gid, ''); + if (!OC_User::isAdminUser($gid)) { + $groups[] = array( + 'id' => str_replace(' ','', $gid ), + 'name' => $gid, + 'usercount' => count($usersInGroup), + ); + $sortGroupsKeys[$sortGroupsIndex] = count($usersInGroup); + $sortGroupsIndex++; + } else { + $adminGroup[] = array( + 'id' => str_replace(' ','', $gid ), + 'name' => $gid, + 'usercount' => count($usersInGroup) + ); + $sortAdminGroupsKeys[$sortAdminGroupsIndex] = count($usersInGroup); + $sortAdminGroupsIndex++; + } +} + +if(!empty($groups)) { + array_multisort($sortGroupsKeys, SORT_DESC, $groups); +} +if(!empty($adminGroup)) { + array_multisort($sortAdminGroupsKeys, SORT_DESC, $adminGroup); +} + +OC_JSON::success( + array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups))); diff --git a/settings/js/users/filter.js b/settings/js/users/filter.js index 2c0eefe25d4..89c2f46dacf 100644 --- a/settings/js/users/filter.js +++ b/settings/js/users/filter.js @@ -10,9 +10,10 @@ * @param jQuery input element that works as the user text input field * @param object the UserList object */ -function UserManagementFilter(filterInput, userList) { +function UserManagementFilter(filterInput, userList, groupList) { this.filterInput = filterInput; this.userList = userList; + this.groupList = groupList; this.thread = undefined; this.oldval = this.filterInput.val(); @@ -25,8 +26,6 @@ function UserManagementFilter(filterInput, userList) { UserManagementFilter.prototype.init = function() { umf = this; this.filterInput.keyup(function(e) { - console.log(e.keyCode); - //we want to react on any printable letter, plus on modyfing stuff like //Backspace and Delete. extended https://stackoverflow.com/a/12467610 var valid = @@ -61,6 +60,8 @@ UserManagementFilter.prototype.init = function() { UserManagementFilter.prototype.run = function() { this.userList.empty(); this.userList.update(); + this.groupList.empty(); + this.groupList.update(); } /** diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js index 0180cb64898..1088467ca11 100644 --- a/settings/js/users/groups.js +++ b/settings/js/users/groups.js @@ -6,17 +6,22 @@ */ var GroupList = { - addGroup: function(gid) { + addGroup: function(gid, usercount) { + if(usercount === undefined || usercount === 0) { + usercount = ''; + } var li = $('li[data-gid]').last().clone(); var ul = $('li[data-gid]').first().parent(); li.attr('data-gid', gid); - li.attr('data-usercount', 0); + li.attr('data-usercount', usercount); li.find('a span').first().text(gid); - li.find('span[class=usercount]').first().text(''); + li.find('span[class=usercount]').first().text(usercount); $(li).appendTo(ul); GroupList.sortGroups(0); + + return li; }, sortGroups: function(usercount) { @@ -75,6 +80,41 @@ ) }, + update: function() { + if (GroupList.updating) { + return; + } + GroupList.updating = true; + pattern = filter.getPattern(); + var query = $.param({ pattern: pattern }); + $.get(OC.generateUrl('/settings/ajax/grouplist') + '?' + query, function (result) { + var lis = []; + if (result.status === 'success') { + $.each(result.data, function (i, subset) { + $.each(subset, function (index, group) { + if($('li[data-gid="' + group.name + '"]').length > 0) { + return true; + } + var li = GroupList.addGroup(group.name, group.usercount); + li.addClass('appear transparent'); + lis.push(li); + }); + }); + if (result.data.length > 0) { + GroupList.doSort(); + } else { + GroupList.noMoreEntries = true; + } + setTimeout(function() { + for (var i = 0; i < lis.length; i++) { + lis[i].removeClass('transparent'); + } + }, 0); + } + GroupList.updating = false; + }); + }, + elementBelongsToAddGroup: function(el) { return !(el !== $('#newgroup-form').get(0) && $('#newgroup-form').find($(el)).length === 0); @@ -134,6 +174,9 @@ remove: function(gid) { $('li').filterAttr('data-gid', gid).remove(); }, + empty: function() { + $('li:not([data-gid=""])').remove(); + }, initDeleteHandling: function() { //set up handler GroupDeleteHandler = new DeleteHandler('removegroup.php', 'groupname', diff --git a/settings/js/users/users.js b/settings/js/users/users.js index 481cf1586ce..e9c85d20e95 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -403,8 +403,6 @@ $(document).ready(function () { UserList.applyMultiplySelect($(element)); }); - - $('table').on('click', 'td.password>img', function (event) { event.stopPropagation(); var img = $(this); @@ -549,5 +547,6 @@ $(document).ready(function () { ); }); // Implements User Search - filter = new UserManagementFilter($('#usersearchform input'), UserList); + filter = new UserManagementFilter( + $('#usersearchform input'), UserList, GroupList); }); diff --git a/settings/routes.php b/settings/routes.php index 1352fac8383..9acfc2852bd 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -25,6 +25,8 @@ $this->create('settings_admin', '/settings/admin') // users $this->create('settings_ajax_userlist', '/settings/ajax/userlist') ->actionInclude('settings/ajax/userlist.php'); +$this->create('settings_ajax_grouplist', '/settings/ajax/grouplist') + ->actionInclude('settings/ajax/grouplist.php'); $this->create('settings_ajax_createuser', '/settings/ajax/createuser.php') ->actionInclude('settings/ajax/createuser.php'); $this->create('settings_ajax_removeuser', '/settings/ajax/removeuser.php') diff --git a/settings/templates/users/part.grouplist.php b/settings/templates/users/part.grouplist.php index 4b1958c1a67..0d5fef7775c 100644 --- a/settings/templates/users/part.grouplist.php +++ b/settings/templates/users/part.grouplist.php @@ -18,6 +18,9 @@ <?php p($l->t('Everyone')); ?> </span> </a> + <span class="utils"> + <span class="usercount"></span> + </span> </li> <!-- The Admin Group --> @@ -25,21 +28,21 @@ <li data-gid="admin"> <a href="#"><?php p($l->t('Admins')); ?></a> <span class="utils"> - <span class="usercount"><?php if(count($adminGroup['useringroup']) > 0) { p(count($adminGroup['useringroup'])); } ?></span> + <span class="usercount"><?php if($adminGroup['useringroup'] > 0) { p($adminGroup['useringroup']); } ?></span> </span> </li> <?php endforeach; ?> <!--List of Groups--> <?php foreach($_["groups"] as $group): ?> - <li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p(count($group['useringroup'])) ?>"> + <li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['useringroup']) ?>"> <a href="#"> <span><?php p($group['name']); ?></span> <img class="svg action rename" src="<?php p(image_path('core', 'actions/rename.svg'))?>" original-title="<?php p($l->t('Edit'))?>" alt="<?php p($l->t("change group name"))?>" title="<?php p($l->t("change group name"))?>" /> </a> <span class="utils"> - <span class="usercount"><?php if(count($group['useringroup']) > 0) { p(count($group['useringroup'])); } ?></span> + <span class="usercount"><?php if($group['useringroup'] > 0) { p($group['useringroup']); } ?></span> <a href="#" class="action delete" original-title="<?php p($l->t('Delete'))?>"> <img src="<?php print_unescaped(image_path('core', 'actions/delete.svg')) ?>" class="svg" /> </a> diff --git a/settings/users.php b/settings/users.php index d6e270bbc32..d3fcbb26a36 100644 --- a/settings/users.php +++ b/settings/users.php @@ -22,6 +22,7 @@ $users = array(); $groups = array(); $adminGroup = array(); $userManager = \OC_User::getManager(); +$groupManager = \OC_Group::getManager(); if (isset($_GET['offset'])) { $offset = $_GET['offset']; @@ -89,14 +90,18 @@ $sortGroupsKeys = array(); $sortAdminGroupsIndex = 0; $sortAdminGroupsKeys = array(); foreach( $accessiblegroups as $gid ) { - $usersInGroup = OC_Group::usersInGroup($gid, '', $limit, $offset); + $group = $groupManager->get($gid); + if(!$group) { + continue; + } + $usersInGroup = $group->count(); if (!OC_User::isAdminUser($gid)) { $groups[] = array( 'id' => str_replace(' ','', $gid ), 'name' => $gid, 'useringroup' => $usersInGroup, ); - $sortGroupsKeys[$sortGroupsIndex] = count($usersInGroup); + $sortGroupsKeys[$sortGroupsIndex] = $usersInGroup; $sortGroupsIndex++; } else { $adminGroup[] = array( @@ -104,7 +109,7 @@ foreach( $accessiblegroups as $gid ) { 'name' => $gid, 'useringroup' => $usersInGroup ); - $sortAdminGroupsKeys[$sortAdminGroupsIndex] = count($usersInGroup); + $sortAdminGroupsKeys[$sortAdminGroupsIndex] = $usersInGroup; $sortAdminGroupsIndex++; } } |