From eddc6d8855b0aa50fe85f85d40bd3ffc24678238 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 5 Sep 2019 16:25:22 +0100 Subject: Forbid changing the name, avatar or topic of a direct room --- synapse/third_party_rules/access_rules.py | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'synapse') diff --git a/synapse/third_party_rules/access_rules.py b/synapse/third_party_rules/access_rules.py index 1a295ea7ce..41862f6d0b 100644 --- a/synapse/third_party_rules/access_rules.py +++ b/synapse/third_party_rules/access_rules.py @@ -237,6 +237,15 @@ class RoomAccessRules(object): if event.type == EventTypes.JoinRules: return self._on_join_rule_change(event, rule) + if event.type == EventTypes.RoomAvatar: + return self._on_room_avatar_change(event, rule) + + if event.type == EventTypes.Name: + return self._on_room_name_change(event, rule) + + if event.type == EventTypes.Topic: + return self._on_room_topic_change(event, rule) + return True def _on_rules_change(self, event, state_events): @@ -461,6 +470,47 @@ class RoomAccessRules(object): return True + def _on_room_avatar_change(self, event, rule): + """Check whether a change of room avatar is allowed. + The current rule is to forbid such a change in direct chats but allow it + everywhere else. + + Args: + event (synapse.events.EventBase): The event to check. + rule (str): The name of the rule to apply. + Returns: + bool, True if the event can be allowed, False otherwise. + """ + return rule != ACCESS_RULE_DIRECT + + + def _on_room_name_change(self, event, rule): + """Check whether a change of room name is allowed. + The current rule is to forbid such a change in direct chats but allow it + everywhere else. + + Args: + event (synapse.events.EventBase): The event to check. + rule (str): The name of the rule to apply. + Returns: + bool, True if the event can be allowed, False otherwise. + """ + return rule != ACCESS_RULE_DIRECT + + + def _on_room_topic_change(self, event, rule): + """Check whether a change of room topic is allowed. + The current rule is to forbid such a change in direct chats but allow it + everywhere else. + + Args: + event (synapse.events.EventBase): The event to check. + rule (str): The name of the rule to apply. + Returns: + bool, True if the event can be allowed, False otherwise. + """ + return rule != ACCESS_RULE_DIRECT + @staticmethod def _get_rule_from_state(state_events): """Extract the rule to be applied from the given set of state events. -- cgit 1.5.1 From d1d464388acff70b75b61bd1ec6b9d33999c5924 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 5 Sep 2019 16:35:13 +0100 Subject: Lint --- synapse/third_party_rules/access_rules.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'synapse') diff --git a/synapse/third_party_rules/access_rules.py b/synapse/third_party_rules/access_rules.py index 41862f6d0b..f564c0484c 100644 --- a/synapse/third_party_rules/access_rules.py +++ b/synapse/third_party_rules/access_rules.py @@ -483,7 +483,6 @@ class RoomAccessRules(object): """ return rule != ACCESS_RULE_DIRECT - def _on_room_name_change(self, event, rule): """Check whether a change of room name is allowed. The current rule is to forbid such a change in direct chats but allow it @@ -497,7 +496,6 @@ class RoomAccessRules(object): """ return rule != ACCESS_RULE_DIRECT - def _on_room_topic_change(self, event, rule): """Check whether a change of room topic is allowed. The current rule is to forbid such a change in direct chats but allow it -- cgit 1.5.1