Merge pull request #2377 from matrix-org/erikj/group_profile_update

Add update group profile API
This commit is contained in:
Erik Johnston 2017-07-20 17:53:39 +01:00 committed by GitHub
commit 0401604222
5 changed files with 55 additions and 0 deletions

View file

@ -642,6 +642,18 @@ class FederationGroupsSummaryServlet(BaseFederationServlet):
defer.returnValue((200, new_content))
@defer.inlineCallbacks
def on_POST(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.update_group_profile(
group_id, requester_user_id, content
)
defer.returnValue((200, new_content))
class FederationGroupsRoomsServlet(BaseFederationServlet):
"""Get the rooms in a group on behalf of a user

View file

@ -341,6 +341,25 @@ class GroupsServerHandler(object):
else:
raise SynapseError(404, "Unknown group")
@defer.inlineCallbacks
def update_group_profile(self, group_id, requester_user_id, content):
"""Update the group profile
"""
yield self.check_group_is_ours(
group_id, and_exists=True, and_is_admin=requester_user_id,
)
profile = {}
for keyname in ("name", "avatar_url", "short_description",
"long_description"):
if keyname in content:
value = content[keyname]
if not isinstance(value, basestring):
raise SynapseError(400, "%r value is not a string" % (keyname,))
profile[keyname] = value
yield self.store.update_group_profile(group_id, profile)
@defer.inlineCallbacks
def get_users_in_group(self, group_id, requester_user_id):
"""Get the users in group as seen by requester_user_id.

View file

@ -72,6 +72,7 @@ class GroupsLocalHandler(object):
# or federation depending on if the group is local or remote
get_group_profile = _create_rerouter("get_group_profile")
update_group_profile = _create_rerouter("update_group_profile")
get_rooms_in_group = _create_rerouter("get_rooms_in_group")
add_room_to_group = _create_rerouter("add_room_to_group")

View file

@ -45,6 +45,18 @@ class GroupServlet(RestServlet):
defer.returnValue((200, group_description))
@defer.inlineCallbacks
def on_POST(self, request, group_id):
requester = yield self.auth.get_user_by_req(request)
user_id = requester.user.to_string()
content = parse_json_object_from_request(request)
yield self.groups_handler.update_group_profile(
group_id, user_id, content,
)
defer.returnValue((200, {}))
class GroupSummaryServlet(RestServlet):
"""Get the full group summary

View file

@ -860,6 +860,17 @@ class GroupServerStore(SQLBaseStore):
desc="create_group",
)
@defer.inlineCallbacks
def update_group_profile(self, group_id, profile,):
yield self._simple_update_one(
table="groups",
keyvalues={
"group_id": group_id,
},
updatevalues=profile,
desc="update_group_profile",
)
def get_attestations_need_renewals(self, valid_until_ms):
"""Get all attestations that need to be renewed until givent time
"""