From d43a2e5eb3d650ccb42448e22fba7ce8e9c80430 Mon Sep 17 00:00:00 2001 From: lian Date: Thu, 19 Jan 2017 17:24:00 +0800 Subject: [PATCH] admin search group by name --- media/css/seahub.css | 3 + seahub/api2/endpoints/admin/groups.py | 15 ++- seahub/templates/js/sysadmin-templates.html | 31 +++++ seahub/urls.py | 1 + .../sysadmin-app/collection/search-groups.js | 24 ++++ static/scripts/sysadmin-app/router.js | 18 ++- .../sysadmin-app/views/search-groups.js | 119 ++++++++++++++++++ static/scripts/sysadmin-app/views/side-nav.js | 19 ++- tests/api/endpoints/admin/test_groups.py | 11 ++ 9 files changed, 236 insertions(+), 5 deletions(-) create mode 100644 static/scripts/sysadmin-app/collection/search-groups.js create mode 100644 static/scripts/sysadmin-app/views/search-groups.js diff --git a/media/css/seahub.css b/media/css/seahub.css index 8fc0f8d9c8..f7c9cd5dfd 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -2881,6 +2881,7 @@ button.sf-dropdown-toggle:focus { } #search-form, #search-user-form, +#search-group-form, #search-repo-form { padding:7px 5px; background:#f7f7f8; @@ -2982,10 +2983,12 @@ button.sf-dropdown-toggle:focus { margin:10px 15px 20px 0; } #search-repo-form label, +#search-group-form label, #search-user-form label { width:3.5em; } #search-repo-form .submit, +#search-group-form .submit, #search-user-form .submit { margin-left:3.5em; } diff --git a/seahub/api2/endpoints/admin/groups.py b/seahub/api2/endpoints/admin/groups.py index fd4d7cd143..2e7a2c66f7 100644 --- a/seahub/api2/endpoints/admin/groups.py +++ b/seahub/api2/endpoints/admin/groups.py @@ -42,12 +42,25 @@ class AdminGroups(APIView): permission_classes = (IsAdminUser,) def get(self, request): - """ List all groups + """ List all groups / search group by name Permission checking: 1. Admin user; """ + # search groups by name + group_name = request.GET.get('name', '') + group_name = group_name.strip() + return_results = [] + if group_name: + # search by name(keyword in name) + groups_all = ccnet_api.search_groups(group_name, -1, -1) + for group in groups_all: + group_info = get_group_info(group.id) + return_results.append(group_info) + + return Response({"name": group_name, "groups": return_results}) + try: current_page = int(request.GET.get('page', '1')) per_page = int(request.GET.get('per_page', '100')) diff --git a/seahub/templates/js/sysadmin-templates.html b/seahub/templates/js/sysadmin-templates.html index b439566af2..3cbac5d3aa 100644 --- a/seahub/templates/js/sysadmin-templates.html +++ b/seahub/templates/js/sysadmin-templates.html @@ -79,6 +79,11 @@ <% } %> <% } %> + <% if (cur_tab == 'groups') { %> +
+ +
+ <% } %> + +