Add bulk group publicised lookup API

This commit is contained in:
Erik Johnston 2017-08-09 13:36:22 +01:00
parent b880ff190a
commit ef8e578677
5 changed files with 142 additions and 0 deletions

View file

@ -584,6 +584,59 @@ class GroupSelfUpdatePublicityServlet(RestServlet):
defer.returnValue((200, {}))
class PublicisedGroupsForUserServlet(RestServlet):
"""Get the list of groups a user is advertising
"""
PATTERNS = client_v2_patterns(
"/publicised_groups/(?P<user_id>[^/]*)$"
)
def __init__(self, hs):
super(PublicisedGroupsForUserServlet, self).__init__()
self.auth = hs.get_auth()
self.clock = hs.get_clock()
self.store = hs.get_datastore()
self.groups_handler = hs.get_groups_local_handler()
@defer.inlineCallbacks
def on_GET(self, request, user_id):
yield self.auth.get_user_by_req(request)
result = yield self.groups_handler.get_publicised_groups_for_user(
user_id
)
defer.returnValue((200, result))
class PublicisedGroupsForUsersServlet(RestServlet):
"""Get the list of groups a user is advertising
"""
PATTERNS = client_v2_patterns(
"/publicised_groups$"
)
def __init__(self, hs):
super(PublicisedGroupsForUsersServlet, self).__init__()
self.auth = hs.get_auth()
self.clock = hs.get_clock()
self.store = hs.get_datastore()
self.groups_handler = hs.get_groups_local_handler()
@defer.inlineCallbacks
def on_POST(self, request):
yield self.auth.get_user_by_req(request)
content = parse_json_object_from_request(request)
user_ids = content["user_ids"]
result = yield self.groups_handler.bulk_get_publicised_groups(
user_ids
)
defer.returnValue((200, result))
class GroupsForUserServlet(RestServlet):
"""Get all groups the logged in user is joined to
"""
@ -627,3 +680,4 @@ def register_servlets(hs, http_server):
GroupRolesServlet(hs).register(http_server)
GroupSelfUpdatePublicityServlet(hs).register(http_server)
GroupSummaryUsersRoleServlet(hs).register(http_server)
PublicisedGroupsForUserServlet(hs).register(http_server)