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

Add an option to disable autojoin for guest accounts #6637

Merged
merged 9 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6637.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add an option to disable autojoining rooms for guest accounts.
7 changes: 7 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,13 @@ account_threepid_delegates:
#
#autocreate_auto_join_rooms: true

# When auto_join_rooms is specified, setting this flag to false prevents
# guest accounts from being automatically joined to the rooms.
#
# Defaults to true.
#
#auto_join_rooms_for_guests: false


## Metrics ###

Expand Down
8 changes: 8 additions & 0 deletions synapse/config/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def read_config(self, config, **kwargs):
if not RoomAlias.is_valid(room_alias):
raise ConfigError("Invalid auto_join_rooms entry %s" % (room_alias,))
self.autocreate_auto_join_rooms = config.get("autocreate_auto_join_rooms", True)
self.auto_join_rooms_for_guests = config.get("auto_join_rooms_for_guests", True)

self.enable_set_displayname = config.get("enable_set_displayname", True)
self.enable_set_avatar_url = config.get("enable_set_avatar_url", True)
Expand Down Expand Up @@ -368,6 +369,13 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
# users cannot be auto-joined since they do not exist.
#
#autocreate_auto_join_rooms: true

# When auto_join_rooms is specified, setting this flag to false prevents
# guest accounts from being automatically joined to the rooms.
#
# Defaults to true.
#
#auto_join_rooms_for_guests: false
"""
% locals()
)
Expand Down
8 changes: 7 additions & 1 deletion synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ def register_user(
fail_count += 1

if not self.hs.config.user_consent_at_registration:
yield defer.ensureDeferred(self._auto_join_rooms(user_id))
if not self.hs.config.auto_join_rooms_for_guests and make_guest:
logger.info(
"Skipping auto-join for %s because auto-join for guests is disabled",
user_id,
)
else:
yield defer.ensureDeferred(self._auto_join_rooms(user_id))
else:
logger.info(
"Skipping auto-join for %s because consent is required at registration",
Expand Down
10 changes: 10 additions & 0 deletions tests/handlers/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ def test_register_mau_blocked(self):
self.handler.register_user(localpart="local_part"), ResourceLimitError
)

def test_auto_join_rooms_for_guests(self):
room_alias_str = "#room:test"
self.hs.config.auto_join_rooms = [room_alias_str]
self.hs.config.auto_join_rooms_for_guests = False
user_id = self.get_success(
self.handler.register_user(localpart="jeff", make_guest=True),
)
rooms = self.get_success(self.store.get_rooms_for_user(user_id))
self.assertEqual(len(rooms), 0)

def test_auto_create_auto_join_rooms(self):
room_alias_str = "#room:test"
self.hs.config.auto_join_rooms = [room_alias_str]
Expand Down