Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Closed
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
14 changes: 12 additions & 2 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def register_user(
threepid=None,
user_type=None,
default_display_name=None,
require_consent=True,
address=None,
bind_emails=[],
):
Expand All @@ -167,6 +168,7 @@ def register_user(
will be set to this. Defaults to 'localpart'.
address (str|None): the IP address used to perform the registration.
bind_emails (List[str]): list of emails to bind to this account.
require_consent (bool): Should the user be required to give consent.
Returns:
Deferred[str]: user_id
Raises:
Expand Down Expand Up @@ -211,6 +213,7 @@ def register_user(
admin=admin,
user_type=user_type,
address=address,
require_consent=require_consent,
)

if self.hs.config.user_directory_search_all_users:
Expand Down Expand Up @@ -244,7 +247,7 @@ def register_user(
user_id = None
attempts += 1

if not self.hs.config.user_consent_at_registration:
if not self.hs.config.user_consent_at_registration and require_consent:
yield self._auto_join_rooms(user_id)
else:
logger.info(
Expand Down Expand Up @@ -525,6 +528,7 @@ def _join_user_to_room(self, requester, room_identifier):
ratelimit=False,
)

@defer.inlineCallbacks
def register_with_store(
self,
user_id,
Expand All @@ -536,6 +540,7 @@ def register_with_store(
admin=False,
user_type=None,
address=None,
require_consent=True,
):
"""Register user in the datastore.

Expand All @@ -553,7 +558,7 @@ def register_with_store(
user_type (str|None): type of user. One of the values from
api.constants.UserTypes, or None for a normal user.
address (str|None): the IP address used to perform the registration.

require_consent (bool): Should the user be required to give consent.
Returns:
Deferred
"""
Expand Down Expand Up @@ -584,8 +589,12 @@ def register_with_store(
admin=admin,
user_type=user_type,
address=address,
require_consent=require_consent,
)
else:
if require_consent is False:
yield self.store.user_set_consent_version(user_id, "no-consent-required")

return self.store.register_user(
user_id=user_id,
password_hash=password_hash,
Expand All @@ -597,6 +606,7 @@ def register_with_store(
user_type=user_type,
)


@defer.inlineCallbacks
def register_device(self, user_id, device_id, initial_display_name, is_guest=False):
"""Register a device for a user and generate an access token.
Expand Down
2 changes: 2 additions & 0 deletions synapse/replication/http/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def _serialize_payload(
"admin": admin,
"user_type": user_type,
"address": address,
"require_consent": require_consent,
}

@defer.inlineCallbacks
Expand All @@ -88,6 +89,7 @@ def _handle_request(self, request, user_id):
admin=content["admin"],
user_type=content["user_type"],
address=content["address"],
require_consent=content["require_consent"],
)

return (200, {})
Expand Down
5 changes: 4 additions & 1 deletion synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ def _do_shared_secret_registration(self, username, password, body):
# downcased one in `username` for the mac calculation
user = body["username"].encode("utf-8")

# do not require consent for this user (for example, bots)
require_consent = body.get("require_consent", True)

# str() because otherwise hmac complains that 'unicode' does not
# have the buffer interface
got_mac = str(body["mac"])
Expand All @@ -542,7 +545,7 @@ def _do_shared_secret_registration(self, username, password, body):
raise SynapseError(403, "HMAC incorrect")

user_id = yield self.registration_handler.register_user(
localpart=username, password=password
localpart=username, password=password, require_consent=require_consent,
)

result = yield self._create_registration_details(user_id, body)
Expand Down
4 changes: 4 additions & 0 deletions synapse/server_notices/consent_server_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def maybe_send_server_notice_to_user(self, user_id):
try:
u = yield self._store.get_user_by_id(user_id)

if u["consent_version"] == "no-consent-required":
# user is exempt
return

if u["is_guest"] and not self._send_to_guests:
# don't send to guests
return
Expand Down