From 726f13ee79f52dbe153300c406eba67a82cb5f5c Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Wed, 3 Nov 2021 17:24:29 +0100 Subject: [PATCH] Delete custom user_may_create_room Because we already do these checks with RoomAccessRules --- synapse/rulecheck/domain_rule_checker.py | 21 +------------- tests/rulecheck/test_domainrulecheck.py | 37 ------------------------ 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/synapse/rulecheck/domain_rule_checker.py b/synapse/rulecheck/domain_rule_checker.py index 96424505ed..da0d8aee30 100644 --- a/synapse/rulecheck/domain_rule_checker.py +++ b/synapse/rulecheck/domain_rule_checker.py @@ -14,7 +14,7 @@ # limitations under the License. import logging -from typing import Dict, Optional +from typing import Optional from synapse.api.constants import EventTypes, Membership from synapse.config._base import ConfigError @@ -84,7 +84,6 @@ class DomainRuleChecker(object): self._api.register_spam_checker_callbacks( user_may_invite=self.user_may_invite, user_may_send_3pid_invite=self.user_may_send_3pid_invite, - user_may_create_room=self.user_may_create_room, user_may_join_room=self.user_may_join_room, ) @@ -198,24 +197,6 @@ class DomainRuleChecker(object): return invitee_domain in self.domain_mapping[inviter_domain] - async def user_may_create_room( - self, userid, invite_list, third_party_invite_list, cloning - ): - """Implements synapse.events.SpamChecker.user_may_create_room""" - - if cloning: - return True - - if not self.can_invite_by_third_party_id and third_party_invite_list: - return False - - number_of_invites = len(invite_list) + len(third_party_invite_list) - - if self.can_only_create_one_to_one_rooms and number_of_invites != 1: - return False - - return True - async def user_may_join_room(self, userid, room_id, is_invited): """Implements the user_may_join_room spam checker callback.""" if self.can_only_join_rooms_with_invite and not is_invited: diff --git a/tests/rulecheck/test_domainrulecheck.py b/tests/rulecheck/test_domainrulecheck.py index b66fffc4aa..ba4be81350 100644 --- a/tests/rulecheck/test_domainrulecheck.py +++ b/tests/rulecheck/test_domainrulecheck.py @@ -272,43 +272,6 @@ class DomainRuleCheckerRoomTestCase(unittest.HomeserverTestCase): channel = self._create_room(self.admin_access_token) assert channel.result["code"] == b"200", channel.result - def test_normal_user_cannot_create_empty_room(self): - channel = self._create_room(self.normal_access_token) - assert channel.result["code"] == b"403", channel.result - - def test_normal_user_cannot_create_room_with_multiple_invites(self): - channel = self._create_room( - self.normal_access_token, - content={"invite": [self.other_user_id, self.admin_user_id]}, - ) - assert channel.result["code"] == b"403", channel.result - - # Test that it correctly counts both normal and third party invites - channel = self._create_room( - self.normal_access_token, - content={ - "invite": [self.other_user_id], - "invite_3pid": [{"medium": "email", "address": "foo@example.com"}], - }, - ) - assert channel.result["code"] == b"403", channel.result - - # Test that it correctly rejects third party invites - channel = self._create_room( - self.normal_access_token, - content={ - "invite": [], - "invite_3pid": [{"medium": "email", "address": "foo@example.com"}], - }, - ) - assert channel.result["code"] == b"403", channel.result - - def test_normal_user_can_room_with_single_invites(self): - channel = self._create_room( - self.normal_access_token, content={"invite": [self.other_user_id]} - ) - assert channel.result["code"] == b"200", channel.result - def test_cannot_join_public_room(self): channel = self._create_room(self.admin_access_token) assert channel.result["code"] == b"200", channel.result