mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Merge pull request #2651 from matrix-org/erikj/update_group_room_settings
Change so that update group room visibility isn't an upsert
This commit is contained in:
commit
0fcb5a8ce5
@ -531,9 +531,9 @@ class TransportLayerClient(object):
|
|||||||
ignore_backoff=True,
|
ignore_backoff=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_room_group_association(self, destination, group_id, requester_user_id,
|
def add_room_to_group(self, destination, group_id, requester_user_id, room_id,
|
||||||
room_id, content):
|
content):
|
||||||
"""Add or update an association between room and group
|
"""Add a room to a group
|
||||||
"""
|
"""
|
||||||
path = PREFIX + "/groups/%s/room/%s" % (group_id, room_id,)
|
path = PREFIX + "/groups/%s/room/%s" % (group_id, room_id,)
|
||||||
|
|
||||||
@ -545,8 +545,21 @@ class TransportLayerClient(object):
|
|||||||
ignore_backoff=True,
|
ignore_backoff=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_room_group_association(self, destination, group_id, requester_user_id,
|
def update_room_in_group(self, destination, group_id, requester_user_id, room_id,
|
||||||
room_id):
|
config_key, content):
|
||||||
|
"""Update room in group
|
||||||
|
"""
|
||||||
|
path = PREFIX + "/groups/%s/room/%s/config/%s" % (group_id, room_id, config_key,)
|
||||||
|
|
||||||
|
return self.client.post_json(
|
||||||
|
destination=destination,
|
||||||
|
path=path,
|
||||||
|
args={"requester_user_id": requester_user_id},
|
||||||
|
data=content,
|
||||||
|
ignore_backoff=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
def remove_room_from_group(self, destination, group_id, requester_user_id, room_id):
|
||||||
"""Remove a room from a group
|
"""Remove a room from a group
|
||||||
"""
|
"""
|
||||||
path = PREFIX + "/groups/%s/room/%s" % (group_id, room_id,)
|
path = PREFIX + "/groups/%s/room/%s" % (group_id, room_id,)
|
||||||
|
@ -676,7 +676,7 @@ class FederationGroupsRoomsServlet(BaseFederationServlet):
|
|||||||
class FederationGroupsAddRoomsServlet(BaseFederationServlet):
|
class FederationGroupsAddRoomsServlet(BaseFederationServlet):
|
||||||
"""Add/remove room from group
|
"""Add/remove room from group
|
||||||
"""
|
"""
|
||||||
PATH = "/groups/(?P<group_id>[^/]*)/room/(?<room_id>)$"
|
PATH = "/groups/(?P<group_id>[^/]*)/room/(?P<room_id>[^/]*)$"
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_POST(self, origin, content, query, group_id, room_id):
|
def on_POST(self, origin, content, query, group_id, room_id):
|
||||||
@ -684,7 +684,7 @@ class FederationGroupsAddRoomsServlet(BaseFederationServlet):
|
|||||||
if get_domain_from_id(requester_user_id) != origin:
|
if get_domain_from_id(requester_user_id) != origin:
|
||||||
raise SynapseError(403, "requester_user_id doesn't match origin")
|
raise SynapseError(403, "requester_user_id doesn't match origin")
|
||||||
|
|
||||||
new_content = yield self.handler.update_room_group_association(
|
new_content = yield self.handler.add_room_to_group(
|
||||||
group_id, requester_user_id, room_id, content
|
group_id, requester_user_id, room_id, content
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -696,13 +696,34 @@ class FederationGroupsAddRoomsServlet(BaseFederationServlet):
|
|||||||
if get_domain_from_id(requester_user_id) != origin:
|
if get_domain_from_id(requester_user_id) != origin:
|
||||||
raise SynapseError(403, "requester_user_id doesn't match origin")
|
raise SynapseError(403, "requester_user_id doesn't match origin")
|
||||||
|
|
||||||
new_content = yield self.handler.delete_room_group_association(
|
new_content = yield self.handler.remove_room_from_group(
|
||||||
group_id, requester_user_id, room_id,
|
group_id, requester_user_id, room_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
defer.returnValue((200, new_content))
|
defer.returnValue((200, new_content))
|
||||||
|
|
||||||
|
|
||||||
|
class FederationGroupsAddRoomsConfigServlet(BaseFederationServlet):
|
||||||
|
"""Update room config in group
|
||||||
|
"""
|
||||||
|
PATH = (
|
||||||
|
"/groups/(?P<group_id>[^/]*)/room/(?P<room_id>[^/]*)"
|
||||||
|
"/config/(?P<config_key>[^/]*)$"
|
||||||
|
)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def on_POST(self, origin, content, query, group_id, room_id, config_key):
|
||||||
|
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")
|
||||||
|
|
||||||
|
result = yield self.groups_handler.update_room_in_group(
|
||||||
|
group_id, requester_user_id, room_id, config_key, content,
|
||||||
|
)
|
||||||
|
|
||||||
|
defer.returnValue((200, result))
|
||||||
|
|
||||||
|
|
||||||
class FederationGroupsUsersServlet(BaseFederationServlet):
|
class FederationGroupsUsersServlet(BaseFederationServlet):
|
||||||
"""Get the users in a group on behalf of a user
|
"""Get the users in a group on behalf of a user
|
||||||
"""
|
"""
|
||||||
@ -1142,6 +1163,8 @@ GROUP_SERVER_SERVLET_CLASSES = (
|
|||||||
FederationGroupsRolesServlet,
|
FederationGroupsRolesServlet,
|
||||||
FederationGroupsRoleServlet,
|
FederationGroupsRoleServlet,
|
||||||
FederationGroupsSummaryUsersServlet,
|
FederationGroupsSummaryUsersServlet,
|
||||||
|
FederationGroupsAddRoomsServlet,
|
||||||
|
FederationGroupsAddRoomsConfigServlet,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -530,9 +530,8 @@ class GroupsServerHandler(object):
|
|||||||
})
|
})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def update_room_group_association(self, group_id, requester_user_id, room_id,
|
def add_room_to_group(self, group_id, requester_user_id, room_id, content):
|
||||||
content):
|
"""Add room to group
|
||||||
"""Add or update an association between room and group
|
|
||||||
"""
|
"""
|
||||||
RoomID.from_string(room_id) # Ensure valid room id
|
RoomID.from_string(room_id) # Ensure valid room id
|
||||||
|
|
||||||
@ -542,21 +541,42 @@ class GroupsServerHandler(object):
|
|||||||
|
|
||||||
is_public = _parse_visibility_from_contents(content)
|
is_public = _parse_visibility_from_contents(content)
|
||||||
|
|
||||||
yield self.store.update_room_group_association(
|
yield self.store.add_room_to_group(group_id, room_id, is_public=is_public)
|
||||||
group_id, room_id, is_public=is_public
|
|
||||||
)
|
|
||||||
|
|
||||||
defer.returnValue({})
|
defer.returnValue({})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def delete_room_group_association(self, group_id, requester_user_id, room_id):
|
def update_room_in_group(self, group_id, requester_user_id, room_id, config_key,
|
||||||
|
content):
|
||||||
|
"""Update room in group
|
||||||
|
"""
|
||||||
|
RoomID.from_string(room_id) # Ensure valid room id
|
||||||
|
|
||||||
|
yield self.check_group_is_ours(
|
||||||
|
group_id, requester_user_id, and_exists=True, and_is_admin=requester_user_id
|
||||||
|
)
|
||||||
|
|
||||||
|
if config_key == "visibility":
|
||||||
|
is_public = _parse_visibility_from_contents(content)
|
||||||
|
|
||||||
|
yield self.store.update_room_in_group_visibility(
|
||||||
|
group_id, room_id,
|
||||||
|
is_public=is_public,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise SynapseError(400, "Uknown config option")
|
||||||
|
|
||||||
|
defer.returnValue({})
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def remove_room_from_group(self, group_id, requester_user_id, room_id):
|
||||||
"""Remove room from group
|
"""Remove room from group
|
||||||
"""
|
"""
|
||||||
yield self.check_group_is_ours(
|
yield self.check_group_is_ours(
|
||||||
group_id, requester_user_id, and_exists=True, and_is_admin=requester_user_id
|
group_id, requester_user_id, and_exists=True, and_is_admin=requester_user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
yield self.store.delete_room_group_association(group_id, room_id)
|
yield self.store.remove_room_from_group(group_id, room_id)
|
||||||
|
|
||||||
defer.returnValue({})
|
defer.returnValue({})
|
||||||
|
|
||||||
|
@ -70,8 +70,9 @@ class GroupsLocalHandler(object):
|
|||||||
|
|
||||||
get_invited_users_in_group = _create_rerouter("get_invited_users_in_group")
|
get_invited_users_in_group = _create_rerouter("get_invited_users_in_group")
|
||||||
|
|
||||||
update_room_group_association = _create_rerouter("update_room_group_association")
|
add_room_to_group = _create_rerouter("add_room_to_group")
|
||||||
delete_room_group_association = _create_rerouter("delete_room_group_association")
|
update_room_in_group = _create_rerouter("update_room_in_group")
|
||||||
|
remove_room_from_group = _create_rerouter("remove_room_from_group")
|
||||||
|
|
||||||
update_group_summary_room = _create_rerouter("update_group_summary_room")
|
update_group_summary_room = _create_rerouter("update_group_summary_room")
|
||||||
delete_group_summary_room = _create_rerouter("delete_group_summary_room")
|
delete_group_summary_room = _create_rerouter("delete_group_summary_room")
|
||||||
|
@ -451,7 +451,7 @@ class GroupAdminRoomsServlet(RestServlet):
|
|||||||
requester_user_id = requester.user.to_string()
|
requester_user_id = requester.user.to_string()
|
||||||
|
|
||||||
content = parse_json_object_from_request(request)
|
content = parse_json_object_from_request(request)
|
||||||
result = yield self.groups_handler.update_room_group_association(
|
result = yield self.groups_handler.add_room_to_group(
|
||||||
group_id, requester_user_id, room_id, content,
|
group_id, requester_user_id, room_id, content,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -462,13 +462,40 @@ class GroupAdminRoomsServlet(RestServlet):
|
|||||||
requester = yield self.auth.get_user_by_req(request)
|
requester = yield self.auth.get_user_by_req(request)
|
||||||
requester_user_id = requester.user.to_string()
|
requester_user_id = requester.user.to_string()
|
||||||
|
|
||||||
result = yield self.groups_handler.delete_room_group_association(
|
result = yield self.groups_handler.remove_room_from_group(
|
||||||
group_id, requester_user_id, room_id,
|
group_id, requester_user_id, room_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
defer.returnValue((200, result))
|
defer.returnValue((200, result))
|
||||||
|
|
||||||
|
|
||||||
|
class GroupAdminRoomsConfigServlet(RestServlet):
|
||||||
|
"""Update the config of a room in a group
|
||||||
|
"""
|
||||||
|
PATTERNS = client_v2_patterns(
|
||||||
|
"/groups/(?P<group_id>[^/]*)/admin/rooms/(?P<room_id>[^/]*)"
|
||||||
|
"/config/(?P<config_key>[^/]*)$"
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, hs):
|
||||||
|
super(GroupAdminRoomsConfigServlet, self).__init__()
|
||||||
|
self.auth = hs.get_auth()
|
||||||
|
self.clock = hs.get_clock()
|
||||||
|
self.groups_handler = hs.get_groups_local_handler()
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def on_PUT(self, request, group_id, room_id, config_key):
|
||||||
|
requester = yield self.auth.get_user_by_req(request)
|
||||||
|
requester_user_id = requester.user.to_string()
|
||||||
|
|
||||||
|
content = parse_json_object_from_request(request)
|
||||||
|
result = yield self.groups_handler.update_room_in_group(
|
||||||
|
group_id, requester_user_id, room_id, config_key, content,
|
||||||
|
)
|
||||||
|
|
||||||
|
defer.returnValue((200, result))
|
||||||
|
|
||||||
|
|
||||||
class GroupAdminUsersInviteServlet(RestServlet):
|
class GroupAdminUsersInviteServlet(RestServlet):
|
||||||
"""Invite a user to the group
|
"""Invite a user to the group
|
||||||
"""
|
"""
|
||||||
|
@ -846,8 +846,19 @@ class GroupServerStore(SQLBaseStore):
|
|||||||
)
|
)
|
||||||
return self.runInteraction("remove_user_from_group", _remove_user_from_group_txn)
|
return self.runInteraction("remove_user_from_group", _remove_user_from_group_txn)
|
||||||
|
|
||||||
def update_room_group_association(self, group_id, room_id, is_public):
|
def add_room_to_group(self, group_id, room_id, is_public):
|
||||||
return self._simple_upsert(
|
return self._simple_insert(
|
||||||
|
table="group_rooms",
|
||||||
|
values={
|
||||||
|
"group_id": group_id,
|
||||||
|
"room_id": room_id,
|
||||||
|
"is_public": is_public,
|
||||||
|
},
|
||||||
|
desc="add_room_to_group",
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_room_in_group_visibility(self, group_id, room_id, is_public):
|
||||||
|
return self._simple_update(
|
||||||
table="group_rooms",
|
table="group_rooms",
|
||||||
keyvalues={
|
keyvalues={
|
||||||
"group_id": group_id,
|
"group_id": group_id,
|
||||||
@ -856,15 +867,11 @@ class GroupServerStore(SQLBaseStore):
|
|||||||
values={
|
values={
|
||||||
"is_public": is_public,
|
"is_public": is_public,
|
||||||
},
|
},
|
||||||
insertion_values={
|
desc="update_room_in_group_visibility",
|
||||||
"group_id": group_id,
|
|
||||||
"room_id": room_id,
|
|
||||||
},
|
|
||||||
desc="update_room_group_association",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_room_group_association(self, group_id, room_id):
|
def remove_room_from_group(self, group_id, room_id):
|
||||||
def _delete_room_group_association_txn(txn):
|
def _remove_room_from_group_txn(txn):
|
||||||
self._simple_delete_txn(
|
self._simple_delete_txn(
|
||||||
txn,
|
txn,
|
||||||
table="group_rooms",
|
table="group_rooms",
|
||||||
@ -883,7 +890,7 @@ class GroupServerStore(SQLBaseStore):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
return self.runInteraction(
|
return self.runInteraction(
|
||||||
"delete_room_group_association", _delete_room_group_association_txn,
|
"remove_room_from_group", _remove_room_from_group_txn,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_publicised_groups_for_user(self, user_id):
|
def get_publicised_groups_for_user(self, user_id):
|
||||||
|
Loading…
Reference in New Issue
Block a user