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

Commit 56e00ca

Browse files
authored
Send the location of the web client to the IS when inviting via 3PIDs. (#8930)
Adds a new setting `email.invite_client_location` which, if defined, is passed to the identity server during invites.
1 parent d781a81 commit 56e00ca

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

changelog.d/8930.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an `email.invite_client_location` configuration option to send a web client location to the invite endpoint on the identity server which allows customisation of the email template.

docs/sample_config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,12 @@ email:
21492149
#
21502150
#validation_token_lifetime: 15m
21512151

2152+
# The web client location to direct users to during an invite. This is passed
2153+
# to the identity server as the org.matrix.web_client_location key. Defaults
2154+
# to unset, giving no guidance to the identity server.
2155+
#
2156+
#invite_client_location: https://app.element.io
2157+
21522158
# Directory in which Synapse will try to find the template files below.
21532159
# If not set, or the files named below are not found within the template
21542160
# directory, default templates from within the Synapse package will be used.

synapse/config/emailconfig.py

+22
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,22 @@ def read_config(self, config, **kwargs):
322322

323323
self.email_subjects = EmailSubjectConfig(**subjects)
324324

325+
# The invite client location should be a HTTP(S) URL or None.
326+
self.invite_client_location = email_config.get("invite_client_location") or None
327+
if self.invite_client_location:
328+
if not isinstance(self.invite_client_location, str):
329+
raise ConfigError(
330+
"Config option email.invite_client_location must be type str"
331+
)
332+
if not (
333+
self.invite_client_location.startswith("http://")
334+
or self.invite_client_location.startswith("https://")
335+
):
336+
raise ConfigError(
337+
"Config option email.invite_client_location must be a http or https URL",
338+
path=("email", "invite_client_location"),
339+
)
340+
325341
def generate_config_section(self, config_dir_path, server_name, **kwargs):
326342
return (
327343
"""\
@@ -389,6 +405,12 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
389405
#
390406
#validation_token_lifetime: 15m
391407
408+
# The web client location to direct users to during an invite. This is passed
409+
# to the identity server as the org.matrix.web_client_location key. Defaults
410+
# to unset, giving no guidance to the identity server.
411+
#
412+
#invite_client_location: https://app.element.io
413+
392414
# Directory in which Synapse will try to find the template files below.
393415
# If not set, or the files named below are not found within the template
394416
# directory, default templates from within the Synapse package will be used.

synapse/handlers/identity.py

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def __init__(self, hs):
5555
self.federation_http_client = hs.get_federation_http_client()
5656
self.hs = hs
5757

58+
self._web_client_location = hs.config.invite_client_location
59+
5860
async def threepid_from_creds(
5961
self, id_server: str, creds: Dict[str, str]
6062
) -> Optional[JsonDict]:
@@ -803,6 +805,9 @@ async def ask_id_server_for_third_party_invite(
803805
"sender_display_name": inviter_display_name,
804806
"sender_avatar_url": inviter_avatar_url,
805807
}
808+
# If a custom web client location is available, include it in the request.
809+
if self._web_client_location:
810+
invite_config["org.matrix.web_client_location"] = self._web_client_location
806811

807812
# Add the identity service access token to the JSON body and use the v2
808813
# Identity Service endpoints if id_access_token is present

0 commit comments

Comments
 (0)