- Add support for orgs in the entity search and the notification system
- Fix the titles/names of the different notification types - Fix the styling of the options buttons on the notifications
This commit is contained in:
parent
1ffbc77106
commit
54ee94754e
6 changed files with 55 additions and 13 deletions
|
@ -2,9 +2,11 @@ from endpoints.api import (ApiResource, parse_args, query_param, truthy_bool, ni
|
|||
require_scope)
|
||||
from data import model
|
||||
from auth.permissions import (OrganizationMemberPermission, ViewTeamPermission,
|
||||
ReadRepositoryPermission, UserAdminPermission)
|
||||
ReadRepositoryPermission, UserAdminPermission,
|
||||
AdministerOrganizationPermission)
|
||||
from auth.auth_context import get_authenticated_user
|
||||
from auth import scopes
|
||||
from util.gravatar import compute_hash
|
||||
|
||||
|
||||
@resource('/v1/entities/<prefix>')
|
||||
|
@ -14,10 +16,12 @@ class EntitySearch(ApiResource):
|
|||
@query_param('namespace', 'Namespace to use when querying for org entities.', type=str,
|
||||
default='')
|
||||
@query_param('includeTeams', 'Whether to include team names.', type=truthy_bool, default=False)
|
||||
@query_param('includeOrgs', 'Whether to include orgs names.', type=truthy_bool, default=False)
|
||||
@nickname('getMatchingEntities')
|
||||
def get(self, args, prefix):
|
||||
""" Get a list of entities that match the specified prefix. """
|
||||
teams = []
|
||||
org_data = []
|
||||
|
||||
namespace_name = args['namespace']
|
||||
robot_namespace = None
|
||||
|
@ -34,6 +38,15 @@ class EntitySearch(ApiResource):
|
|||
if args['includeTeams']:
|
||||
teams = model.get_matching_teams(prefix, organization)
|
||||
|
||||
if args['includeOrgs'] and AdministerOrganizationPermission(namespace_name) \
|
||||
and namespace_name.startswith(prefix):
|
||||
org_data = [{
|
||||
'name': namespace_name,
|
||||
'kind': 'org',
|
||||
'is_org_member': True,
|
||||
'gravatar': compute_hash(organization.email),
|
||||
}]
|
||||
|
||||
except model.InvalidOrganizationException:
|
||||
# namespace name was a user
|
||||
user = get_authenticated_user()
|
||||
|
@ -69,7 +82,7 @@ class EntitySearch(ApiResource):
|
|||
user_data = [user_view(user) for user in users]
|
||||
|
||||
return {
|
||||
'results': team_data + user_data
|
||||
'results': team_data + user_data + org_data
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,4 +126,4 @@ class FindRepositories(ApiResource):
|
|||
'repositories': [repo_view(repo) for repo in matching
|
||||
if (repo.visibility.name == 'public' or
|
||||
ReadRepositoryPermission(repo.namespace, repo.name).can())]
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue