##// 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 from rhodecode.lib.index import searcher_from_config
37 from rhodecode.lib.index import searcher_from_config
38 from rhodecode.lib.ext_json import json
38 from rhodecode.lib.ext_json import json
39 from rhodecode.lib.utils import jsonify
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 from rhodecode.model.db import Repository, RepoGroup
41 from rhodecode.model.db import Repository, RepoGroup
42 from rhodecode.model.repo import RepoModel
42 from rhodecode.model.repo import RepoModel
43 from rhodecode.model.repo_group import RepoGroupModel
43 from rhodecode.model.repo_group import RepoGroupModel
@@ -259,13 +259,16 b' class HomeController(BaseController):'
259 @jsonify
259 @jsonify
260 def user_autocomplete_data(self):
260 def user_autocomplete_data(self):
261 query = request.GET.get('query')
261 query = request.GET.get('query')
262 active = str2bool(request.GET.get('active') or True)
262
263
263 repo_model = RepoModel()
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 if request.GET.get('user_groups'):
268 if request.GET.get('user_groups'):
267 # extend with user groups
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 _users = _users + _user_groups
272 _users = _users + _user_groups
270
273
271 return {'suggestions': _users}
274 return {'suggestions': _users}
@@ -275,9 +278,11 b' class HomeController(BaseController):'
275 @jsonify
278 @jsonify
276 def user_group_autocomplete_data(self):
279 def user_group_autocomplete_data(self):
277 query = request.GET.get('query')
280 query = request.GET.get('query')
281 active = str2bool(request.GET.get('active') or True)
278
282
279 repo_model = RepoModel()
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 _user_groups = _user_groups
286 _user_groups = _user_groups
282
287
283 return {'suggestions': _user_groups}
288 return {'suggestions': _user_groups}
@@ -133,6 +133,18 b' class TestUserAutocompleteData(TestContr'
133 values = [suggestion['value'] for suggestion in result['suggestions']]
133 values = [suggestion['value'] for suggestion in result['suggestions']]
134 assert user_name in values
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 def test_returns_groups_when_user_groups_sent(self, user_util):
148 def test_returns_groups_when_user_groups_sent(self, user_util):
137 self.log_user()
149 self.log_user()
138 group = user_util.create_user_group(user_groups_active=True)
150 group = user_util.create_user_group(user_groups_active=True)
@@ -173,8 +185,10 b' class TestUserAutocompleteData(TestContr'
173 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
185 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
174
186
175 result = json.loads(response.body)
187 result = json.loads(response.body)
176 users_mock.assert_called_once_with(name_contains=query)
188 users_mock.assert_called_once_with(
177 groups_mock.assert_called_once_with(name_contains=query)
189 name_contains=query, only_active=True)
190 groups_mock.assert_called_once_with(
191 name_contains=query, only_active=True)
178 assert len(result['suggestions']) == 20
192 assert len(result['suggestions']) == 20
179
193
180
194
General Comments 0
You need to be logged in to leave comments. Login now