summary refs log tree commit diff
path: root/synapse/api/auth.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-09-14 18:04:36 +0100
committerErik Johnston <erik@matrix.org>2015-09-14 18:04:36 +0100
commit228465b0ecfc7d7137ac3acaf30050e234957b6a (patch)
tree1e273d754bc819fecfb877e19a15a08b4d1e231a /synapse/api/auth.py
parentOnly allow people to set the alias list for their own domain. (diff)
parentMerge pull request #265 from matrix-org/erikj/check_room_exists (diff)
downloadsynapse-github/erikj/check_alias.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/check_alias github/erikj/check_alias erikj/check_alias
Diffstat (limited to 'synapse/api/auth.py')
-rw-r--r--synapse/api/auth.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py

index 81012f99c1..bf004a44c6 100644 --- a/synapse/api/auth.py +++ b/synapse/api/auth.py
@@ -112,7 +112,7 @@ class Auth(object): self._check_power_levels(event, auth_events) if event.type == EventTypes.Redaction: - self._check_redaction(event, auth_events) + self.check_redaction(event, auth_events) logger.debug("Allowing! %s", event) except AuthError as e: @@ -567,16 +567,35 @@ class Auth(object): return True - def _check_redaction(self, event, auth_events): + def check_redaction(self, event, auth_events): + """Check whether the event sender is allowed to redact the target event. + + Returns: + True if the the sender is allowed to redact the target event if the + target event was created by them. + False if the sender is allowed to redact the target event with no + further checks. + + Raises: + AuthError if the event sender is definitely not allowed to redact + the target event. + """ user_level = self._get_user_power_level(event.user_id, auth_events) redact_level = self._get_named_level(auth_events, "redact", 50) - if user_level < redact_level: - raise AuthError( - 403, - "You don't have permission to redact events" - ) + if user_level > redact_level: + return False + + redacter_domain = EventID.from_string(event.event_id).domain + redactee_domain = EventID.from_string(event.redacts).domain + if redacter_domain == redactee_domain: + return True + + raise AuthError( + 403, + "You don't have permission to redact events" + ) def _check_power_levels(self, event, auth_events): user_list = event.content.get("users", {})