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

Add group summary APIs #2363

Merged
merged 11 commits into from
Jul 17, 2017
255 changes: 246 additions & 9 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ class FederationGroupsProfileServlet(BaseFederationServlet):
PATH = "/groups/(?P<group_id>[^/]*)/profile$"

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

Expand All @@ -627,14 +627,30 @@ def on_POST(self, origin, content, query, group_id):
defer.returnValue((200, new_content))


class FederationGroupsSummaryServlet(BaseFederationServlet):
PATH = "/groups/(?P<group_id>[^/]*)/summary$"

@defer.inlineCallbacks
def on_GET(self, origin, content, query, group_id):
requester_user_id = 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_group_summary(
group_id, requester_user_id
)

defer.returnValue((200, new_content))


class FederationGroupsRoomsServlet(BaseFederationServlet):
"""Get the rooms in a group on behalf of a user
"""
PATH = "/groups/(?P<group_id>[^/]*)/rooms$"

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

Expand All @@ -652,7 +668,7 @@ class FederationGroupsAddRoomsServlet(BaseFederationServlet):

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

Expand All @@ -669,8 +685,8 @@ class FederationGroupsUsersServlet(BaseFederationServlet):
PATH = "/groups/(?P<group_id>[^/]*)/users$"

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

Expand All @@ -688,7 +704,7 @@ class FederationGroupsInviteServlet(BaseFederationServlet):

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

Expand Down Expand Up @@ -723,7 +739,7 @@ class FederationGroupsRemoveUserServlet(BaseFederationServlet):

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

Expand All @@ -750,6 +766,220 @@ def on_POST(self, origin, content, query, group_id, user_id):
defer.returnValue((200, new_content))


class FederationGroupsSummaryRoomsServlet(BaseFederationServlet):
"""Add/remove a room from the group summary, with optional category.

Matches both:
- /groups/:group/summary/rooms/:room_id
- /groups/:group/summary/categories/:category/rooms/:room_id
"""
PATH = (
"/groups/(?P<group_id>[^/]*)/summary"
"(/categories/(?P<category_id>[^/]+))?"
"/rooms/(?P<room_id>[^/]*)$"
)

@defer.inlineCallbacks
def on_POST(self, origin, content, query, group_id, category_id, room_id):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check that the category is not the default ID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(done)

requester_user_id = query["requester_user_id"]
if get_domain_from_id(requester_user_id) != origin:
raise SynapseError(403, "requester_user_id doesn't match origin")

resp = yield self.handler.update_group_summary_room(
group_id, requester_user_id,
room_id=room_id,
category_id=category_id,
content=content,
)

defer.returnValue((200, resp))

@defer.inlineCallbacks
def on_DELETE(self, origin, content, query, group_id, category_id, room_id):
requester_user_id = query["requester_user_id"]
if get_domain_from_id(requester_user_id) != origin:
raise SynapseError(403, "requester_user_id doesn't match origin")

resp = yield self.handler.delete_group_summary_room(
group_id, requester_user_id,
room_id=room_id,
category_id=category_id,
)

defer.returnValue((200, resp))


class FederationGroupsCategoriesServlet(BaseFederationServlet):
"""Get all categories for a group
"""
PATH = (
"/groups/(?P<group_id>[^/]*)/categories/$"
)

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

resp = yield self.handler.get_group_categories(
group_id, requester_user_id,
)

defer.returnValue((200, resp))


class FederationGroupsCategoryServlet(BaseFederationServlet):
"""Add/remove/get a category in a group
"""
PATH = (
"/groups/(?P<group_id>[^/]*)/categories/(?P<category_id>[^/]+)$"
)

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

resp = yield self.handler.get_group_category(
group_id, requester_user_id, category_id
)

defer.returnValue((200, resp))

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

resp = yield self.handler.upsert_group_category(
group_id, requester_user_id, category_id, content,
)

defer.returnValue((200, resp))

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

resp = yield self.handler.delete_group_category(
group_id, requester_user_id, category_id,
)

defer.returnValue((200, resp))


class FederationGroupsRolesServlet(BaseFederationServlet):
"""Get roles in a group
"""
PATH = (
"/groups/(?P<group_id>[^/]*)/roles/$"
)

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

resp = yield self.handler.get_group_roles(
group_id, requester_user_id,
)

defer.returnValue((200, resp))


class FederationGroupsRoleServlet(BaseFederationServlet):
"""Add/remove/get a role in a group
"""
PATH = (
"/groups/(?P<group_id>[^/]*)/roles/(?P<role_id>[^/]+)$"
)

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

resp = yield self.handler.get_group_role(
group_id, requester_user_id, role_id
)

defer.returnValue((200, resp))

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

resp = yield self.handler.update_group_role(
group_id, requester_user_id, role_id, content,
)

defer.returnValue((200, resp))

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

resp = yield self.handler.delete_group_role(
group_id, requester_user_id, role_id,
)

defer.returnValue((200, resp))


class FederationGroupsSummaryUsersServlet(BaseFederationServlet):
"""Add/remove a user from the group summary, with optional role.

Matches both:
- /groups/:group/summary/users/:user_id
- /groups/:group/summary/roles/:role/users/:user_id
"""
PATH = (
"/groups/(?P<group_id>[^/]*)/summary"
"(/roles/(?P<role_id>[^/]+))?"
"/users/(?P<user_id>[^/]*)$"
)

@defer.inlineCallbacks
def on_POST(self, origin, content, query, group_id, role_id, user_id):
requester_user_id = query["requester_user_id"]
if get_domain_from_id(requester_user_id) != origin:
raise SynapseError(403, "requester_user_id doesn't match origin")

resp = yield self.handler.update_group_summary_user(
group_id, requester_user_id,
user_id=user_id,
role_id=role_id,
content=content,
)

defer.returnValue((200, resp))

@defer.inlineCallbacks
def on_DELETE(self, origin, content, query, group_id, role_id, user_id):
requester_user_id = query["requester_user_id"]
if get_domain_from_id(requester_user_id) != origin:
raise SynapseError(403, "requester_user_id doesn't match origin")

resp = yield self.handler.delete_group_summary_user(
group_id, requester_user_id,
user_id=user_id,
role_id=role_id,
)

defer.returnValue((200, resp))


FEDERATION_SERVLET_CLASSES = (
FederationSendServlet,
FederationPullServlet,
Expand Down Expand Up @@ -784,11 +1014,18 @@ def on_POST(self, origin, content, query, group_id, user_id):

GROUP_SERVER_SERVLET_CLASSES = (
FederationGroupsProfileServlet,
FederationGroupsSummaryServlet,
FederationGroupsRoomsServlet,
FederationGroupsUsersServlet,
FederationGroupsInviteServlet,
FederationGroupsAcceptInviteServlet,
FederationGroupsRemoveUserServlet,
FederationGroupsSummaryRoomsServlet,
FederationGroupsCategoriesServlet,
FederationGroupsCategoryServlet,
FederationGroupsRolesServlet,
FederationGroupsRoleServlet,
FederationGroupsSummaryUsersServlet,
)


Expand Down
Loading