# HG changeset patch # User Marcin Kuzminski # Date 2016-06-18 12:23:57 # Node ID c6ddf19a654d1e89d339479b970f4b734e5c7d26 # Parent 1cb0de524645e3e4087b760c2ce766afebc952b3 autocomplete: add flags to show/hide active users, and also display this information in autocomplete data. ref #3374 diff --git a/rhodecode/controllers/home.py b/rhodecode/controllers/home.py --- a/rhodecode/controllers/home.py +++ b/rhodecode/controllers/home.py @@ -274,4 +274,11 @@ class HomeController(BaseController): @XHRRequired() @jsonify def user_group_autocomplete_data(self): - return {'suggestions': []} + query = request.GET.get('query') + + repo_model = RepoModel() + _user_groups = repo_model.get_user_groups(name_contains=query) + _user_groups = _user_groups + + return {'suggestions': _user_groups} + diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -140,10 +140,12 @@ class RepoModel(BaseModel): return None - def get_users(self, name_contains=None, limit=20): + def get_users(self, name_contains=None, limit=20, only_active=True): # TODO: mikhail: move this method to the UserModel. query = self.sa.query(User) - query = query.filter(User.active == true()) + if only_active: + query = query.filter(User.active == true()) + if name_contains: ilike_expression = u'%{}%'.format(safe_unicode(name_contains)) query = query.filter( @@ -165,16 +167,19 @@ class RepoModel(BaseModel): 'icon_link': h.gravatar_url(user.email, 14), 'value_display': h.person(user.email), 'value': user.username, - 'value_type': 'user' + 'value_type': 'user', + 'active': user.active, } for user in users ] return _users - def get_user_groups(self, name_contains=None, limit=20): + def get_user_groups(self, name_contains=None, limit=20, only_active=True): # TODO: mikhail: move this method to the UserGroupModel. query = self.sa.query(UserGroup) - query = query.filter(UserGroup.users_group_active == true()) + if only_active: + query = query.filter(UserGroup.users_group_active == true()) + if name_contains: ilike_expression = u'%{}%'.format(safe_unicode(name_contains)) query = query.filter( @@ -196,7 +201,8 @@ class RepoModel(BaseModel): 'value_display': 'Group: %s (%d members)' % ( group.users_group_name, len(group.members),), 'value': group.users_group_name, - 'value_type': 'user_group' + 'value_type': 'user_group', + 'active': group.users_group_active, } for group in user_groups ] diff --git a/rhodecode/public/js/src/rhodecode/utils/autocomplete.js b/rhodecode/public/js/src/rhodecode/utils/autocomplete.js --- a/rhodecode/public/js/src/rhodecode/utils/autocomplete.js +++ b/rhodecode/public/js/src/rhodecode/utils/autocomplete.js @@ -19,19 +19,25 @@ /** * autocomplete formatter that uses gravatar * */ -var autocompleteFormatResult = function(data, value, org_formatter) { - var value_display = data.value_display; +var autocompleteFormatResult = function (data, value, org_formatter) { + var activeUser = data.active || true; + var valueDisplay = data.value_display; + + if (!activeUser) { + valueDisplay = '(disabled) ' + valueDisplay; + } + var escapeRegExChars = function (value) { return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); }; var pattern = '(' + escapeRegExChars(value) + ')'; - value_display = value_display.replace(new RegExp(pattern, 'gi'), '$1<\/strong>'); + valueDisplay = valueDisplay.replace(new RegExp(pattern, 'gi'), '$1<\/strong>'); var tmpl = '
{1}
'; if (data.icon_link === "") { tmpl = '
{0}
'; - return tmpl.format(value_display); + return tmpl.format(valueDisplay); } - return tmpl.format(data.icon_link, value_display); + return tmpl.format(data.icon_link, valueDisplay); }; /**