##// END OF EJS Templates
admin users and admin users group: add number of inactive users/users_group, resolves #5454
Bartłomiej Wołyńczyk -
r2727:15796c8e default
parent child Browse files
Show More
@@ -41,6 +41,7 b' from rhodecode.model.db import ('
41 or_, count, User, UserGroup, UserGroupMember)
41 or_, count, User, UserGroup, UserGroupMember)
42 from rhodecode.model.meta import Session
42 from rhodecode.model.meta import Session
43 from rhodecode.model.user_group import UserGroupModel
43 from rhodecode.model.user_group import UserGroupModel
44 from rhodecode.model.db import true
44
45
45 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
46
47
@@ -108,6 +109,10 b' class AdminUserGroupsView(BaseAppView, D'
108 .filter(UserGroup.users_group_id.in_(allowed_ids))\
109 .filter(UserGroup.users_group_id.in_(allowed_ids))\
109 .count()
110 .count()
110
111
112 user_groups_data_total_inactive_count = UserGroup.query()\
113 .filter(UserGroup.users_group_id.in_(allowed_ids))\
114 .filter(UserGroup.users_group_active != true()).count()
115
111 member_count = count(UserGroupMember.user_id)
116 member_count = count(UserGroupMember.user_id)
112 base_q = Session.query(
117 base_q = Session.query(
113 UserGroup.users_group_name,
118 UserGroup.users_group_name,
@@ -123,13 +128,17 b' class AdminUserGroupsView(BaseAppView, D'
123 .join(User, User.user_id == UserGroup.user_id) \
128 .join(User, User.user_id == UserGroup.user_id) \
124 .group_by(UserGroup, User)
129 .group_by(UserGroup, User)
125
130
131 base_q_inactive = base_q.filter(UserGroup.users_group_active != true())
132
126 if search_q:
133 if search_q:
127 like_expression = u'%{}%'.format(safe_unicode(search_q))
134 like_expression = u'%{}%'.format(safe_unicode(search_q))
128 base_q = base_q.filter(or_(
135 base_q = base_q.filter(or_(
129 UserGroup.users_group_name.ilike(like_expression),
136 UserGroup.users_group_name.ilike(like_expression),
130 ))
137 ))
138 base_q_inactive = base_q.filter(UserGroup.users_group_active != true())
131
139
132 user_groups_data_total_filtered_count = base_q.count()
140 user_groups_data_total_filtered_count = base_q.count()
141 user_groups_data_total_filtered_inactive_count = base_q_inactive.count()
133
142
134 if order_by == 'members_total':
143 if order_by == 'members_total':
135 sort_col = member_count
144 sort_col = member_count
@@ -171,7 +180,9 b' class AdminUserGroupsView(BaseAppView, D'
171 'draw': draw,
180 'draw': draw,
172 'data': user_groups_data,
181 'data': user_groups_data,
173 'recordsTotal': user_groups_data_total_count,
182 'recordsTotal': user_groups_data_total_count,
183 'recordsTotalInactive': user_groups_data_total_inactive_count,
174 'recordsFiltered': user_groups_data_total_filtered_count,
184 'recordsFiltered': user_groups_data_total_filtered_count,
185 'recordsFilteredInactive': user_groups_data_total_filtered_inactive_count,
175 })
186 })
176
187
177 return data
188 return data
@@ -32,6 +32,7 b' from rhodecode.apps._base import BaseApp'
32 from rhodecode.apps.ssh_support import SshKeyFileChangeEvent
32 from rhodecode.apps.ssh_support import SshKeyFileChangeEvent
33 from rhodecode.authentication.plugins import auth_rhodecode
33 from rhodecode.authentication.plugins import auth_rhodecode
34 from rhodecode.events import trigger
34 from rhodecode.events import trigger
35 from rhodecode.model.db import true
35
36
36 from rhodecode.lib import audit_logger
37 from rhodecode.lib import audit_logger
37 from rhodecode.lib.exceptions import (
38 from rhodecode.lib.exceptions import (
@@ -89,7 +90,6 b' class AdminUsersView(BaseAppView, DataGr'
89 draw, start, limit = self._extract_chunk(self.request)
90 draw, start, limit = self._extract_chunk(self.request)
90 search_q, order_by, order_dir = self._extract_ordering(
91 search_q, order_by, order_dir = self._extract_ordering(
91 self.request, column_map=column_map)
92 self.request, column_map=column_map)
92
93 _render = self.request.get_partial_renderer(
93 _render = self.request.get_partial_renderer(
94 'rhodecode:templates/data_table/_dt_elements.mako')
94 'rhodecode:templates/data_table/_dt_elements.mako')
95
95
@@ -100,8 +100,14 b' class AdminUsersView(BaseAppView, DataGr'
100 .filter(User.username != User.DEFAULT_USER) \
100 .filter(User.username != User.DEFAULT_USER) \
101 .count()
101 .count()
102
102
103 users_data_total_inactive_count = User.query()\
104 .filter(User.username != User.DEFAULT_USER) \
105 .filter(User.active != true())\
106 .count()
107
103 # json generate
108 # json generate
104 base_q = User.query().filter(User.username != User.DEFAULT_USER)
109 base_q = User.query().filter(User.username != User.DEFAULT_USER)
110 base_inactive_q = base_q.filter(User.active != true())
105
111
106 if search_q:
112 if search_q:
107 like_expression = u'%{}%'.format(safe_unicode(search_q))
113 like_expression = u'%{}%'.format(safe_unicode(search_q))
@@ -111,8 +117,10 b' class AdminUsersView(BaseAppView, DataGr'
111 User.name.ilike(like_expression),
117 User.name.ilike(like_expression),
112 User.lastname.ilike(like_expression),
118 User.lastname.ilike(like_expression),
113 ))
119 ))
120 base_inactive_q = base_q.filter(User.active != true())
114
121
115 users_data_total_filtered_count = base_q.count()
122 users_data_total_filtered_count = base_q.count()
123 users_data_total_filtered_inactive_count = base_inactive_q.count()
116
124
117 sort_col = getattr(User, order_by, None)
125 sort_col = getattr(User, order_by, None)
118 if sort_col:
126 if sort_col:
@@ -148,12 +156,13 b' class AdminUsersView(BaseAppView, DataGr'
148 "extern_name": user.extern_name,
156 "extern_name": user.extern_name,
149 "action": user_actions(user.user_id, user.username),
157 "action": user_actions(user.user_id, user.username),
150 })
158 })
151
152 data = ({
159 data = ({
153 'draw': draw,
160 'draw': draw,
154 'data': users_data,
161 'data': users_data,
155 'recordsTotal': users_data_total_count,
162 'recordsTotal': users_data_total_count,
156 'recordsFiltered': users_data_total_filtered_count,
163 'recordsFiltered': users_data_total_filtered_count,
164 'recordsTotalInactive': users_data_total_inactive_count,
165 'recordsFilteredInactive': users_data_total_filtered_inactive_count
157 })
166 })
158
167
159 return data
168 return data
@@ -10,7 +10,7 b''
10
10
11 <%def name="breadcrumbs_links()">
11 <%def name="breadcrumbs_links()">
12 <input class="q_filter_box" id="q_filter" size="15" type="text" name="filter" placeholder="${_('quick filter...')}" value=""/>
12 <input class="q_filter_box" id="q_filter" size="15" type="text" name="filter" placeholder="${_('quick filter...')}" value=""/>
13 ${h.link_to(_('Admin'),h.route_path('admin_home'))} &raquo; <span id="user_group_count">0</span> ${_('user groups')}
13 ${h.link_to(_('Admin'),h.route_path('admin_home'))} &raquo; <span id="user_group_count">0</span>
14 </%def>
14 </%def>
15
15
16 <%def name="menu_bar_nav()">
16 <%def name="menu_bar_nav()">
@@ -38,21 +38,33 b''
38 </div>
38 </div>
39 <script>
39 <script>
40 $(document).ready(function() {
40 $(document).ready(function() {
41 var getDatatableCount = function(){
41 var $userGroupsListTable = $('#user_group_list_table');
42 var table = $('#user_group_list_table').dataTable();
43 var page = table.api().page.info();
44 var active = page.recordsDisplay;
45 var total = page.recordsTotal;
46
47 var _text = _gettext("{0} out of {1} users").format(active, total);
48 $('#user_group_count').text(_text);
49 };
50
42
51 // user list
43 // user list
52 $('#user_group_list_table').DataTable({
44 $userGroupsListTable.DataTable({
53 processing: true,
45 processing: true,
54 serverSide: true,
46 serverSide: true,
55 ajax: "${h.route_path('user_groups_data')}",
47 ajax: {
48 "url": "${h.route_path('user_groups_data')}",
49 "dataSrc": function (json) {
50 var filteredCount = json.recordsFiltered;
51 var filteredInactiveCount = json.recordsFilteredInactive;
52 var totalInactive = json.recordsTotalInactive;
53 var total = json.recordsTotal;
54
55 var _text = _gettext(
56 "{0} ({1} inactive) of {2} user groups ({3} inactive)").format(
57 filteredCount, filteredInactiveCount, total, totalInactive);
58
59 if (total === filteredCount) {
60 _text = _gettext(
61 "{0} user groups ({1} inactive)").format(total, totalInactive);
62 }
63 $('#user_group_count').text(_text);
64 return json.data;
65 },
66 },
67
56 dom: 'rtp',
68 dom: 'rtp',
57 pageLength: ${c.visual.admin_grid_items},
69 pageLength: ${c.visual.admin_grid_items},
58 order: [[ 0, "asc" ]],
70 order: [[ 0, "asc" ]],
@@ -79,17 +91,12 b''
79 }
91 }
80 });
92 });
81
93
82 $('#user_group_list_table').on('xhr.dt', function(e, settings, json, xhr){
94 $userGroupsListTable.on('xhr.dt', function(e, settings, json, xhr){
83 $('#user_group_list_table').css('opacity', 1);
95 $userGroupsListTable.css('opacity', 1);
84 });
96 });
85
97
86 $('#user_group_list_table').on('preXhr.dt', function(e, settings, data){
98 $userGroupsListTable.on('preXhr.dt', function(e, settings, data){
87 $('#user_group_list_table').css('opacity', 0.3);
99 $userGroupsListTable.css('opacity', 0.3);
88 });
89
90 // refresh counters on draw
91 $('#user_group_list_table').on('draw.dt', function(){
92 getDatatableCount();
93 });
100 });
94
101
95 // filter
102 // filter
@@ -39,22 +39,30 b''
39
39
40 $(document).ready(function() {
40 $(document).ready(function() {
41 var $userListTable = $('#user_list_table');
41 var $userListTable = $('#user_list_table');
42
43 var getDatatableCount = function(){
44 var table = $userListTable.dataTable();
45 var page = table.api().page.info();
46 var active = page.recordsDisplay;
47 var total = page.recordsTotal;
48
49 var _text = _gettext("{0} out of {1} users").format(active, total);
50 $('#user_count').text(_text);
51 };
52
53 // user list
42 // user list
54 $userListTable.DataTable({
43 $userListTable.DataTable({
55 processing: true,
44 processing: true,
56 serverSide: true,
45 serverSide: true,
57 ajax: "${h.route_path('users_data')}",
46 ajax: {
47 "url": "${h.route_path('users_data')}",
48 "dataSrc": function ( json ) {
49 var filteredCount = json.recordsFiltered;
50 var filteredInactiveCount = json.recordsFilteredInactive;
51 var totalInactive = json.recordsTotalInactive;
52 var total = json.recordsTotal;
53
54 var _text = _gettext(
55 "{0} ({1} inactive) of {2} users ({3} inactive)").format(
56 filteredCount, filteredInactiveCount, total, totalInactive);
57
58 if(total === filteredCount){
59 _text = _gettext(
60 "{0} users ({1} inactive)").format(total, totalInactive);
61 }
62 $('#user_count').text(_text);
63 return json.data;
64 }
65 },
58 dom: 'rtp',
66 dom: 'rtp',
59 pageLength: ${c.visual.admin_grid_items},
67 pageLength: ${c.visual.admin_grid_items},
60 order: [[ 0, "asc" ]],
68 order: [[ 0, "asc" ]],
@@ -100,11 +108,6 b''
100 $userListTable.css('opacity', 0.3);
108 $userListTable.css('opacity', 0.3);
101 });
109 });
102
110
103 // refresh counters on draw
104 $userListTable.on('draw.dt', function(){
105 getDatatableCount();
106 });
107
108 // filter
111 // filter
109 $('#q_filter').on('keyup',
112 $('#q_filter').on('keyup',
110 $.debounce(250, function() {
113 $.debounce(250, function() {
General Comments 0
You need to be logged in to leave comments. Login now