Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Implement GET /groups/$groupId/invited_users #2544

Merged
merged 5 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,19 @@ def get_users_in_group(self, destination, group_id, requester_user_id):
ignore_backoff=True,
)

@log_function
def get_invited_users_in_group(self, destination, group_id, requester_user_id):
"""Get users that have been invited to a group
"""
path = PREFIX + "/groups/%s/invited_users" % (group_id,)

return self.client.get_json(
destination=destination,
path=path,
args={"requester_user_id": requester_user_id},
ignore_backoff=True,
)

@log_function
def accept_group_invite(self, destination, group_id, user_id, content):
"""Accept a group invite
Expand Down
18 changes: 17 additions & 1 deletion synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,22 @@ def on_GET(self, origin, content, query, group_id):

defer.returnValue((200, new_content))

class FederationGroupsInvitedUsersServlet(BaseFederationServlet):
"""Get the users that have been invited to a group
"""
PATH = "/groups/(?P<group_id>[^/]*)/invited_users$"

@defer.inlineCallbacks
def on_GET(self, origin, content, query, group_id):
requester_user_id = parse_string_from_args(query, "requester_user_id")
if get_domain_from_id(requester_user_id) != origin:
raise SynapseError(403, "requester_user_id doesn't match origin")

new_content = yield self.handler.get_invited_users_in_group(
group_id, requester_user_id
)

defer.returnValue((200, new_content))

class FederationGroupsInviteServlet(BaseFederationServlet):
"""Ask a group server to invite someone to the group
Expand Down Expand Up @@ -1109,12 +1125,12 @@ def on_POST(self, origin, content, query):
PublicRoomList,
)


GROUP_SERVER_SERVLET_CLASSES = (
FederationGroupsProfileServlet,
FederationGroupsSummaryServlet,
FederationGroupsRoomsServlet,
FederationGroupsUsersServlet,
FederationGroupsInvitedUsersServlet,
FederationGroupsInviteServlet,
FederationGroupsAcceptInviteServlet,
FederationGroupsRemoveUserServlet,
Expand Down
35 changes: 35 additions & 0 deletions synapse/groups/groups_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,41 @@ def get_users_in_group(self, group_id, requester_user_id):
"total_user_count_estimate": len(user_results),
})

@defer.inlineCallbacks
def get_invited_users_in_group(self, group_id, requester_user_id):
"""Get the users that have been invited to a group as seen by requester_user_id.

The ordering is arbitrary at the moment
"""

yield self.check_group_is_ours(group_id, and_exists=True)

is_user_in_group = yield self.store.is_user_in_group(requester_user_id, group_id)

if not is_user_in_group:
raise SynapseError(403, "User not in group")

invited_users = yield self.store.get_invited_users_in_group(group_id)

user_profiles = []

for user_id in invited_users:
user_profile = {
"user_id": user_id
}
try:
profile = yield self.profile_handler.get_profile_from_cache(user)
user_profile.update(profile)
except Exception as e:
pass
user_profiles.append(user_profile)

defer.returnValue({
"chunk": user_profiles,
"total_user_count_estimate": len(invited_users),
})


@defer.inlineCallbacks
def get_rooms_in_group(self, group_id, requester_user_id):
"""Get the rooms in group as seen by requester_user_id
Expand Down
2 changes: 2 additions & 0 deletions synapse/handlers/groups_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(self, hs):
update_group_profile = _create_rerouter("update_group_profile")
get_rooms_in_group = _create_rerouter("get_rooms_in_group")

get_invited_users_in_group = _create_rerouter("get_invited_users_in_group")

add_room_to_group = _create_rerouter("add_room_to_group")
remove_room_from_group = _create_rerouter("remove_room_from_group")

Expand Down
21 changes: 21 additions & 0 deletions synapse/rest/client/v2_alpha/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,26 @@ def on_GET(self, request, group_id):

defer.returnValue((200, result))

class GroupInvitedUsersServlet(RestServlet):
"""Get users invited to a group
"""
PATTERNS = client_v2_patterns("/groups/(?P<group_id>[^/]*)/invited_users$")

def __init__(self, hs):
super(GroupInvitedUsersServlet, self).__init__()
self.auth = hs.get_auth()
self.clock = hs.get_clock()
self.groups_handler = hs.get_groups_local_handler()

@defer.inlineCallbacks
def on_GET(self, request, group_id):
requester = yield self.auth.get_user_by_req(request)
user_id = requester.user.to_string()

result = yield self.groups_handler.get_invited_users_in_group(group_id, user_id)

defer.returnValue((200, result))


class GroupCreateServlet(RestServlet):
"""Create a group
Expand Down Expand Up @@ -674,6 +694,7 @@ def on_GET(self, request):
def register_servlets(hs, http_server):
GroupServlet(hs).register(http_server)
GroupSummaryServlet(hs).register(http_server)
GroupInvitedUsersServlet(hs).register(http_server)
GroupUsersServlet(hs).register(http_server)
GroupRoomServlet(hs).register(http_server)
GroupCreateServlet(hs).register(http_server)
Expand Down
12 changes: 12 additions & 0 deletions synapse/storage/group_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ def get_users_in_group(self, group_id, include_private=False):
desc="get_users_in_group",
)

def get_invited_users_in_group(self, group_id):
# TODO: Pagination

return self._simple_select_onecol(
table="group_invites",
keyvalues={
"group_id": group_id,
},
retcol="user_id",
desc="get_invited_users_in_group",
)

def get_rooms_in_group(self, group_id, include_private=False):
# TODO: Pagination

Expand Down