##// END OF EJS Templates
admin: in usergroups admin allow prefiltering the list of users...
dan -
r93:07ae5171 default
parent child Browse files
Show More
@@ -36,6 +36,7 b' from rhodecode.lib import auth'
36 from rhodecode.lib import helpers as h
36 from rhodecode.lib import helpers as h
37 from rhodecode.lib.exceptions import UserGroupAssignedException,\
37 from rhodecode.lib.exceptions import UserGroupAssignedException,\
38 RepoGroupAssignmentError
38 RepoGroupAssignmentError
39 from rhodecode.lib.utils import jsonify, action_logger
39 from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int
40 from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int
40 from rhodecode.lib.auth import (
41 from rhodecode.lib.auth import (
41 LoginRequired, NotAnonymous, HasUserGroupPermissionAnyDecorator,
42 LoginRequired, NotAnonymous, HasUserGroupPermissionAnyDecorator,
@@ -181,7 +182,8 b' class UserGroupsController(BaseControlle'
181 h.flash(_('Error occurred during creation of user group %s') \
182 h.flash(_('Error occurred during creation of user group %s') \
182 % request.POST.get('users_group_name'), category='error')
183 % request.POST.get('users_group_name'), category='error')
183
184
184 return redirect(url('users_groups'))
185 return redirect(
186 url('edit_users_group', user_group_id=user_group.users_group_id))
185
187
186 @HasPermissionAnyDecorator('hg.admin', 'hg.usergroup.create.true')
188 @HasPermissionAnyDecorator('hg.admin', 'hg.usergroup.create.true')
187 def new(self):
189 def new(self):
@@ -467,5 +469,12 b' class UserGroupsController(BaseControlle'
467 c.group_members_obj = sorted((x.user for x in c.user_group.members),
469 c.group_members_obj = sorted((x.user for x in c.user_group.members),
468 key=lambda u: u.username.lower())
470 key=lambda u: u.username.lower())
469
471
470 c.group_members = [(x.user_id, x.username) for x in c.group_members_obj]
472 group_members = [(x.user_id, x.username) for x in c.group_members_obj]
473
474 if request.is_xhr:
475 return jsonify(lambda *a, **k: {
476 'members': group_members
477 })
478
479 c.group_members = group_members
471 return render('admin/user_groups/user_group_edit.html')
480 return render('admin/user_groups/user_group_edit.html')
@@ -14,6 +14,7 b' function registerRCRoutes() {'
14 pyroutes.register('files_home', '/%(repo_name)s/files/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']);
14 pyroutes.register('files_home', '/%(repo_name)s/files/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']);
15 pyroutes.register('edit_repo', '/%(repo_name)s/settings', ['repo_name']);
15 pyroutes.register('edit_repo', '/%(repo_name)s/settings', ['repo_name']);
16 pyroutes.register('edit_repo_perms', '/%(repo_name)s/settings/permissions', ['repo_name']);
16 pyroutes.register('edit_repo_perms', '/%(repo_name)s/settings/permissions', ['repo_name']);
17 pyroutes.register('edit_user_group_members', '/_admin/user_groups/%(user_group_id)s/edit/members', ['user_group_id']);
17 pyroutes.register('pullrequest_home', '/%(repo_name)s/pull-request/new', ['repo_name']);
18 pyroutes.register('pullrequest_home', '/%(repo_name)s/pull-request/new', ['repo_name']);
18 pyroutes.register('user_autocomplete_data', '/_users', []);
19 pyroutes.register('user_autocomplete_data', '/_users', []);
19 pyroutes.register('toggle_following', '/_admin/toggle_following', []);
20 pyroutes.register('toggle_following', '/_admin/toggle_following', []);
@@ -44,6 +44,9 b''
44 <div class="field">
44 <div class="field">
45 <div class="label">
45 <div class="label">
46 <label for="users_group_active">${_('Members')}:</label>
46 <label for="users_group_active">${_('Members')}:</label>
47 ${h.text('from_user_group',
48 placeholder="select only users",
49 class_="medium")}
47 </div>
50 </div>
48 <div class="select side-by-side-selector">
51 <div class="select side-by-side-selector">
49 <div class="left-group">
52 <div class="left-group">
@@ -60,7 +63,8 b''
60 <i id="remove_element" class="icon-chevron-right"></i>
63 <i id="remove_element" class="icon-chevron-right"></i>
61 </div>
64 </div>
62 <div class="right-group">
65 <div class="right-group">
63 <label class="text" >${_('Available members')}</label>
66 <label class="text" >${_('Available members')}
67 </label>
64 ${h.select('available_members',[],c.available_members,multiple=True,size=8,)}
68 ${h.select('available_members',[],c.available_members,multiple=True,size=8,)}
65 <div class="btn" id="add_all_elements" >
69 <div class="btn" id="add_all_elements" >
66 <i class="icon-chevron-left"></i>${_('Add all elements')}
70 <i class="icon-chevron-left"></i>${_('Add all elements')}
@@ -86,6 +90,42 b''
86 'dropdownAutoWidth': true
90 'dropdownAutoWidth': true
87 });
91 });
88
92
93 $('#from_user_group').autocomplete({
94 serviceUrl: pyroutes.url('user_autocomplete_data'),
95 minChars:2,
96 maxHeight:400,
97 width:300,
98 deferRequestBy: 300, //miliseconds
99 showNoSuggestionNotice: true,
100 params: { user_groups:true },
101 formatResult: autocompleteFormatResult,
102 lookupFilter: autocompleteFilterResult,
103 onSelect: function(element, suggestion){
104
105 function preSelectUserIds(uids) {
106 $('#available_members').val(uids);
107 $('#users_group_members').val(uids);
108 }
109
110 if (suggestion.value_type == 'user_group') {
111 $.getJSON(
112 pyroutes.url('edit_user_group_members',
113 {'user_group_id': suggestion.id}),
114 function(data) {
115 var uids = [];
116 $.each(data.members, function(idx, user) {
117 var userid = user[0],
118 username = user[1];
119 uids.push(userid.toString());
120 });
121 preSelectUserIds(uids)
122 }
123 );
124 } else if (suggestion.value_type == 'user') {
125 preSelectUserIds([suggestion.id.toString()]);
126 }
127 }
128 });
89 UsersAutoComplete('user', '${c.rhodecode_user.user_id}');
129 UsersAutoComplete('user', '${c.rhodecode_user.user_id}');
90 })
130 })
91 </script>
131 </script>
@@ -35,7 +35,8 b' class TestAdminUsersGroupsController(Tes'
35
35
36 def test_index(self):
36 def test_index(self):
37 self.log_user()
37 self.log_user()
38 self.app.get(url('users_groups'))
38 response = self.app.get(url('users_groups'))
39 response.mustcontain('No members yet')
39
40
40 def test_create(self):
41 def test_create(self):
41 self.log_user()
42 self.log_user()
@@ -148,7 +149,13 b' class TestAdminUsersGroupsController(Tes'
148 fixture.destroy_user_group(users_group_name)
149 fixture.destroy_user_group(users_group_name)
149
150
150 def test_edit(self):
151 def test_edit(self):
151 self.app.get(url('edit_users_group', user_group_id=1))
152 self.log_user()
153 response = self.app.get(url('edit_users_group', user_group_id=1))
154
155 def test_edit_user_group_members(self):
156 self.log_user()
157 response = self.app.get(url('edit_user_group_members', user_group_id=1))
158 response.mustcontain('No members yet')
152
159
153 def test_usergroup_escape(self):
160 def test_usergroup_escape(self):
154 user = User.get_by_username('test_admin')
161 user = User.get_by_username('test_admin')
General Comments 0
You need to be logged in to leave comments. Login now