Repository navigation
Open the invite's room after registering #6025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50b818b
Add a `guest_invites` config section
devonh 234c0bc
Add an `OpenRoom` post-auth action
devonh 46b97d9
Rename the `guest_invites` config section to `room_invites`
devonh 427f639
Store the room an invite opens on its registration token
devonh 4c5f171
Name the invite's token, not its room, in the post-auth action
devonh f231f48
Open the invite's room from its token when registering
devonh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -535,6 +535,7 @@ impl Options { | |
| username, | ||
| email, | ||
| passwordless, | ||
| None, | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright 2026 Element Creations Ltd. | ||
| // | ||
| // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
| // Please see LICENSE files in the repository root for full details. | ||
|
|
||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize, de::Error}; | ||
| use url::Url; | ||
|
|
||
| use crate::ConfigurationSection; | ||
|
|
||
| /// Configuration section for inviting email addresses to rooms | ||
| #[derive(Clone, Debug, Default, Deserialize, JsonSchema, Serialize)] | ||
| pub struct RoomInvitesConfig { | ||
| /// The client URL to send invitees to once they are signed in, with | ||
| /// `{room_id}` standing for the room ID, e.g. | ||
| /// `https://app.element.io/#/room/{room_id}`. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub client_room_url: Option<String>, | ||
| } | ||
|
|
||
| impl RoomInvitesConfig { | ||
| /// Returns true if the configuration is the default one | ||
| pub(crate) fn is_default(&self) -> bool { | ||
| self.client_room_url.is_none() | ||
| } | ||
| } | ||
|
|
||
| impl ConfigurationSection for RoomInvitesConfig { | ||
| const PATH: Option<&'static str> = Some("room_invites"); | ||
|
|
||
| fn validate( | ||
| &self, | ||
| figment: &figment::Figment, | ||
| ) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { | ||
| let metadata = figment.find_metadata(Self::PATH.unwrap()); | ||
|
|
||
| let error = |message: &str| -> Box<dyn std::error::Error + Send + Sync + 'static> { | ||
| let mut error = figment::error::Error::custom(message); | ||
| error.metadata = metadata.cloned(); | ||
| error.profile = Some(figment::Profile::Default); | ||
| error.path = vec![Self::PATH.unwrap().to_owned(), "client_room_url".to_owned()]; | ||
| error.into() | ||
| }; | ||
|
|
||
| match &self.client_room_url { | ||
| Some(url) if !url.contains("{room_id}") => { | ||
| return Err(error("must contain `{room_id}`")); | ||
| } | ||
| Some(url) | ||
| if !Url::parse(&url.replace("{room_id}", "room")).is_ok_and(|url| { | ||
| matches!(url.scheme(), "http" | "https") && url.has_host() | ||
| }) => | ||
| { | ||
| return Err(error("must be an absolute HTTP or HTTPS URL")); | ||
| } | ||
| _ => {} | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| // The closures passed to `Jail::expect_with` return `figment::Error`, which is | ||
| // large, and we can't change figment's API. | ||
| #![expect(clippy::result_large_err)] | ||
|
|
||
| use figment::{ | ||
| Figment, Jail, | ||
| providers::{Format, Yaml}, | ||
| }; | ||
|
|
||
| use super::*; | ||
|
|
||
| fn load(jail: &mut Jail, yaml: &str) -> Result<RoomInvitesConfig, String> { | ||
| jail.create_file("config.yaml", yaml) | ||
| .map_err(|e| e.to_string())?; | ||
| let figment = Figment::new().merge(Yaml::file("config.yaml")); | ||
| RoomInvitesConfig::extract(&figment).map_err(|e| e.to_string()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn defaults() { | ||
| Jail::expect_with(|jail| { | ||
| let config = load(jail, "room_invites: {}").unwrap(); | ||
| assert_eq!(config.client_room_url, None); | ||
| assert!(config.is_default()); | ||
| Ok(()) | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn client_room_url_requires_room_id() { | ||
| Jail::expect_with(|jail| { | ||
| let error = load( | ||
| jail, | ||
| "room_invites: { client_room_url: 'https://app.example.com/' }", | ||
| ) | ||
| .unwrap_err(); | ||
| assert!(error.contains("{room_id}"), "{error}"); | ||
| Ok(()) | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn client_room_url_must_be_absolute() { | ||
| Jail::expect_with(|jail| { | ||
| for url in [ | ||
| "app.example.com/#/room/{room_id}", | ||
| "localhost:8080/#/room/{room_id}", | ||
| "ftp://app.example.com/#/room/{room_id}", | ||
| "https:/#/room/{room_id}", | ||
| ] { | ||
| let error = load( | ||
| jail, | ||
| &format!("room_invites: {{ client_room_url: '{url}' }}"), | ||
| ) | ||
| .unwrap_err(); | ||
| assert!( | ||
| error.contains("absolute HTTP or HTTPS URL"), | ||
| "{url}: {error}" | ||
| ); | ||
| } | ||
| Ok(()) | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // Copyright 2025, 2026 Element Creations Ltd. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should 2025 be here? |
||
| // Copyright 2024, 2025 New Vector Ltd. | ||
| // Copyright 2023, 2024 The Matrix.org Foundation C.I.C. | ||
| // | ||
|
|
@@ -127,4 +128,8 @@ pub struct SiteConfig { | |
| /// `verification_uri_complete` and whether `/link` accepts a `code` | ||
| /// query parameter to auto-fill the user code. | ||
| pub device_code_user_code_auto_fill_enabled: bool, | ||
|
|
||
| /// The client URL to send invitees to, with `{room_id}` standing for the | ||
| /// room ID. | ||
| pub room_invites_client_room_url: Option<String>, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,7 @@ pub async fn handler( | |
| params.username, | ||
| params.email, | ||
| params.passwordless, | ||
| None, | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,7 @@ mod tests { | |
| None, | ||
| None, | ||
| false, | ||
| None, | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should 2025 be here?