From 1497e100795cc2b7d00ce3946bfa5cba69890fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 03:50:59 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(settings):=20the=20admin=20set?= =?UTF-8?q?s=20the=20address=20mail=20links=20point=20at?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A box behind a proxy answers on localhost and is reached on a public name, so every mailed link carried the wrong origin. The outgoing mail panel now takes a link address, stored on the workspace and used by both the sign-in mail and every rule mail; empty falls back to config/izlek.toml's base_url, which the field shows as its placeholder. A trailing slash is trimmed and anything that is not an http:// or https:// origin is refused. Also fits the sheet viewer inside its panel: the viewer body is a row flex, so without a min-width the sheet's automatic minimum size was the whole table's width and a wide book pushed the panel off the screen instead of panning inside it. --- .../izlek-core/migrations/0002_public_url.sql | 6 ++ crates/izlek-core/src/accounts.rs | 21 +++++- crates/izlek-core/src/mail.rs | 10 ++- crates/izlek-core/src/store/mod.rs | 9 +++ crates/izlek-core/src/store/turso_store.rs | 16 ++++- crates/izlek-core/tests/store.rs | 49 ++++++++++++- crates/izlek-web/src/i18n.rs | 6 ++ crates/izlek-web/src/settings.rs | 59 ++++++++++++++- crates/izlek-web/tests/http.rs | 71 +++++++++++++++++++ style/main.scss | 5 ++ 10 files changed, 245 insertions(+), 7 deletions(-) create mode 100644 crates/izlek-core/migrations/0002_public_url.sql diff --git a/crates/izlek-core/migrations/0002_public_url.sql b/crates/izlek-core/migrations/0002_public_url.sql new file mode 100644 index 0000000..c8a9398 --- /dev/null +++ b/crates/izlek-core/migrations/0002_public_url.sql @@ -0,0 +1,6 @@ +-- The address mail points at, when it is not the one the process was +-- configured with. A box behind a proxy answers on localhost and is reached +-- on a public name, and only an admin knows which — so this is workspace +-- content, edited in Settings, and `config/izlek.toml`'s `base_url` is what +-- it falls back to. +ALTER TABLE workspace ADD COLUMN public_url TEXT; diff --git a/crates/izlek-core/src/accounts.rs b/crates/izlek-core/src/accounts.rs index 05d5e1c..b37e5b7 100644 --- a/crates/izlek-core/src/accounts.rs +++ b/crates/izlek-core/src/accounts.rs @@ -195,6 +195,25 @@ impl Accounts { Ok(()) } + /// The address the process was configured with — what a link falls back + /// to when no admin has set one. + pub fn configured_url(&self) -> &str { + &self.base_url + } + + /// The origin a mailed link points at: the address an admin set in + /// Settings, or the one the process was configured with. A box behind a + /// proxy answers on localhost and is reached on a public name, and only + /// the admin knows which — so the stored one wins whenever it is there. + async fn base(&self) -> Result { + Ok(self + .store + .workspace() + .await? + .and_then(|workspace| workspace.public_url) + .unwrap_or_else(|| self.base_url.clone())) + } + async fn mint_link(&self, actor: &User, user: &User) -> Result { let token = Token::mint(); let expires_at = OffsetDateTime::now_utc() + SIGNIN_LINK_LIFETIME; @@ -205,7 +224,7 @@ impl Accounts { let body = format!( "{actor} added you to Izlek.\n\n{base}/join/{token}\n\nThe link works once and expires in 7 days.\n", actor = actor.display_name, - base = self.base_url, + base = self.base().await?, token = token.expose(), ); self.store diff --git a/crates/izlek-core/src/mail.rs b/crates/izlek-core/src/mail.rs index 3a18fab..5f91302 100644 --- a/crates/izlek-core/src/mail.rs +++ b/crates/izlek-core/src/mail.rs @@ -719,12 +719,20 @@ impl Engine { | ActivityKind::Other(_) => format!("{} touched it.", actor), }, }; + // The address an admin set in Settings wins over the configured one: + // a box behind a proxy answers on localhost and is reached on a + // public name, and a mail nobody can click is a mail not sent. + let base = self + .store + .workspace() + .await? + .and_then(|workspace| workspace.public_url) + .unwrap_or_else(|| self.base_url.clone()); let mut body = format!( "{key} — {title}\n\n{happened}\n\n{when}\n\n{base}/?task={id}\n", key = facts.row.task_key, title = facts.row.title, when = day_and_time(event.at()), - base = self.base_url, id = facts.row.id, ); if rule.include_task_details { diff --git a/crates/izlek-core/src/store/mod.rs b/crates/izlek-core/src/store/mod.rs index db82786..a70e0ec 100644 --- a/crates/izlek-core/src/store/mod.rs +++ b/crates/izlek-core/src/store/mod.rs @@ -71,6 +71,11 @@ pub struct Workspace { pub attachment_limit_bytes: u64, pub photo_limit_bytes: u64, pub allowed_file_types: Vec, + /// The origin mail links point at, when an admin has set one. `None` + /// means the address the process was configured with — a box behind a + /// proxy answers on localhost and is reached on a public name, and only + /// an admin knows which. + pub public_url: Option, } /// One file hung off a task, as a screen lists it: a name, a type, a size and @@ -618,6 +623,10 @@ pub trait Store: BoardReads + DetailReads + 'static { /// returns reaches a response body. async fn smtp_password(&self, workspace_id: &str) -> Result>; + /// Writes the address mail links point at. `None` clears it, and the + /// configured `base_url` is what a cleared one falls back to. + async fn set_public_url(&self, workspace_id: &str, public_url: Option<&str>) -> Result<()>; + async fn set_limits( &self, workspace_id: &str, diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index 24af5cb..bf266fa 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -33,6 +33,7 @@ use time::macros::format_description; /// Every migration, in order. Adding one means appending a file and a line. const MIGRATIONS: &[(i64, &str)] = &[ (1, include_str!("../../migrations/0001_init.sql")), + (2, include_str!("../../migrations/0002_public_url.sql")), ]; /// The board a fresh workspace gets, and its columns. `Done` is the column @@ -562,6 +563,7 @@ fn workspace_from(row: &Row) -> Result { }), None => None, }, + public_url: opt_text(row, 15)?, }) } @@ -572,7 +574,7 @@ const WORKSPACE_COLUMNS: &str = "id, name, created_at, attachment_limit_bytes, \ allowed_file_types, photo_limit_bytes, smtp_host, smtp_port, smtp_username, \ smtp_from_name, smtp_from_address, \ (smtp_password IS NOT NULL AND smtp_password <> ''), \ - smtp_test_at, smtp_test_ms, smtp_test_error"; + smtp_test_at, smtp_test_ms, smtp_test_error, public_url"; fn user_from(row: &Row) -> Result { Ok(User { @@ -820,6 +822,18 @@ impl Store for TursoStore { Ok(sealed.as_deref().and_then(|s| secret::open(&self.key, s))) } + async fn set_public_url(&self, workspace_id: &str, public_url: Option<&str>) -> Result<()> { + let conn = self.conn.lock().await; + conn + .execute( + "UPDATE workspace SET public_url = ?1 WHERE id = ?2", + params![public_url, workspace_id], + ) + .await + .map_err(backend)?; + Ok(()) + } + async fn set_limits( &self, workspace_id: &str, diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index 97f3525..60590c2 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -101,14 +101,14 @@ async fn migrations_apply_once_and_survive_reopen() { let path = dir.join("izlek.db").to_string_lossy().into_owned(); let first = TursoStore::open(&path).await.unwrap(); - assert_eq!(first.schema_version().await.unwrap(), 1); + assert_eq!(first.schema_version().await.unwrap(), 2); claim(&first).await; drop(first); // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and // must not lose what the first open wrote. let second = TursoStore::open(&path).await.unwrap(); - assert_eq!(second.schema_version().await.unwrap(), 1); + assert_eq!(second.schema_version().await.unwrap(), 2); assert_eq!(second.workspace().await.unwrap().unwrap().name, "Izlek"); drop(second); let _ = std::fs::remove_dir_all(&dir); @@ -5654,3 +5654,48 @@ async fn an_every_column_rule_survives_the_round_trip() { let _ = admin; let _ = std::fs::remove_dir_all(&dir); } + +/// A box behind a proxy answers on one address and is reached on another, so +/// an admin can set the origin mail links point at. What is stored wins over +/// what the process was configured with. +#[tokio::test] +async fn a_stored_address_is_the_one_mail_links_point_at() { + let (dir, store, workspace, admin) = shared().await; + let mate = member(&store, &workspace, "emre@izlek.sh", "Emre").await; + let task = add_task(&store, &workspace, "Backlog", "Ship it", None, &admin).await; + store.assign_task(&task, &mate).await.unwrap(); + a_rule(&store, &workspace, "Done", "Task completed").await; + store + .set_public_url(&workspace, Some("https://board.example")) + .await + .unwrap(); + + let mailer = Remembering::taking_everything(); + let engine = Engine::new(store.clone(), mailer.clone(), "http://127.0.0.1:3000"); + let moved = moved_to(&store, &workspace, &task, "Backlog", "Done", &admin).await; + engine.on_transition(&moved).await.unwrap(); + + let sent = mailer.sent(); + assert!( + sent[0].body.contains("https://board.example/?task="), + "the mail did not use the stored address: {}", + sent[0].body + ); + + // Cleared, the configured address is what is left. + store.set_public_url(&workspace, None).await.unwrap(); + let back = add_task(&store, &workspace, "Backlog", "Ship it too", None, &admin).await; + store.assign_task(&back, &mate).await.unwrap(); + let moved = moved_to(&store, &workspace, &back, "Backlog", "Done", &admin).await; + engine.on_transition(&moved).await.unwrap(); + let sent = mailer.sent(); + assert!( + sent.last() + .unwrap() + .body + .contains("http://127.0.0.1:3000/?task="), + "a cleared address did not fall back: {}", + sent.last().unwrap().body + ); + let _ = std::fs::remove_dir_all(&dir); +} diff --git a/crates/izlek-web/src/i18n.rs b/crates/izlek-web/src/i18n.rs index 43a5496..e71a28b 100644 --- a/crates/izlek-web/src/i18n.rs +++ b/crates/izlek-web/src/i18n.rs @@ -161,6 +161,8 @@ pub enum Key { SmtpUsernameRequired, PasswordNeededFirstTime, NotFromAddress, + NotAnOrigin, + LinkAddressLabel, SenderNotConfiguredYet, // pages.rs @@ -598,6 +600,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (PasswordNeededFirstTime, Tr) => "İlk seferde bir parola gerekir.", (NotFromAddress, En) => "That is not a from-address.", (NotFromAddress, Tr) => "Bu bir gönderen adresi değil.", + (NotAnOrigin, En) => "Not an http:// or https:// address.", + (NotAnOrigin, Tr) => "http:// veya https:// adresi değil.", + (LinkAddressLabel, En) => "Link address", + (LinkAddressLabel, Tr) => "Bağlantı adresi", (SenderNotConfiguredYet, En) => "No sender to test.", (SenderNotConfiguredYet, Tr) => "Test edilecek gönderen yok.", diff --git a/crates/izlek-web/src/settings.rs b/crates/izlek-web/src/settings.rs index d629fe3..96a9a1b 100644 --- a/crates/izlek-web/src/settings.rs +++ b/crates/izlek-web/src/settings.rs @@ -342,6 +342,10 @@ struct SaveSenderForm { password: String, from_name: String, from_address: String, + /// The origin mailed links point at. Empty falls back to the address the + /// process was configured with. + #[serde(default)] + public_url: String, } /// Writes the workspace's sender. Admin-only, checked here. @@ -370,6 +374,9 @@ async fn save_sender( let username = input.username.trim().to_string(); let from_name = input.from_name.trim().to_string(); let from_address = input.from_address.trim().to_string(); + // Trailing slashes go: every link built from this appends its own path, + // and `https://izlek.sh//?task=X` is a link that works by luck. + let public_url = input.public_url.trim().trim_end_matches('/').to_string(); // Not typed is not the same as blanked. Nothing here can clear a stored // password; replacing it means typing a new one. let password = (!input.password.is_empty()).then_some(input.password); @@ -393,6 +400,8 @@ async fn save_sender( Some(Key::PasswordNeededFirstTime) } else if !is_address(&from_address) { Some(Key::NotFromAddress) + } else if !public_url.is_empty() && !is_origin(&public_url) { + Some(Key::NotAnOrigin) } else { None }; @@ -403,7 +412,7 @@ async fn save_sender( )); } - let outcome = store + let outcome = match store .set_sender( &admin.workspace_id, NewSender { @@ -415,7 +424,18 @@ async fn save_sender( from_address, }, ) - .await; + .await + { + Ok(()) => { + store + .set_public_url( + &admin.workspace_id, + (!public_url.is_empty()).then_some(public_url.as_str()), + ) + .await + } + Err(problem) => Err(problem), + }; let refusal = match outcome { Ok(()) => { let _ = store @@ -855,6 +875,9 @@ struct Sender { from_address: String, password_set: bool, test: Option, + /// The origin mailed links point at, empty when the configured one is + /// still in use. + public_url: String, } impl Sender { @@ -877,6 +900,7 @@ async fn sender_now(cx: &Cx, zone: time::UtcOffset) -> Result { from_address: String::new(), password_set: false, test: None, + public_url: String::new(), }, Some(workspace) => Sender { host: workspace.smtp_host.unwrap_or_default(), @@ -893,10 +917,28 @@ async fn sender_now(cx: &Cx, zone: time::UtcOffset) -> Result { took: test.error.is_none().then(|| took_label(test.took_ms)), error: test.error, }), + public_url: workspace.public_url.unwrap_or_default(), }, }) } +/// Whether a typed address is an origin a link can be built on: an http or +/// https scheme, a host after it, and no whitespace anywhere. A path is +/// allowed — Izlek behind `example.com/izlek` is a real deployment — but a +/// bare host or a mail address is not. +fn is_origin(value: &str) -> bool { + let Some(rest) = value + .strip_prefix("https://") + .or_else(|| value.strip_prefix("http://")) + else { + return false; + }; + let host = rest.split('/').next().unwrap_or_default(); + !host.is_empty() + && !host.contains('@') + && !value.chars().any(char::is_whitespace) +} + /// The refusal that landed on this call's redirect, if any, and this call's /// own `saved=` flag. fn call_state<'q>(query: &'q str, call: &str) -> (Option, bool) { @@ -989,6 +1031,9 @@ async fn settings_page(cx: &Cx) -> Result { }; let zone = izlek_core::detail::parse_zone(&user.timezone); + // What a link falls back to when the field is empty — the placeholder + // shows it rather than an invented example. + let configured_url = accounts(cx).configured_url().to_string(); let sender = if administers { Some(sender_now(cx, zone).await?) } else { @@ -1227,6 +1272,16 @@ async fn settings_page(cx: &Cx) -> Result { > +
diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index 4d7e2a2..65c8116 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -6423,3 +6423,74 @@ async fn the_queue_says_when_the_next_try_fires() { logs.body ); } + +/// An admin can set the address mail links point at — the box answers on +/// localhost and is reached through a proxy on a public name. A trailing +/// slash is trimmed, something that is not an origin is refused, and an empty +/// field puts the configured address back. +#[tokio::test] +async fn an_admin_sets_the_address_mail_links_point_at() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + + async fn sender_with(app: &App, admin: &str, public_url: &str) -> Answer { + app.post( + "/api/save_sender", + Some(admin), + &[ + ("host", "smtp.fastmail.com"), + ("port", "465"), + ("username", "izlek"), + ("password", SENDER_PASSWORD), + ("from_name", "Izlek"), + ("from_address", "izlek@izlek.sh"), + ("public_url", public_url), + ], + ) + .await + } + + let answer = sender_with(&app, &admin_cookie, "https://board.example/").await; + assert!( + answer + .location + .as_deref() + .is_some_and(|location| !location.contains("refusal=")), + "the address was refused: {:?}", + answer.location + ); + assert_eq!( + app.store.workspace().await.unwrap().unwrap().public_url, + Some("https://board.example".to_string()), + "the trailing slash was kept" + ); + + // The field shows what is stored, so a reload does not blank it. + let page = app + .get("/settings?section=outgoing", Some(&admin_cookie)) + .await; + let html = String::from_utf8_lossy(&page.bytes); + assert!(html.contains("https://board.example"), "{html}"); + + let refused = sender_with(&app, &admin_cookie, "board.example").await; + assert!( + refused + .location + .as_deref() + .is_some_and(|location| location.contains("refusal=")), + "a bare host was taken as an origin: {:?}", + refused.location + ); + assert_eq!( + app.store.workspace().await.unwrap().unwrap().public_url, + Some("https://board.example".to_string()), + "the refused save wrote anyway" + ); + + sender_with(&app, &admin_cookie, "").await; + assert_eq!( + app.store.workspace().await.unwrap().unwrap().public_url, + None, + "an empty field did not clear the stored address" + ); +} diff --git a/style/main.scss b/style/main.scss index 6c3f469..ceeee6a 100644 --- a/style/main.scss +++ b/style/main.scss @@ -1237,6 +1237,10 @@ img.avatar { flex-direction: column; gap: 10px; width: min(86vw, 900px); + // The viewer body is a row flex, so without this the sheet's automatic + // minimum size is the whole table's width and a wide book pushes the panel + // off the screen instead of panning inside it. + min-width: 0; } .sheet-tabs { @@ -1265,6 +1269,7 @@ img.avatar { .sheet-grid { max-height: 70vh; + min-width: 0; overflow: auto; scrollbar-width: none; border: 1px solid var(--border);