##// END OF EJS Templates
autocomplete: allow to pass in a GET flag to control if non-active users should be returned in...
marcink -
r226:6371ca5e default
parent child Browse files
Show More
@@ -37,7 +37,7 b' from rhodecode.lib.base import BaseContr'
37 37 from rhodecode.lib.index import searcher_from_config
38 38 from rhodecode.lib.ext_json import json
39 39 from rhodecode.lib.utils import jsonify
40 from rhodecode.lib.utils2 import safe_unicode
40 from rhodecode.lib.utils2 import safe_unicode, str2bool
41 41 from rhodecode.model.db import Repository, RepoGroup
42 42 from rhodecode.model.repo import RepoModel
43 43 from rhodecode.model.repo_group import RepoGroupModel
@@ -259,13 +259,16 b' class HomeController(BaseController):'
259 259 @jsonify
260 260 def user_autocomplete_data(self):
261 261 query = request.GET.get('query')
262 active = str2bool(request.GET.get('active') or True)
262 263
263 264 repo_model = RepoModel()
264 _users = repo_model.get_users(name_contains=query)
265 _users = repo_model.get_users(
266 name_contains=query, only_active=active)
265 267
266 268 if request.GET.get('user_groups'):
267 269 # extend with user groups
268 _user_groups = repo_model.get_user_groups(name_contains=query)
270 _user_groups = repo_model.get_user_groups(
271 name_contains=query, only_active=active)
269 272 _users = _users + _user_groups
270 273
271 274 return {'suggestions': _users}
@@ -275,9 +278,11 b' class HomeController(BaseController):'
275 278 @jsonify
276 279 def user_group_autocomplete_data(self):
277 280 query = request.GET.get('query')
281 active = str2bool(request.GET.get('active') or True)
278 282
279 283 repo_model = RepoModel()
280 _user_groups = repo_model.get_user_groups(name_contains=query)
284 _user_groups = repo_model.get_user_groups(
285 name_contains=query, only_active=active)
281 286 _user_groups = _user_groups
282 287
283 288 return {'suggestions': _user_groups}
@@ -133,6 +133,18 b' class TestUserAutocompleteData(TestContr'
133 133 values = [suggestion['value'] for suggestion in result['suggestions']]
134 134 assert user_name in values
135 135
136 def test_returns_inactive_users_when_active_flag_sent(self, user_util):
137 self.log_user()
138 user = user_util.create_user(is_active=False)
139 user_name = user.username
140 response = self.app.get(
141 url(controller='home', action='user_autocomplete_data',
142 user_groups='true', active='0'),
143 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
144 result = json.loads(response.body)
145 values = [suggestion['value'] for suggestion in result['suggestions']]
146 assert user_name in values
147
136 148 def test_returns_groups_when_user_groups_sent(self, user_util):
137 149 self.log_user()
138 150 group = user_util.create_user_group(user_groups_active=True)
@@ -173,8 +185,10 b' class TestUserAutocompleteData(TestContr'
173 185 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
174 186
175 187 result = json.loads(response.body)
176 users_mock.assert_called_once_with(name_contains=query)
177 groups_mock.assert_called_once_with(name_contains=query)
188 users_mock.assert_called_once_with(
189 name_contains=query, only_active=True)
190 groups_mock.assert_called_once_with(
191 name_contains=query, only_active=True)
178 192 assert len(result['suggestions']) == 20
179 193
180 194
General Comments 0
You need to be logged in to leave comments. Login now