]> source.dussan.org Git - nextcloud-server.git/commitdiff
enable group filtering
authorArthur Schiwon <blizzz@owncloud.com>
Mon, 14 Apr 2014 22:13:23 +0000 (00:13 +0200)
committerArthur Schiwon <blizzz@owncloud.com>
Mon, 2 Jun 2014 10:53:55 +0000 (12:53 +0200)
settings/ajax/grouplist.php [new file with mode: 0644]
settings/js/users/filter.js
settings/js/users/groups.js
settings/js/users/users.js
settings/routes.php
settings/templates/users/part.grouplist.php
settings/users.php

diff --git a/settings/ajax/grouplist.php b/settings/ajax/grouplist.php
new file mode 100644 (file)
index 0000000..1041d73
--- /dev/null
@@ -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)));
index 2c0eefe25d4590aa6b293bd3ff525f948342d6f8..89c2f46dacf235f08b1807b83b6ac3ea4ccd993c 100644 (file)
  * @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();
 }
 
 /**
index 0180cb6489877cbd1d4bf281d8b42919bada40cb..1088467ca11a29a2dd3d949e0dbc54b307fc08b0 100644 (file)
@@ -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) {
                )
        },
 
+       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);
        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',
index 481cf1586ce94c782bee1863bef9141b5bf7df80..e9c85d20e9536b4a9fe5178c2078e7e84427c428 100644 (file)
@@ -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);
 });
index 1352fac83836ab657baee7b15dd8b978ba272a96..9acfc2852bdbbe4d7d3ee2bafd27287cb398b95e 100644 (file)
@@ -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')
index 4b1958c1a672e613899b4ec72975b050fa0dc525..0d5fef7775c85a87ef782c44a4aa4c5a3ba2efda 100644 (file)
@@ -18,6 +18,9 @@
                                <?php p($l->t('Everyone')); ?>
                        </span>
                </a>
+               <span class="utils">
+                       <span class="usercount"></span>
+               </span>
        </li>
 
        <!-- The Admin Group -->
                <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>
index d6e270bbc3246b2e871547c75b09133b7d9c0b74..d3fcbb26a36c73c2b26418ed9cf9e480f5dc18bc 100644 (file)
@@ -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++;
        }
 }