1
0

Delete custom user_may_create_room

Because we already do these checks with RoomAccessRules
This commit is contained in:
Brendan Abolivier
2021-11-03 17:24:29 +01:00
parent 58d6cdd10d
commit 726f13ee79
2 changed files with 1 additions and 57 deletions

View File

@@ -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:

View File

@@ -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