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 7 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.
5 changes: 5 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,11 @@ 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. Default
# true when auto_join_rooms is specified.
#auto_join_rooms_for_guests: false


## Metrics ###

Expand Down
7 changes: 7 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,12 @@ 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 when auto_join_rooms is specified.
turt2live marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does whether auto_join_rooms is set matter to the default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't do anything otherwise, similar to the auto create room setting above it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok; I think it would be clearer just to omit the "when..." clause then.

#
#auto_join_rooms_for_guests: false
richvdh marked this conversation as resolved.
Show resolved Hide resolved
"""
% 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
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def default_config(name, parse=False):
"media_storage_providers": [],
"autocreate_auto_join_rooms": True,
"auto_join_rooms": [],
"auto_join_rooms_for_guest": True,
richvdh marked this conversation as resolved.
Show resolved Hide resolved
"limit_usage_by_mau": False,
"hs_disabled": False,
"hs_disabled_message": "",
Expand Down