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

Commit

Permalink
Merge pull request #3889 from matrix-org/rav/404_on_remove_unknown_alias
Browse files Browse the repository at this point in the history
Return a 404 when deleting unknown room alias
  • Loading branch information
richvdh authored Sep 18, 2018
2 parents ad95ec1 + f75b996 commit 1e09a1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/3889.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix 500 error when deleting unknown room alias
19 changes: 16 additions & 3 deletions synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
from twisted.internet import defer

from synapse.api.constants import EventTypes
from synapse.api.errors import AuthError, CodeMessageException, Codes, SynapseError
from synapse.api.errors import (
AuthError,
CodeMessageException,
Codes,
NotFoundError,
StoreError,
SynapseError,
)
from synapse.types import RoomAlias, UserID, get_domain_from_id

from ._base import BaseHandler
Expand Down Expand Up @@ -109,7 +116,13 @@ def create_appservice_association(self, service, room_alias, room_id,
def delete_association(self, requester, user_id, room_alias):
# association deletion for human users

can_delete = yield self._user_can_delete_alias(room_alias, user_id)
try:
can_delete = yield self._user_can_delete_alias(room_alias, user_id)
except StoreError as e:
if e.code == 404:
raise NotFoundError("Unknown room alias")
raise

if not can_delete:
raise AuthError(
403, "You don't have permission to delete the alias.",
Expand Down Expand Up @@ -320,7 +333,7 @@ def can_modify_alias(self, alias, user_id=None):
def _user_can_delete_alias(self, alias, user_id):
creator = yield self.store.get_room_alias_creator(alias.to_string())

if creator and creator == user_id:
if creator is not None and creator == user_id:
defer.returnValue(True)

is_admin = yield self.auth.is_server_admin(UserID.from_string(user_id))
Expand Down
1 change: 0 additions & 1 deletion synapse/storage/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def get_room_alias_creator(self, room_alias):
},
retcol="creator",
desc="get_room_alias_creator",
allow_none=True
)

@cached(max_entries=5000)
Expand Down

0 comments on commit 1e09a1d

Please sign in to comment.