quick-serach: added option to also search user-groups.
This commit is contained in:
parent
1bc95ca628
commit
bfbb9e33a4
2 changed files with 44 additions and 2 deletions
|
|
@ -211,6 +211,39 @@ class HomeView(BaseAppView):
|
|||
}
|
||||
for obj in acl_iter]
|
||||
|
||||
def _get_user_groups_list(self, name_contains=None, limit=20):
|
||||
org_query = name_contains
|
||||
if not name_contains:
|
||||
return []
|
||||
|
||||
name_contains = re.compile('(?:user_group:)(.+)').findall(name_contains)
|
||||
if len(name_contains) != 1:
|
||||
return []
|
||||
name_contains = name_contains[0]
|
||||
|
||||
query = UserGroup.query()\
|
||||
.order_by(func.length(UserGroup.users_group_name))\
|
||||
.order_by(UserGroup.users_group_name)
|
||||
|
||||
if name_contains:
|
||||
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
|
||||
query = query.filter(
|
||||
UserGroup.users_group_name.ilike(ilike_expression))
|
||||
query = query.limit(limit)
|
||||
|
||||
acl_iter = query
|
||||
|
||||
return [
|
||||
{
|
||||
'id': obj.users_group_id,
|
||||
'value': org_query,
|
||||
'value_display': obj.users_group_name,
|
||||
'type': 'user_group',
|
||||
'url': h.route_path(
|
||||
'user_group_profile', user_group_name=obj.users_group_name)
|
||||
}
|
||||
for obj in acl_iter]
|
||||
|
||||
def _get_hash_commit_list(self, auth_user, query):
|
||||
org_query = query
|
||||
if not query or len(query) < 3:
|
||||
|
|
@ -309,6 +342,10 @@ class HomeView(BaseAppView):
|
|||
for serialized_user in users:
|
||||
res.append(serialized_user)
|
||||
|
||||
user_groups = self._get_user_groups_list(query)
|
||||
for serialized_user_group in user_groups:
|
||||
res.append(serialized_user_group)
|
||||
|
||||
commits = self._get_hash_commit_list(c.auth_user, query)
|
||||
if commits:
|
||||
unique_repos = collections.OrderedDict()
|
||||
|
|
|
|||
|
|
@ -404,9 +404,11 @@ Enter name of repository, or repository group for quick search.
|
|||
|
||||
Prefix query to allow special search:
|
||||
|
||||
For usernames, e.g user:admin
|
||||
user:admin, to search for usernames
|
||||
|
||||
For commit hash/id, e.g commit:efced4
|
||||
user_group:devops, to search for user groups
|
||||
|
||||
commit:efced4, to search for commits
|
||||
|
||||
</div>
|
||||
</li>
|
||||
|
|
@ -544,6 +546,9 @@ For commit hash/id, e.g commit:efced4
|
|||
else if (searchType === 'repo_group') {
|
||||
icon += '<i class="icon-folder-close"></i> ';
|
||||
}
|
||||
else if (searchType === 'user_group') {
|
||||
icon += '<i class="icon-group"></i> ';
|
||||
}
|
||||
else if (searchType === 'user') {
|
||||
icon += '<img class="gravatar" src="{0}"/>'.format(data['icon_link']);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue