mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-17 20:53:50 +01:00
Grant ASes the ability to delete aliases in their own namespace.
This commit is contained in:
parent
e426df8e10
commit
c3ae8def75
2 changed files with 52 additions and 7 deletions
|
@ -87,10 +87,9 @@ class DirectoryHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def delete_association(self, user_id, room_alias):
|
def delete_association(self, user_id, room_alias):
|
||||||
# TODO Check if server admin
|
# association deletion for human users
|
||||||
|
|
||||||
if not self.hs.is_mine(room_alias):
|
# TODO Check if server admin
|
||||||
raise SynapseError(400, "Room alias must be local")
|
|
||||||
|
|
||||||
is_claimed = yield self.is_alias_exclusive_to_appservices(room_alias)
|
is_claimed = yield self.is_alias_exclusive_to_appservices(room_alias)
|
||||||
if is_claimed:
|
if is_claimed:
|
||||||
|
@ -99,10 +98,29 @@ class DirectoryHandler(BaseHandler):
|
||||||
errcode=Codes.EXCLUSIVE
|
errcode=Codes.EXCLUSIVE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
yield self._delete_association(room_alias)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def delete_appservice_association(self, service, room_alias):
|
||||||
|
if not service.is_interested_in_alias(room_alias.to_string()):
|
||||||
|
raise SynapseError(
|
||||||
|
400,
|
||||||
|
"This application service has not reserved this kind of alias",
|
||||||
|
errcode=Codes.EXCLUSIVE
|
||||||
|
)
|
||||||
|
yield self._delete_association(room_alias)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def _delete_association(self, room_alias):
|
||||||
|
if not self.hs.is_mine(room_alias):
|
||||||
|
raise SynapseError(400, "Room alias must be local")
|
||||||
|
|
||||||
room_id = yield self.store.delete_room_alias(room_alias)
|
room_id = yield self.store.delete_room_alias(room_alias)
|
||||||
|
|
||||||
if room_id:
|
# TODO - Looks like _update_room_alias_event has never been implemented
|
||||||
yield self._update_room_alias_events(user_id, room_id)
|
# if room_id:
|
||||||
|
# yield self._update_room_alias_events(user_id, room_id)
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_association(self, room_alias):
|
def get_association(self, room_alias):
|
||||||
|
|
|
@ -87,24 +87,51 @@ class ClientDirectoryServer(ClientV1RestServlet):
|
||||||
yield dir_handler.create_appservice_association(
|
yield dir_handler.create_appservice_association(
|
||||||
service, room_alias, room_id, servers
|
service, room_alias, room_id, servers
|
||||||
)
|
)
|
||||||
|
logger.info(
|
||||||
|
"Application service at %s created alias %s pointing to %s",
|
||||||
|
service.url,
|
||||||
|
room_alias.to_string(),
|
||||||
|
room_id
|
||||||
|
)
|
||||||
|
|
||||||
defer.returnValue((200, {}))
|
defer.returnValue((200, {}))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_DELETE(self, request, room_alias):
|
def on_DELETE(self, request, room_alias):
|
||||||
|
dir_handler = self.handlers.directory_handler
|
||||||
|
|
||||||
|
try:
|
||||||
|
service = yield self.auth.get_appservice_by_req(request)
|
||||||
|
room_alias = RoomAlias.from_string(room_alias)
|
||||||
|
yield dir_handler.delete_appservice_association(
|
||||||
|
service, room_alias
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
"Application service at %s deleted alias %s",
|
||||||
|
service.url,
|
||||||
|
room_alias.to_string()
|
||||||
|
)
|
||||||
|
defer.returnValue((200, {}))
|
||||||
|
except AuthError:
|
||||||
|
# fallback to default user behaviour if they aren't an AS
|
||||||
|
pass
|
||||||
|
|
||||||
user, client = yield self.auth.get_user_by_req(request)
|
user, client = yield self.auth.get_user_by_req(request)
|
||||||
|
|
||||||
is_admin = yield self.auth.is_server_admin(user)
|
is_admin = yield self.auth.is_server_admin(user)
|
||||||
if not is_admin:
|
if not is_admin:
|
||||||
raise AuthError(403, "You need to be a server admin")
|
raise AuthError(403, "You need to be a server admin")
|
||||||
|
|
||||||
dir_handler = self.handlers.directory_handler
|
|
||||||
|
|
||||||
room_alias = RoomAlias.from_string(room_alias)
|
room_alias = RoomAlias.from_string(room_alias)
|
||||||
|
|
||||||
yield dir_handler.delete_association(
|
yield dir_handler.delete_association(
|
||||||
user.to_string(), room_alias
|
user.to_string(), room_alias
|
||||||
)
|
)
|
||||||
|
logger.info(
|
||||||
|
"User %s deleted alias %s",
|
||||||
|
user.to_string(),
|
||||||
|
room_alias.to_string()
|
||||||
|
)
|
||||||
|
|
||||||
defer.returnValue((200, {}))
|
defer.returnValue((200, {}))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue