Sections page through a rail, the server address is the admin's
Browse files at this commit1e00f669067de7609e4e1d3bd56c2cc0fb4663abParent: 16e8c67- feat
- sections page through a rail, the server address is the admin's
7 changed files +655 -178
- crates/in-core/src/config.rs +24 -16
- crates/in-web/src/drive.rs +2 -2
- crates/in-web/src/i18n.rs +13 -0
- crates/in-web/src/server.rs +19 -0
- crates/in-web/src/settings.rs +265 -137
- crates/in-web/src/share.rs +17 -16
- crates/in-web/tests/http.rs +315 -7
crates/in-core/src/config.rsmodified+24 -16
| @@ -360,22 +360,10 @@ impl Config { | |||
| 360 | // like every key here. | 360 | // like every key here. |
| 361 | let base_url = value(toml.base_url); | 361 | let base_url = value(toml.base_url); |
| 362 | if let Some(base) = &base_url { | 362 | if let Some(base) = &base_url { |
| 363 | - if !base.starts_with("http://") && !base.starts_with("https://") { | 363 | + Config::validate_base_url(base).map_err(|why| ConfigError::Invalid { |
| 364 | - return Err(ConfigError::Invalid { | 364 | + key: "base_url", |
| 365 | - key: "base_url", | 365 | + why, |
| 366 | - why: format!( | 366 | + })?; |
| 367 | - "{base:?} names no scheme — an origin like https://files.example.com is what links are built from" | ||
| 368 | - ), | ||
| 369 | - }); | ||
| 370 | - } | ||
| 371 | - if base.ends_with('/') { | ||
| 372 | - return Err(ConfigError::Invalid { | ||
| 373 | - key: "base_url", | ||
| 374 | - why: format!( | ||
| 375 | - "{base:?} ends in a slash — set the bare origin; In joins the /s/ path itself" | ||
| 376 | - ), | ||
| 377 | - }); | ||
| 378 | - } | ||
| 379 | } | 367 | } |
| 380 | 368 | ||
| 381 | let oidc_toml = toml.oidc.ok_or(ConfigError::Missing("[oidc]"))?; | 369 | let oidc_toml = toml.oidc.ok_or(ConfigError::Missing("[oidc]"))?; |
| @@ -472,6 +460,26 @@ fn listen_url_of(listen: &SocketAddr) -> String { | |||
| 472 | } | 460 | } |
| 473 | } | 461 | } |
| 474 | 462 | ||
| 463 | +impl Config { | ||
| 464 | + /// Whether a base URL is an origin a public link can be built on: an | ||
| 465 | + /// `http` or `https` scheme and no trailing slash. Shared by the file's | ||
| 466 | + /// own parse and the admin's server-address form, so a value the boot | ||
| 467 | + /// refuses is refused by the form for exactly the same reason. | ||
| 468 | + pub fn validate_base_url(value: &str) -> Result<(), String> { | ||
| 469 | + if !value.starts_with("http://") && !value.starts_with("https://") { | ||
| 470 | + return Err(format!( | ||
| 471 | + "{value:?} names no scheme — an origin like https://files.example.com is what links are built from" | ||
| 472 | + )); | ||
| 473 | + } | ||
| 474 | + if value.ends_with('/') { | ||
| 475 | + return Err(format!( | ||
| 476 | + "{value:?} ends in a slash — set the bare origin; In joins the /s/ path itself" | ||
| 477 | + )); | ||
| 478 | + } | ||
| 479 | + Ok(()) | ||
| 480 | + } | ||
| 481 | +} | ||
| 482 | + | ||
| 475 | /// Adds the top-level keys the file does not mention, each with its own | 483 | /// Adds the top-level keys the file does not mention, each with its own |
| 476 | /// comment and the default already in effect. The file is how a reader learns | 484 | /// comment and the default already in effect. The file is how a reader learns |
| 477 | /// what can be changed, so a key that is silently defaulted is a key nobody | 485 | /// what can be changed, so a key that is silently defaulted is a key nobody |
crates/in-web/src/drive.rsmodified+2 -2
| @@ -25,7 +25,7 @@ use topcoat::view::view; | |||
| 25 | 25 | ||
| 26 | use crate::i18n::{Key, lang, t}; | 26 | use crate::i18n::{Key, lang, t}; |
| 27 | use crate::layout::{NavPage, topbar}; | 27 | use crate::layout::{NavPage, topbar}; |
| 28 | -use crate::server::{Refusal, app, back_to, refusal_of, require_user}; | 28 | +use crate::server::{Refusal, app, back_to, refusal_of, require_user, share_origin}; |
| 29 | 29 | ||
| 30 | /// A [`StoreError`] in the drive's own words. Cross-owner reads and writes | 30 | /// A [`StoreError`] in the drive's own words. Cross-owner reads and writes |
| 31 | /// alike answer [`Refusal::NotFound`]: telling a stranger which ids exist is | 31 | /// alike answer [`Refusal::NotFound`]: telling a stranger which ids exist is |
| @@ -505,7 +505,7 @@ async fn drive(cx: &Cx) -> Result { | |||
| 505 | // A link minted from this surface redirects back here with the plaintext | 505 | // A link minted from this surface redirects back here with the plaintext |
| 506 | // token on `?created=` — rendered once, like the settings page does. | 506 | // token on `?created=` — rendered once, like the settings page does. |
| 507 | let created = created_token(uri(cx).query().unwrap_or("")); | 507 | let created = created_token(uri(cx).query().unwrap_or("")); |
| 508 | - let origin = app(cx).config.public_origin(); | 508 | + let origin = share_origin(cx).await; |
| 509 | 509 | ||
| 510 | let current_id = current | 510 | let current_id = current |
| 511 | .as_ref() | 511 | .as_ref() |
crates/in-web/src/i18n.rsmodified+13 -0
| @@ -227,6 +227,11 @@ pub enum Key { | |||
| 227 | PasswordLabel, | 227 | PasswordLabel, |
| 228 | WrongPassword, | 228 | WrongPassword, |
| 229 | Unlock, | 229 | Unlock, |
| 230 | + // Server address (SettingsPaging owns this block). | ||
| 231 | + ServerAddress, | ||
| 232 | + EffectiveOrigin, | ||
| 233 | + BaseUrlLabel, | ||
| 234 | + BaseUrlNote, | ||
| 230 | } | 235 | } |
| 231 | 236 | ||
| 232 | pub fn t(lang: Lang, key: Key) -> &'static str { | 237 | pub fn t(lang: Lang, key: Key) -> &'static str { |
| @@ -379,6 +384,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 379 | PasswordLabel => "Password", | 384 | PasswordLabel => "Password", |
| 380 | WrongPassword => "Wrong password.", | 385 | WrongPassword => "Wrong password.", |
| 381 | Unlock => "Unlock", | 386 | Unlock => "Unlock", |
| 387 | + ServerAddress => "Server address", | ||
| 388 | + EffectiveOrigin => "Effective origin", | ||
| 389 | + BaseUrlLabel => "Public base URL", | ||
| 390 | + BaseUrlNote => "The origin share links carry: a saved value wins, an empty one falls back to the configured base_url, then the bind address.", | ||
| 382 | }, | 391 | }, |
| 383 | Lang::Tr => match key { | 392 | Lang::Tr => match key { |
| 384 | Cancel => "Vazgeç", | 393 | Cancel => "Vazgeç", |
| @@ -527,6 +536,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 527 | PasswordLabel => "Parola", | 536 | PasswordLabel => "Parola", |
| 528 | WrongPassword => "Parola hatalı.", | 537 | WrongPassword => "Parola hatalı.", |
| 529 | Unlock => "Kilidi aç", | 538 | Unlock => "Kilidi aç", |
| 539 | + ServerAddress => "Sunucu adresi", | ||
| 540 | + EffectiveOrigin => "Etkin kök adres", | ||
| 541 | + BaseUrlLabel => "Herkese açık kök adres", | ||
| 542 | + BaseUrlNote => "Paylaşım bağlantılarının taşıdığı kök adres: kaydedilen değer önceliklidir, boş bırakılırsa yapılandırılmış base_url'e, sonra bağlanılan adrese dönülür.", | ||
| 530 | }, | 543 | }, |
| 531 | } | 544 | } |
| 532 | } | 545 | } |
crates/in-web/src/server.rsmodified+19 -0
| @@ -42,6 +42,18 @@ pub fn app(cx: &Cx) -> App { | |||
| 42 | app_context::<App>(cx).clone() | 42 | app_context::<App>(cx).clone() |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | +/// The origin the public links carry: the `base_url` an admin saved on the | ||
| 46 | +/// running install when one is set, else the config chain — the file's | ||
| 47 | +/// `base_url`, else the address bound. Every public URL construction (the | ||
| 48 | +/// share links and their copy-once banners) asks this; the settings | ||
| 49 | +/// server-address panel is what edits the setting the lookup reads. | ||
| 50 | +pub async fn share_origin(cx: &Cx) -> String { | ||
| 51 | + match app(cx).store.get_setting("base_url").await { | ||
| 52 | + Ok(Some(base)) if !base.trim().is_empty() => base.trim().to_string(), | ||
| 53 | + _ => app(cx).config.public_origin(), | ||
| 54 | + } | ||
| 55 | +} | ||
| 56 | + | ||
| 45 | /// A stable-enough label for the client, for rate limiting. A proxy header is | 57 | /// A stable-enough label for the client, for rate limiting. A proxy header is |
| 46 | /// only trusted because In is meant to sit behind one; the address bucket is | 58 | /// only trusted because In is meant to sit behind one; the address bucket is |
| 47 | /// the limit that actually protects the login round-trip either way. | 59 | /// the limit that actually protects the login round-trip either way. |
| @@ -219,6 +231,9 @@ pub enum Refusal { | |||
| 219 | /// The admin's quota form named something unusable — unparseable, or a | 231 | /// The admin's quota form named something unusable — unparseable, or a |
| 220 | /// unit the form does not offer. | 232 | /// unit the form does not offer. |
| 221 | BadLimit, | 233 | BadLimit, |
| 234 | + /// The admin's server-address form named something no public link can | ||
| 235 | + /// be built on — no `http`/`https` scheme, or a trailing slash. | ||
| 236 | + BadBaseUrl, | ||
| 222 | } | 237 | } |
| 223 | 238 | ||
| 224 | impl Refusal { | 239 | impl Refusal { |
| @@ -242,6 +257,7 @@ impl Refusal { | |||
| 242 | Refusal::BadTheme => "That is not a theme.".to_string(), | 257 | Refusal::BadTheme => "That is not a theme.".to_string(), |
| 243 | Refusal::BadLanguage => "That is not a language.".to_string(), | 258 | Refusal::BadLanguage => "That is not a language.".to_string(), |
| 244 | Refusal::BadLimit => "That limit is not usable.".to_string(), | 259 | Refusal::BadLimit => "That limit is not usable.".to_string(), |
| 260 | + Refusal::BadBaseUrl => "That address is not an origin links can be built on.".to_string(), | ||
| 245 | } | 261 | } |
| 246 | } | 262 | } |
| 247 | 263 | ||
| @@ -267,6 +283,7 @@ impl Refusal { | |||
| 267 | Refusal::BadTheme => "Bu bir tema değil.".to_string(), | 283 | Refusal::BadTheme => "Bu bir tema değil.".to_string(), |
| 268 | Refusal::BadLanguage => "Bu bir dil değil.".to_string(), | 284 | Refusal::BadLanguage => "Bu bir dil değil.".to_string(), |
| 269 | Refusal::BadLimit => "Bu sınır kullanılamaz.".to_string(), | 285 | Refusal::BadLimit => "Bu sınır kullanılamaz.".to_string(), |
| 286 | + Refusal::BadBaseUrl => "Bu adres, bağlantı kurulabilecek bir kök adres değil.".to_string(), | ||
| 270 | } | 287 | } |
| 271 | } | 288 | } |
| 272 | 289 | ||
| @@ -290,6 +307,7 @@ impl Refusal { | |||
| 290 | "bad-theme" => Refusal::BadTheme, | 307 | "bad-theme" => Refusal::BadTheme, |
| 291 | "bad-language" => Refusal::BadLanguage, | 308 | "bad-language" => Refusal::BadLanguage, |
| 292 | "bad-limit" => Refusal::BadLimit, | 309 | "bad-limit" => Refusal::BadLimit, |
| 310 | + "bad-base-url" => Refusal::BadBaseUrl, | ||
| 293 | _ => return None, | 311 | _ => return None, |
| 294 | }) | 312 | }) |
| 295 | } | 313 | } |
| @@ -317,6 +335,7 @@ impl Refusal { | |||
| 317 | Refusal::BadTheme => "bad-theme", | 335 | Refusal::BadTheme => "bad-theme", |
| 318 | Refusal::BadLanguage => "bad-language", | 336 | Refusal::BadLanguage => "bad-language", |
| 319 | Refusal::BadLimit => "bad-limit", | 337 | Refusal::BadLimit => "bad-limit", |
| 338 | + Refusal::BadBaseUrl => "bad-base-url", | ||
| 320 | } | 339 | } |
| 321 | } | 340 | } |
| 322 | } | 341 | } |
crates/in-web/src/settings.rsmodified+265 -137
| @@ -1,14 +1,17 @@ | |||
| 1 | //! Settings: the reader's profile and quota, plus the admin's user panel. | 1 | //! Settings: the reader's profile and quota, plus the admin's user panel. |
| 2 | //! | 2 | //! |
| 3 | -//! `GET /settings` shows the profile im vouches for (name, address) with the | 3 | +//! `GET /settings` renders one rail section at a time (`?section=`, the |
| 4 | -//! quota usage bar beside it, and the reader's own live share links with | 4 | +//! profile when the pair is missing or unknown): the profile with the quota |
| 5 | -//! their revoke buttons — including the copy-once banner after a creation | 5 | +//! usage bar; the reader's own live share links with their revoke buttons — |
| 6 | -//! (`?created=<token>` on the query, rendered once and never stored). | 6 | +//! including the copy-once banner after a creation (`?created=<token>` on |
| 7 | -//! Admins additionally see every account with its quota and disabled flag in | 7 | +//! the query, rendered once and never stored); and, for an admin, the |
| 8 | -//! the Everyone panel. `POST /api/settings/quota|disable` are admin-only: | 8 | +//! Everyone panel of every account with its quota and disabled flag, plus |
| 9 | -//! the first sets a user's byte quota, the second disables or re-enables | 9 | +//! the server address the public links carry. `POST |
| 10 | -//! them (a disabled account reads as signed-out everywhere, the im session | 10 | +//! /api/settings/quota|disable|base_url` are admin-only: the first sets a |
| 11 | -//! untouched, and disabling yourself is refused). | 11 | +//! user's byte quota, the second disables or re-enables them (a disabled |
| 12 | +//! account reads as signed-out everywhere, the im session untouched, and | ||
| 13 | +//! disabling yourself is refused), the third stores the origin share links | ||
| 14 | +//! are built from. | ||
| 12 | 15 | ||
| 13 | use in_core::store::{ShareKind, User}; | 16 | use in_core::store::{ShareKind, User}; |
| 14 | use serde::Deserialize; | 17 | use serde::Deserialize; |
| @@ -21,7 +24,7 @@ use topcoat::view::view; | |||
| 21 | 24 | ||
| 22 | use crate::i18n::{Key, lang, t}; | 25 | use crate::i18n::{Key, lang, t}; |
| 23 | use crate::layout::{NavPage, topbar}; | 26 | use crate::layout::{NavPage, topbar}; |
| 24 | -use crate::server::{Refusal, app, back_to, require_admin, require_user}; | 27 | +use crate::server::{Refusal, app, back_to, require_admin, require_user, share_origin}; |
| 25 | use crate::share::{refusal_banner, refusal_of}; | 28 | use crate::share::{refusal_banner, refusal_of}; |
| 26 | 29 | ||
| 27 | /// Bytes in human units: `512 B`, `1.5 KiB`, `2.0 GiB`. One decimal past | 30 | /// Bytes in human units: `512 B`, `1.5 KiB`, `2.0 GiB`. One decimal past |
| @@ -93,11 +96,13 @@ fn unit_bytes(amount: &str, unit: &str) -> Option<u64> { | |||
| 93 | 96 | ||
| 94 | type Redirect = Result<(StatusCode, [(HeaderName, String); 1])>; | 97 | type Redirect = Result<(StatusCode, [(HeaderName, String); 1])>; |
| 95 | 98 | ||
| 96 | -/// Back to settings, the refusal (if any) on the query — or `saved=<call>` | 99 | +/// Back to the posting page's section, the refusal (if any) on the query — |
| 97 | -/// when there was nothing to refuse, the way iz's `saved_or_refused` marks | 100 | +/// or `saved=<call>` when there was nothing to refuse, the way iz's |
| 98 | -/// a save the page should chip. | 101 | +/// `saved_or_refused` marks a save the page should chip. `nowhere` names |
| 99 | -fn redirect_back(cx: &Cx, call: &str, refusal: Option<Refusal>) -> Redirect { | 102 | +/// the section the call is answered on, for a post that arrives without a |
| 100 | - let back = back_to(cx, "/settings"); | 103 | +/// `Referer` to go back to. |
| 104 | +fn redirect_back(cx: &Cx, nowhere: &str, call: &str, refusal: Option<Refusal>) -> Redirect { | ||
| 105 | + let back = back_to(cx, nowhere); | ||
| 101 | let separator = if back.contains('?') { '&' } else { '?' }; | 106 | let separator = if back.contains('?') { '&' } else { '?' }; |
| 102 | let location = match refusal { | 107 | let location = match refusal { |
| 103 | Some(refusal) => format!("{back}{separator}refusal={}&on={call}", refusal.code()), | 108 | Some(refusal) => format!("{back}{separator}refusal={}&on={call}", refusal.code()), |
| @@ -122,7 +127,7 @@ struct QuotaForm { | |||
| 122 | #[route(POST "/api/settings/quota")] | 127 | #[route(POST "/api/settings/quota")] |
| 123 | async fn set_quota(cx: &Cx, Form(input): Form<QuotaForm>) -> Redirect { | 128 | async fn set_quota(cx: &Cx, Form(input): Form<QuotaForm>) -> Redirect { |
| 124 | if let Err(refusal) = require_admin(cx).await { | 129 | if let Err(refusal) = require_admin(cx).await { |
| 125 | - return redirect_back(cx, "quota", Some(refusal)); | 130 | + return redirect_back(cx, "/settings?section=everyone", "quota", Some(refusal)); |
| 126 | } | 131 | } |
| 127 | match unit_bytes(&input.quota, &input.quota_unit) { | 132 | match unit_bytes(&input.quota, &input.quota_unit) { |
| 128 | Some(quota_bytes) => match app(cx) | 133 | Some(quota_bytes) => match app(cx) |
| @@ -130,10 +135,10 @@ async fn set_quota(cx: &Cx, Form(input): Form<QuotaForm>) -> Redirect { | |||
| 130 | .set_user_quota(&input.user_id, quota_bytes) | 135 | .set_user_quota(&input.user_id, quota_bytes) |
| 131 | .await | 136 | .await |
| 132 | { | 137 | { |
| 133 | - Ok(()) => redirect_back(cx, "quota", None), | 138 | + Ok(()) => redirect_back(cx, "/settings?section=everyone", "quota", None), |
| 134 | - Err(error) => redirect_back(cx, "quota", Some(refusal_of(error))), | 139 | + Err(error) => redirect_back(cx, "/settings?section=everyone", "quota", Some(refusal_of(error))), |
| 135 | }, | 140 | }, |
| 136 | - None => redirect_back(cx, "quota", Some(Refusal::BadLimit)), | 141 | + None => redirect_back(cx, "/settings?section=everyone", "quota", Some(Refusal::BadLimit)), |
| 137 | } | 142 | } |
| 138 | } | 143 | } |
| 139 | 144 | ||
| @@ -150,10 +155,10 @@ struct DisableForm { | |||
| 150 | async fn set_disabled(cx: &Cx, Form(input): Form<DisableForm>) -> Redirect { | 155 | async fn set_disabled(cx: &Cx, Form(input): Form<DisableForm>) -> Redirect { |
| 151 | let admin = match require_admin(cx).await { | 156 | let admin = match require_admin(cx).await { |
| 152 | Ok(admin) => admin, | 157 | Ok(admin) => admin, |
| 153 | - Err(refusal) => return redirect_back(cx, "disable", Some(refusal)), | 158 | + Err(refusal) => return redirect_back(cx, "/settings?section=everyone", "disable", Some(refusal)), |
| 154 | }; | 159 | }; |
| 155 | if input.user_id == admin.id { | 160 | if input.user_id == admin.id { |
| 156 | - return redirect_back(cx, "disable", Some(Refusal::Forbidden)); | 161 | + return redirect_back(cx, "/settings?section=everyone", "disable", Some(Refusal::Forbidden)); |
| 157 | } | 162 | } |
| 158 | let disabled = match input.disabled.as_deref() { | 163 | let disabled = match input.disabled.as_deref() { |
| 159 | None => true, | 164 | None => true, |
| @@ -167,8 +172,8 @@ async fn set_disabled(cx: &Cx, Form(input): Form<DisableForm>) -> Redirect { | |||
| 167 | .set_user_disabled(&input.user_id, disabled) | 172 | .set_user_disabled(&input.user_id, disabled) |
| 168 | .await | 173 | .await |
| 169 | { | 174 | { |
| 170 | - Ok(()) => redirect_back(cx, "disable", None), | 175 | + Ok(()) => redirect_back(cx, "/settings?section=everyone", "disable", None), |
| 171 | - Err(error) => redirect_back(cx, "disable", Some(refusal_of(error))), | 176 | + Err(error) => redirect_back(cx, "/settings?section=everyone", "disable", Some(refusal_of(error))), |
| 172 | } | 177 | } |
| 173 | } | 178 | } |
| 174 | 179 | ||
| @@ -196,29 +201,89 @@ const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"]; | |||
| 196 | async fn set_preferences(cx: &Cx, Form(input): Form<PreferencesForm>) -> Redirect { | 201 | async fn set_preferences(cx: &Cx, Form(input): Form<PreferencesForm>) -> Redirect { |
| 197 | let user = match require_user(cx).await { | 202 | let user = match require_user(cx).await { |
| 198 | Ok(user) => user, | 203 | Ok(user) => user, |
| 199 | - Err(refusal) => return redirect_back(cx, "preferences", Some(refusal)), | 204 | + Err(refusal) => return redirect_back(cx, "/settings?section=profile", "preferences", Some(refusal)), |
| 200 | }; | 205 | }; |
| 201 | if !UI_OPTIONS.contains(&input.ui.as_str()) { | 206 | if !UI_OPTIONS.contains(&input.ui.as_str()) { |
| 202 | - return redirect_back(cx, "preferences", Some(Refusal::BadUi)); | 207 | + return redirect_back(cx, "/settings?section=profile", "preferences", Some(Refusal::BadUi)); |
| 203 | } | 208 | } |
| 204 | if !THEME_OPTIONS.contains(&input.theme.as_str()) { | 209 | if !THEME_OPTIONS.contains(&input.theme.as_str()) { |
| 205 | - return redirect_back(cx, "preferences", Some(Refusal::BadTheme)); | 210 | + return redirect_back(cx, "/settings?section=profile", "preferences", Some(Refusal::BadTheme)); |
| 206 | } | 211 | } |
| 207 | if !LANGUAGE_OPTIONS.contains(&input.language.as_str()) { | 212 | if !LANGUAGE_OPTIONS.contains(&input.language.as_str()) { |
| 208 | - return redirect_back(cx, "preferences", Some(Refusal::BadLanguage)); | 213 | + return redirect_back(cx, "/settings?section=profile", "preferences", Some(Refusal::BadLanguage)); |
| 209 | } | 214 | } |
| 210 | match app(cx) | 215 | match app(cx) |
| 211 | .store | 216 | .store |
| 212 | .set_preferences(&user.id, &input.theme, &input.language, &input.ui) | 217 | .set_preferences(&user.id, &input.theme, &input.language, &input.ui) |
| 213 | .await | 218 | .await |
| 214 | { | 219 | { |
| 215 | - Ok(()) => redirect_back(cx, "preferences", None), | 220 | + Ok(()) => redirect_back(cx, "/settings?section=profile", "preferences", None), |
| 216 | - Err(error) => redirect_back(cx, "preferences", Some(refusal_of(error))), | 221 | + Err(error) => redirect_back(cx, "/settings?section=profile", "preferences", Some(refusal_of(error))), |
| 217 | } | 222 | } |
| 218 | } | 223 | } |
| 219 | 224 | ||
| 220 | -/// The reader's profile and quota, their live share links, and — for an | 225 | +#[derive(Deserialize)] |
| 221 | -/// admin — every account with its quota and kill switch. | 226 | +struct BaseUrlForm { |
| 227 | + #[serde(default)] | ||
| 228 | + base_url: String, | ||
| 229 | +} | ||
| 230 | + | ||
| 231 | +/// Stores the origin the public links are built from, in the instance | ||
| 232 | +/// `setting` store under `base_url`. While a non-empty value sits there it | ||
| 233 | +/// is what [`crate::server::share_origin`] hands every link builder; | ||
| 234 | +/// saving empty clears it, and the origin falls back to the config chain. | ||
| 235 | +/// A value the boot would refuse is refused here for the same reason — | ||
| 236 | +/// [`in_core::Config::validate_base_url`], the very check `parse` runs — | ||
| 237 | +/// and the stored setting is left untouched. | ||
| 238 | +#[route(POST "/api/settings/base_url")] | ||
| 239 | +async fn set_base_url(cx: &Cx, Form(input): Form<BaseUrlForm>) -> Redirect { | ||
| 240 | + if let Err(refusal) = require_admin(cx).await { | ||
| 241 | + return redirect_back(cx, "/settings?section=server", "base_url", Some(refusal)); | ||
| 242 | + } | ||
| 243 | + let trimmed = input.base_url.trim().to_string(); | ||
| 244 | + if !trimmed.is_empty() && in_core::Config::validate_base_url(&trimmed).is_err() { | ||
| 245 | + return redirect_back(cx, "/settings?section=server", "base_url", Some(Refusal::BadBaseUrl)); | ||
| 246 | + } | ||
| 247 | + match app(cx).store.set_setting("base_url", &trimmed).await { | ||
| 248 | + Ok(()) => redirect_back(cx, "/settings?section=server", "base_url", None), | ||
| 249 | + Err(error) => redirect_back(cx, "/settings?section=server", "base_url", Some(refusal_of(error))), | ||
| 250 | + } | ||
| 251 | +} | ||
| 252 | + | ||
| 253 | +/// Which rail section the page renders. Only one is drawn at a time; an | ||
| 254 | +/// admin-only value asked for by anyone else falls back to `Profile`, same | ||
| 255 | +/// as a section name it does not recognize at all. | ||
| 256 | +#[derive(Clone, Copy, PartialEq, Eq)] | ||
| 257 | +enum Section { | ||
| 258 | + Profile, | ||
| 259 | + Links, | ||
| 260 | + Everyone, | ||
| 261 | + Server, | ||
| 262 | +} | ||
| 263 | + | ||
| 264 | +/// The class a rail link wears: `active` on the section it points to when | ||
| 265 | +/// that is the one showing, plain otherwise. | ||
| 266 | +fn rail_class(current: Section, target: Section) -> &'static str { | ||
| 267 | + if current == target { | ||
| 268 | + "settings-section-link active" | ||
| 269 | + } else { | ||
| 270 | + "settings-section-link" | ||
| 271 | + } | ||
| 272 | +} | ||
| 273 | + | ||
| 274 | +/// The value of one query pair, if present. | ||
| 275 | +fn query_value(query: &str, key: &str) -> Option<String> { | ||
| 276 | + query.split('&').find_map(|pair| { | ||
| 277 | + let (name, value) = pair.split_once('=')?; | ||
| 278 | + (name == key).then(|| value.to_string()) | ||
| 279 | + }) | ||
| 280 | +} | ||
| 281 | + | ||
| 282 | +/// The settings screen, one rail section at a time: the reader's profile | ||
| 283 | +/// and quota, their live share links, and — for an admin — every account | ||
| 284 | +/// with its quota and kill switch, plus the server address the public | ||
| 285 | +/// links are built from. An admin section asked for by anyone else renders | ||
| 286 | +/// the profile, the way an unknown section name does. | ||
| 222 | #[page("/settings")] | 287 | #[page("/settings")] |
| 223 | async fn settings(cx: &Cx) -> Result { | 288 | async fn settings(cx: &Cx) -> Result { |
| 224 | let user = match require_user(cx).await { | 289 | let user = match require_user(cx).await { |
| @@ -238,131 +303,174 @@ async fn settings(cx: &Cx) -> Result { | |||
| 238 | let store = app(cx).store; | 303 | let store = app(cx).store; |
| 239 | // Re-read the row so the quota bar never shows a stale number. | 304 | // Re-read the row so the quota bar never shows a stale number. |
| 240 | let fresh = store.user(&user.id).await?.unwrap_or_else(|| user.clone()); | 305 | let fresh = store.user(&user.id).await?.unwrap_or_else(|| user.clone()); |
| 241 | - let links = store.share_links(&user.id).await?; | 306 | + let administers = fresh.admin; |
| 242 | - let live_links: Vec<_> = links | 307 | + let query = uri(cx).query().unwrap_or(""); |
| 243 | - .iter() | 308 | + let section = match query_value(query, "section").as_deref() { |
| 244 | - .filter(|link| link.revoked_at.is_none()) | 309 | + Some("links") => Section::Links, |
| 245 | - .collect(); | 310 | + Some("everyone") if administers => Section::Everyone, |
| 246 | - // The display name per live link's target: the row carries only the id. | 311 | + Some("server") if administers => Section::Server, |
| 247 | - // A missing or trashed target keeps its id — the grant row outlives the | 312 | + _ => Section::Profile, |
| 248 | - // trash, and the panel still revokes it. Enrichment never fails the | 313 | + }; |
| 249 | - // page: an unreadable target reads as its id, the way the shared list | 314 | + let created = created_token(query); |
| 250 | - // degrades per row. | 315 | + // Only the section on show pays for its rows: the links panel names |
| 316 | + // each live link's target, Everyone lists the accounts, and the server | ||
| 317 | + // panel needs the origin — nothing else reads them. | ||
| 251 | let mut link_names: Vec<(&in_core::store::ShareLink, String)> = Vec::new(); | 318 | let mut link_names: Vec<(&in_core::store::ShareLink, String)> = Vec::new(); |
| 252 | - for link in &live_links { | 319 | + let links = if section == Section::Links { |
| 253 | - let name = match link.kind { | 320 | + store.share_links(&user.id).await? |
| 254 | - ShareKind::File => store | 321 | + } else { |
| 255 | - .file(&link.target_id) | 322 | + Vec::new() |
| 256 | - .await | 323 | + }; |
| 257 | - .ok() | 324 | + if section == Section::Links { |
| 258 | - .flatten() | 325 | + // The display name per live link's target: the row carries only |
| 259 | - .map(|file| file.name), | 326 | + // the id. A missing or trashed target keeps its id — the grant row |
| 260 | - ShareKind::Folder => store | 327 | + // outlives the trash, and the panel still revokes it. Enrichment |
| 261 | - .folder(&link.target_id) | 328 | + // never fails the page: an unreadable target reads as its id, the |
| 262 | - .await | 329 | + // way the shared list degrades per row. |
| 263 | - .ok() | 330 | + for link in links.iter().filter(|link| link.revoked_at.is_none()) { |
| 264 | - .flatten() | 331 | + let name = match link.kind { |
| 265 | - .map(|folder| folder.name), | 332 | + ShareKind::File => store |
| 333 | + .file(&link.target_id) | ||
| 334 | + .await | ||
| 335 | + .ok() | ||
| 336 | + .flatten() | ||
| 337 | + .map(|file| file.name), | ||
| 338 | + ShareKind::Folder => store | ||
| 339 | + .folder(&link.target_id) | ||
| 340 | + .await | ||
| 341 | + .ok() | ||
| 342 | + .flatten() | ||
| 343 | + .map(|folder| folder.name), | ||
| 344 | + } | ||
| 345 | + .unwrap_or_else(|| link.target_id.clone()); | ||
| 346 | + link_names.push((link, name)); | ||
| 266 | } | 347 | } |
| 267 | - .unwrap_or_else(|| link.target_id.clone()); | ||
| 268 | - link_names.push((*link, name)); | ||
| 269 | } | 348 | } |
| 270 | - let users = if fresh.admin { | 349 | + let users = if administers && section == Section::Everyone { |
| 271 | store.users().await? | 350 | store.users().await? |
| 272 | } else { | 351 | } else { |
| 273 | Vec::new() | 352 | Vec::new() |
| 274 | }; | 353 | }; |
| 275 | - let created = created_token(uri(cx).query().unwrap_or("")); | 354 | + // The origin the copy-once banner and the server panel show: the |
| 276 | - let origin = app(cx).config.public_origin(); | 355 | + // stored setting when an admin set one, the config chain otherwise. |
| 356 | + let origin = if matches!(section, Section::Links | Section::Server) { | ||
| 357 | + share_origin(cx).await | ||
| 358 | + } else { | ||
| 359 | + String::new() | ||
| 360 | + }; | ||
| 361 | + // What the server form's field holds: the stored setting alone. An | ||
| 362 | + // empty field is not an invented value — the effective line above it | ||
| 363 | + // shows what an empty save falls back to. | ||
| 364 | + let stored_base_url = if section == Section::Server { | ||
| 365 | + store | ||
| 366 | + .get_setting("base_url") | ||
| 367 | + .await? | ||
| 368 | + .filter(|value| !value.trim().is_empty()) | ||
| 369 | + .unwrap_or_default() | ||
| 370 | + } else { | ||
| 371 | + String::new() | ||
| 372 | + }; | ||
| 277 | view! { | 373 | view! { |
| 278 | cx => | 374 | cx => |
| 279 | (topbar(cx, NavPage::Settings, &fresh, language).await?) | 375 | (topbar(cx, NavPage::Settings, &fresh, language).await?) |
| 280 | <div class="settings-shell"> | 376 | <div class="settings-shell"> |
| 377 | + <nav class="settings-sections"> | ||
| 378 | + <a class=(rail_class(section, Section::Profile)) href="/settings?section=profile">(t(language, Key::Profile))</a> | ||
| 379 | + <a class=(rail_class(section, Section::Links)) href="/settings?section=links">(t(language, Key::ManageLinks))</a> | ||
| 380 | + if administers { | ||
| 381 | + <a class=(rail_class(section, Section::Everyone)) href="/settings?section=everyone">(t(language, Key::AdminPanel))</a> | ||
| 382 | + <a class=(rail_class(section, Section::Server)) href="/settings?section=server">(t(language, Key::ServerAddress))</a> | ||
| 383 | + } | ||
| 384 | + </nav> | ||
| 281 | <main class="settings-stage stage-wide"> | 385 | <main class="settings-stage stage-wide"> |
| 282 | <h1 class="settings-title">(t(language, Key::Settings))</h1> | 386 | <h1 class="settings-title">(t(language, Key::Settings))</h1> |
| 283 | - (refusal_banner(cx, language, &["create", "revoke", "add", "remove", "quota", "disable", "preferences"]).await?) | 387 | + (refusal_banner(cx, language, &["create", "revoke", "add", "remove", "quota", "disable", "preferences", "base_url"]).await?) |
| 284 | - if let Some(token) = created { | 388 | + if section == Section::Profile { |
| 285 | <section class="panel"> | 389 | <section class="panel"> |
| 286 | <div class="panel-head"> | 390 | <div class="panel-head"> |
| 287 | - <h2 class="panel-title">(t(language, Key::LinkCreated))</h2> | 391 | + <h2 class="panel-title">(t(language, Key::Profile))</h2> |
| 288 | </div> | 392 | </div> |
| 289 | <div class="panel-body"> | 393 | <div class="panel-body"> |
| 290 | - <p class="field-note">(t(language, Key::CopyLinkOnce))</p> | ||
| 291 | - <p class="member-link-value">(format!("{origin}/s/{token}"))</p> | ||
| 292 | - </div> | ||
| 293 | - </section> | ||
| 294 | - } | ||
| 295 | - <section class="panel"> | ||
| 296 | - <div class="panel-head"> | ||
| 297 | - <h2 class="panel-title">(t(language, Key::Profile))</h2> | ||
| 298 | - </div> | ||
| 299 | - <div class="panel-body"> | ||
| 300 | - <label class="field"> | ||
| 301 | - <span class="field-label">(t(language, Key::DisplayName))</span> | ||
| 302 | - <span class="field-static">(fresh.display_name.clone())</span> | ||
| 303 | - </label> | ||
| 304 | - <label class="field"> | ||
| 305 | - <span class="field-label">(t(language, Key::EmailAddress))</span> | ||
| 306 | - <span class="field-static">(fresh.email.clone())</span> | ||
| 307 | - </label> | ||
| 308 | - <div class="field"> | ||
| 309 | - <span class="field-label">(t(language, Key::QuotaUsage))</span> | ||
| 310 | - <span class="field-static">(format!("{} {} {}", human_bytes(fresh.used_bytes), t(language, Key::QuotaOf), human_bytes(fresh.quota_bytes)))</span> | ||
| 311 | - <div class="quota-bar" role="progressbar" aria-valuenow=(quota_percent(&fresh).to_string()) aria-valuemin="0" aria-valuemax="100"> | ||
| 312 | - <div class="quota-fill" style=(format!("width: {}%", quota_percent(&fresh)))></div> | ||
| 313 | - </div> | ||
| 314 | - </div> | ||
| 315 | - <form class="field" method="post" action="/api/settings/preferences"> | ||
| 316 | - <label class="field"> | ||
| 317 | - <span class="field-label">(t(language, Key::UiLabel))</span> | ||
| 318 | - <select class="field-input" name="ui"> | ||
| 319 | - <option value="instrument" selected=(fresh.ui == "instrument")>"Instrument"</option> | ||
| 320 | - <option value="ledger" selected=(fresh.ui == "ledger")>"Ledger"</option> | ||
| 321 | - </select> | ||
| 322 | - </label> | ||
| 323 | <label class="field"> | 394 | <label class="field"> |
| 324 | - <span class="field-label">(t(language, Key::ThemeLabel))</span> | 395 | + <span class="field-label">(t(language, Key::DisplayName))</span> |
| 325 | - <select class="field-input" name="theme"> | 396 | + <span class="field-static">(fresh.display_name.clone())</span> |
| 326 | - <option value="light" selected=(fresh.theme == "light")>(t(language, Key::LightOption))</option> | ||
| 327 | - <option value="dark" selected=(fresh.theme == "dark")>(t(language, Key::DarkOption))</option> | ||
| 328 | - </select> | ||
| 329 | </label> | 397 | </label> |
| 330 | <label class="field"> | 398 | <label class="field"> |
| 331 | - <span class="field-label">(t(language, Key::LanguageLabel))</span> | 399 | + <span class="field-label">(t(language, Key::EmailAddress))</span> |
| 332 | - <select class="field-input" name="language"> | 400 | + <span class="field-static">(fresh.email.clone())</span> |
| 333 | - <option value="en" selected=(fresh.language == "en")>"English"</option> | ||
| 334 | - <option value="tr" selected=(fresh.language == "tr")>"Türkçe"</option> | ||
| 335 | - </select> | ||
| 336 | </label> | 401 | </label> |
| 337 | - <div class="panel-foot"> | 402 | + <div class="field"> |
| 338 | - <button class="primary" type="submit">(t(language, Key::Save))</button> | 403 | + <span class="field-label">(t(language, Key::QuotaUsage))</span> |
| 404 | + <span class="field-static">(format!("{} {} {}", human_bytes(fresh.used_bytes), t(language, Key::QuotaOf), human_bytes(fresh.quota_bytes)))</span> | ||
| 405 | + <div class="quota-bar" role="progressbar" aria-valuenow=(quota_percent(&fresh).to_string()) aria-valuemin="0" aria-valuemax="100"> | ||
| 406 | + <div class="quota-fill" style=(format!("width: {}%", quota_percent(&fresh)))></div> | ||
| 407 | + </div> | ||
| 339 | </div> | 408 | </div> |
| 340 | - </form> | 409 | + <form class="field" method="post" action="/api/settings/preferences"> |
| 341 | - </div> | 410 | + <label class="field"> |
| 342 | - </section> | 411 | + <span class="field-label">(t(language, Key::UiLabel))</span> |
| 343 | - <section class="panel"> | 412 | + <select class="field-input" name="ui"> |
| 344 | - <div class="panel-head"> | 413 | + <option value="instrument" selected=(fresh.ui == "instrument")>"Instrument"</option> |
| 345 | - <h2 class="panel-title">(t(language, Key::ManageLinks))</h2> | 414 | + <option value="ledger" selected=(fresh.ui == "ledger")>"Ledger"</option> |
| 346 | - </div> | 415 | + </select> |
| 347 | - <div class="panel-body"> | 416 | + </label> |
| 348 | - if live_links.is_empty() { | 417 | + <label class="field"> |
| 349 | - <p class="field-note">(t(language, Key::NoLinks))</p> | 418 | + <span class="field-label">(t(language, Key::ThemeLabel))</span> |
| 350 | - } | 419 | + <select class="field-input" name="theme"> |
| 351 | - for (link, target_name) in &link_names { | 420 | + <option value="light" selected=(fresh.theme == "light")>(t(language, Key::LightOption))</option> |
| 352 | - <div class="member-row"> | 421 | + <option value="dark" selected=(fresh.theme == "dark")>(t(language, Key::DarkOption))</option> |
| 353 | - <span class="member-name">(format!("{} · {}", link.kind.as_str(), target_name.clone()))</span> | 422 | + </select> |
| 354 | - <span class="field-note">(expiry_line(language, link.expires_at))</span> | 423 | + </label> |
| 355 | - <div class="spacer"></div> | 424 | + <label class="field"> |
| 356 | - <span class="field-note">(if link.can_download { t(language, Key::CanDownload) } else { t(language, Key::ViewOnly) })</span> | 425 | + <span class="field-label">(t(language, Key::LanguageLabel))</span> |
| 357 | - <form class="pop-row-form" method="post" action="/api/share/link/revoke"> | 426 | + <select class="field-input" name="language"> |
| 358 | - <input type="hidden" name="id" value=(link.id.clone())> | 427 | + <option value="en" selected=(fresh.language == "en")>"English"</option> |
| 359 | - <button class="quiet quiet-danger" type="submit">(t(language, Key::RevokeLink))</button> | 428 | + <option value="tr" selected=(fresh.language == "tr")>"Türkçe"</option> |
| 360 | - </form> | 429 | + </select> |
| 430 | + </label> | ||
| 431 | + <div class="panel-foot"> | ||
| 432 | + <button class="primary" type="submit">(t(language, Key::Save))</button> | ||
| 433 | + </div> | ||
| 434 | + </form> | ||
| 435 | + </div> | ||
| 436 | + </section> | ||
| 437 | + } | ||
| 438 | + if section == Section::Links { | ||
| 439 | + if let Some(token) = created { | ||
| 440 | + <section class="panel"> | ||
| 441 | + <div class="panel-head"> | ||
| 442 | + <h2 class="panel-title">(t(language, Key::LinkCreated))</h2> | ||
| 361 | </div> | 443 | </div> |
| 362 | - } | 444 | + <div class="panel-body"> |
| 363 | - </div> | 445 | + <p class="field-note">(t(language, Key::CopyLinkOnce))</p> |
| 364 | - </section> | 446 | + <p class="member-link-value">(format!("{origin}/s/{token}"))</p> |
| 365 | - if fresh.admin { | 447 | + </div> |
| 448 | + </section> | ||
| 449 | + } | ||
| 450 | + <section class="panel"> | ||
| 451 | + <div class="panel-head"> | ||
| 452 | + <h2 class="panel-title">(t(language, Key::ManageLinks))</h2> | ||
| 453 | + </div> | ||
| 454 | + <div class="panel-body"> | ||
| 455 | + if link_names.is_empty() { | ||
| 456 | + <p class="field-note">(t(language, Key::NoLinks))</p> | ||
| 457 | + } | ||
| 458 | + for (link, target_name) in &link_names { | ||
| 459 | + <div class="member-row"> | ||
| 460 | + <span class="member-name">(format!("{} · {}", link.kind.as_str(), target_name.clone()))</span> | ||
| 461 | + <span class="field-note">(expiry_line(language, link.expires_at))</span> | ||
| 462 | + <div class="spacer"></div> | ||
| 463 | + <span class="field-note">(if link.can_download { t(language, Key::CanDownload) } else { t(language, Key::ViewOnly) })</span> | ||
| 464 | + <form class="pop-row-form" method="post" action="/api/share/link/revoke"> | ||
| 465 | + <input type="hidden" name="id" value=(link.id.clone())> | ||
| 466 | + <button class="quiet quiet-danger" type="submit">(t(language, Key::RevokeLink))</button> | ||
| 467 | + </form> | ||
| 468 | + </div> | ||
| 469 | + } | ||
| 470 | + </div> | ||
| 471 | + </section> | ||
| 472 | + } | ||
| 473 | + if section == Section::Everyone { | ||
| 366 | <section class="panel"> | 474 | <section class="panel"> |
| 367 | <div class="panel-head"> | 475 | <div class="panel-head"> |
| 368 | <h2 class="panel-title">(t(language, Key::AdminPanel))</h2> | 476 | <h2 class="panel-title">(t(language, Key::AdminPanel))</h2> |
| @@ -427,6 +535,29 @@ async fn settings(cx: &Cx) -> Result { | |||
| 427 | </div> | 535 | </div> |
| 428 | </section> | 536 | </section> |
| 429 | } | 537 | } |
| 538 | + if section == Section::Server { | ||
| 539 | + <section class="panel"> | ||
| 540 | + <div class="panel-head"> | ||
| 541 | + <h2 class="panel-title">(t(language, Key::ServerAddress))</h2> | ||
| 542 | + </div> | ||
| 543 | + <div class="panel-body"> | ||
| 544 | + <label class="field"> | ||
| 545 | + <span class="field-label">(t(language, Key::EffectiveOrigin))</span> | ||
| 546 | + <span class="field-static">(origin.clone())</span> | ||
| 547 | + </label> | ||
| 548 | + <form class="field" method="post" action="/api/settings/base_url"> | ||
| 549 | + <label class="field"> | ||
| 550 | + <span class="field-label">(t(language, Key::BaseUrlLabel))</span> | ||
| 551 | + <input class="field-input" type="url" name="base_url" value=(stored_base_url) placeholder="https://files.example.com"> | ||
| 552 | + </label> | ||
| 553 | + <p class="field-note">(t(language, Key::BaseUrlNote))</p> | ||
| 554 | + <div class="panel-foot"> | ||
| 555 | + <button class="primary" type="submit">(t(language, Key::Save))</button> | ||
| 556 | + </div> | ||
| 557 | + </form> | ||
| 558 | + </div> | ||
| 559 | + </section> | ||
| 560 | + } | ||
| 430 | </main> | 561 | </main> |
| 431 | </div> | 562 | </div> |
| 432 | (crate::dropdown::dropdown_script(cx).await?) | 563 | (crate::dropdown::dropdown_script(cx).await?) |
| @@ -435,10 +566,7 @@ async fn settings(cx: &Cx) -> Result { | |||
| 435 | 566 | ||
| 436 | /// The just-minted token off the redirect's `?created=` pair, if present. | 567 | /// The just-minted token off the redirect's `?created=` pair, if present. |
| 437 | fn created_token(query: &str) -> Option<String> { | 568 | fn created_token(query: &str) -> Option<String> { |
| 438 | - query.split('&').find_map(|pair| { | 569 | + query_value(query, "created").filter(|value| !value.is_empty()) |
| 439 | - let (name, value) = pair.split_once('=')?; | ||
| 440 | - (name == "created" && !value.is_empty()).then(|| value.to_string()) | ||
| 441 | - }) | ||
| 442 | } | 570 | } |
| 443 | 571 | ||
| 444 | /// When the link stops opening, or never on its own. | 572 | /// When the link stops opening, or never on its own. |
crates/in-web/src/share.rsmodified+17 -16
| @@ -34,7 +34,7 @@ use topcoat::view::view; | |||
| 34 | use crate::files::{ViewerKind, entry_chip, media_player, media_player_script, viewer_kind}; | 34 | use crate::files::{ViewerKind, entry_chip, media_player, media_player_script, viewer_kind}; |
| 35 | use crate::i18n::{Key, Lang, lang, t}; | 35 | use crate::i18n::{Key, Lang, lang, t}; |
| 36 | use crate::layout::{NavPage, document_shell, topbar, wordmark}; | 36 | use crate::layout::{NavPage, document_shell, topbar, wordmark}; |
| 37 | -use crate::server::{Refusal, app, back_to, require_user}; | 37 | +use crate::server::{Refusal, app, back_to, require_user, share_origin}; |
| 38 | 38 | ||
| 39 | path_param!(token); | 39 | path_param!(token); |
| 40 | path_param!(kind); | 40 | path_param!(kind); |
| @@ -219,18 +219,18 @@ struct CreateLinkForm { | |||
| 219 | async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect { | 219 | async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect { |
| 220 | let user = match require_user(cx).await { | 220 | let user = match require_user(cx).await { |
| 221 | Ok(user) => user, | 221 | Ok(user) => user, |
| 222 | - Err(refusal) => return redirect_back(cx, "/settings", "create", Some(refusal)), | 222 | + Err(refusal) => return redirect_back(cx, "/settings?section=links", "create", Some(refusal)), |
| 223 | }; | 223 | }; |
| 224 | let Some(kind) = parse_kind(&input.kind) else { | 224 | let Some(kind) = parse_kind(&input.kind) else { |
| 225 | - return redirect_back(cx, "/settings", "create", Some(Refusal::NotFound)); | 225 | + return redirect_back(cx, "/settings?section=links", "create", Some(Refusal::NotFound)); |
| 226 | }; | 226 | }; |
| 227 | if let Err(refusal) = owned_target(app(cx).store.as_ref(), &user, kind, &input.target_id).await | 227 | if let Err(refusal) = owned_target(app(cx).store.as_ref(), &user, kind, &input.target_id).await |
| 228 | { | 228 | { |
| 229 | - return redirect_back(cx, "/settings", "create", Some(refusal)); | 229 | + return redirect_back(cx, "/settings?section=links", "create", Some(refusal)); |
| 230 | } | 230 | } |
| 231 | let expires_at = match parse_expiry(input.expires_in_days.as_deref()) { | 231 | let expires_at = match parse_expiry(input.expires_in_days.as_deref()) { |
| 232 | Ok(expires_at) => expires_at, | 232 | Ok(expires_at) => expires_at, |
| 233 | - Err(refusal) => return redirect_back(cx, "/settings", "create", Some(refusal)), | 233 | + Err(refusal) => return redirect_back(cx, "/settings?section=links", "create", Some(refusal)), |
| 234 | }; | 234 | }; |
| 235 | // An optional password on the link: a trimmed empty field is no | 235 | // An optional password on the link: a trimmed empty field is no |
| 236 | // password at all. Argon2id is CPU-slow on purpose, so the hash runs | 236 | // password at all. Argon2id is CPU-slow on purpose, so the hash runs |
| @@ -240,7 +240,7 @@ async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect { | |||
| 240 | Some(password) => { | 240 | Some(password) => { |
| 241 | match tokio::task::spawn_blocking(move || hash_link_password(&password)).await { | 241 | match tokio::task::spawn_blocking(move || hash_link_password(&password)).await { |
| 242 | Ok(Ok(hash)) => Some(hash), | 242 | Ok(Ok(hash)) => Some(hash), |
| 243 | - _ => return redirect_back(cx, "/settings", "create", Some(Refusal::Unavailable)), | 243 | + _ => return redirect_back(cx, "/settings?section=links", "create", Some(Refusal::Unavailable)), |
| 244 | } | 244 | } |
| 245 | } | 245 | } |
| 246 | None => None, | 246 | None => None, |
| @@ -260,12 +260,12 @@ async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect { | |||
| 260 | .await; | 260 | .await; |
| 261 | match created { | 261 | match created { |
| 262 | Ok(link) => { | 262 | Ok(link) => { |
| 263 | - let back = back_to(cx, "/settings"); | 263 | + let back = back_to(cx, "/settings?section=links"); |
| 264 | let separator = if back.contains('?') { '&' } else { '?' }; | 264 | let separator = if back.contains('?') { '&' } else { '?' }; |
| 265 | let location = format!("{back}{separator}created={}", link.token); | 265 | let location = format!("{back}{separator}created={}", link.token); |
| 266 | Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)])) | 266 | Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)])) |
| 267 | } | 267 | } |
| 268 | - Err(error) => redirect_back(cx, "/settings", "create", Some(refusal_of(error))), | 268 | + Err(error) => redirect_back(cx, "/settings?section=links", "create", Some(refusal_of(error))), |
| 269 | } | 269 | } |
| 270 | } | 270 | } |
| 271 | 271 | ||
| @@ -280,7 +280,7 @@ struct RevokeLinkForm { | |||
| 280 | async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect { | 280 | async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect { |
| 281 | let user = match require_user(cx).await { | 281 | let user = match require_user(cx).await { |
| 282 | Ok(user) => user, | 282 | Ok(user) => user, |
| 283 | - Err(refusal) => return redirect_back(cx, "/settings", "revoke", Some(refusal)), | 283 | + Err(refusal) => return redirect_back(cx, "/settings?section=links", "revoke", Some(refusal)), |
| 284 | }; | 284 | }; |
| 285 | let store = app(cx).store; | 285 | let store = app(cx).store; |
| 286 | let mine = store | 286 | let mine = store |
| @@ -288,17 +288,17 @@ async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect { | |||
| 288 | .await | 288 | .await |
| 289 | .map_err(|_| Refusal::Unavailable); | 289 | .map_err(|_| Refusal::Unavailable); |
| 290 | let Ok(links) = mine else { | 290 | let Ok(links) = mine else { |
| 291 | - return redirect_back(cx, "/settings", "revoke", Some(Refusal::Unavailable)); | 291 | + return redirect_back(cx, "/settings?section=links", "revoke", Some(Refusal::Unavailable)); |
| 292 | }; | 292 | }; |
| 293 | if !links | 293 | if !links |
| 294 | .iter() | 294 | .iter() |
| 295 | .any(|link| link.id == input.id && link.created_by == user.id) | 295 | .any(|link| link.id == input.id && link.created_by == user.id) |
| 296 | { | 296 | { |
| 297 | - return redirect_back(cx, "/settings", "revoke", Some(Refusal::NotFound)); | 297 | + return redirect_back(cx, "/settings?section=links", "revoke", Some(Refusal::NotFound)); |
| 298 | } | 298 | } |
| 299 | match store.revoke_share_link(&input.id).await { | 299 | match store.revoke_share_link(&input.id).await { |
| 300 | - Ok(()) => redirect_back(cx, "/settings", "revoke", None), | 300 | + Ok(()) => redirect_back(cx, "/settings?section=links", "revoke", None), |
| 301 | - Err(error) => redirect_back(cx, "/settings", "revoke", Some(refusal_of(error))), | 301 | + Err(error) => redirect_back(cx, "/settings?section=links", "revoke", Some(refusal_of(error))), |
| 302 | } | 302 | } |
| 303 | } | 303 | } |
| 304 | 304 | ||
| @@ -1350,9 +1350,10 @@ pub(crate) async fn share_modal( | |||
| 1350 | Err(_) => return Ok(None), | 1350 | Err(_) => return Ok(None), |
| 1351 | }; | 1351 | }; |
| 1352 | let language = lang(cx).await; | 1352 | let language = lang(cx).await; |
| 1353 | - // The links this modal shows carry the public origin — the configured | 1353 | + // The links this modal shows carry the public origin — the admin-set |
| 1354 | - // `base_url` when the deployment names one, the bound address otherwise. | 1354 | + // `base_url` setting when one is stored, else the config chain: the |
| 1355 | - let origin = app(cx).config.public_origin(); | 1355 | + // file's `base_url`, else the bound address. |
| 1356 | + let origin = share_origin(cx).await; | ||
| 1356 | let store = app(cx).store.clone(); | 1357 | let store = app(cx).store.clone(); |
| 1357 | // The owned, live target: present, untrashed, and theirs. Anything else | 1358 | // The owned, live target: present, untrashed, and theirs. Anything else |
| 1358 | // opens nothing — a stranger learns not even whose it is. | 1359 | // opens nothing — a stranger learns not even whose it is. |
crates/in-web/tests/http.rsmodified+315 -7
| @@ -1736,7 +1736,7 @@ async fn link_create_without_the_flag_is_view_only() { | |||
| 1736 | "share modal showed no name: {}", | 1736 | "share modal showed no name: {}", |
| 1737 | named.text() | 1737 | named.text() |
| 1738 | ); | 1738 | ); |
| 1739 | - let settings = app.get("/settings", Some(&admin)).await; | 1739 | + let settings = app.get("/settings?section=links", Some(&admin)).await; |
| 1740 | assert_eq!(settings.status, StatusCode::OK, "{}", settings.text()); | 1740 | assert_eq!(settings.status, StatusCode::OK, "{}", settings.text()); |
| 1741 | assert!( | 1741 | assert!( |
| 1742 | settings.text().contains("file · plain.txt"), | 1742 | settings.text().contains("file · plain.txt"), |
| @@ -2407,6 +2407,14 @@ async fn settings_quota_and_disable_guards() { | |||
| 2407 | ) | 2407 | ) |
| 2408 | .await; | 2408 | .await; |
| 2409 | assert!(answer.accepted(), "quota refused: {:?}", answer.location); | 2409 | assert!(answer.accepted(), "quota refused: {:?}", answer.location); |
| 2410 | + assert!( | ||
| 2411 | + answer | ||
| 2412 | + .location | ||
| 2413 | + .as_deref() | ||
| 2414 | + .is_some_and(|location| location.contains("section=everyone")), | ||
| 2415 | + "quota left the Everyone section: {:?}", | ||
| 2416 | + answer.location | ||
| 2417 | + ); | ||
| 2410 | assert_eq!( | 2418 | assert_eq!( |
| 2411 | app.store.user(&bob_id).await.unwrap().unwrap().quota_bytes, | 2419 | app.store.user(&bob_id).await.unwrap().unwrap().quota_bytes, |
| 2412 | 2147483648 | 2420 | 2147483648 |
| @@ -2452,6 +2460,14 @@ async fn settings_quota_and_disable_guards() { | |||
| 2452 | ) | 2460 | ) |
| 2453 | .await; | 2461 | .await; |
| 2454 | assert!(answer.accepted(), "disable refused: {:?}", answer.location); | 2462 | assert!(answer.accepted(), "disable refused: {:?}", answer.location); |
| 2463 | + assert!( | ||
| 2464 | + answer | ||
| 2465 | + .location | ||
| 2466 | + .as_deref() | ||
| 2467 | + .is_some_and(|location| location.contains("section=everyone")), | ||
| 2468 | + "disable left the Everyone section: {:?}", | ||
| 2469 | + answer.location | ||
| 2470 | + ); | ||
| 2455 | let page = app.get("/settings", Some(&bob)).await; | 2471 | let page = app.get("/settings", Some(&bob)).await; |
| 2456 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 2472 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 2457 | assert!( | 2473 | assert!( |
| @@ -2487,7 +2503,7 @@ async fn share_links_carry_the_configured_base_url() { | |||
| 2487 | 2503 | ||
| 2488 | // The banner the mint redirects back to. | 2504 | // The banner the mint redirects back to. |
| 2489 | let page = app | 2505 | let page = app |
| 2490 | - .get(&format!("/settings?created={token}"), Some(&admin)) | 2506 | + .get(&format!("/settings?section=links&created={token}"), Some(&admin)) |
| 2491 | .await; | 2507 | .await; |
| 2492 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 2508 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 2493 | assert!( | 2509 | assert!( |
| @@ -2548,7 +2564,7 @@ async fn share_links_follow_the_bind_without_a_base_url() { | |||
| 2548 | // No `base_url`: the links say the address bound, as they always | 2564 | // No `base_url`: the links say the address bound, as they always |
| 2549 | // have. | 2565 | // have. |
| 2550 | let page = app | 2566 | let page = app |
| 2551 | - .get(&format!("/settings?created={token}"), Some(&admin)) | 2567 | + .get(&format!("/settings?section=links&created={token}"), Some(&admin)) |
| 2552 | .await; | 2568 | .await; |
| 2553 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 2569 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 2554 | assert!( | 2570 | assert!( |
| @@ -2559,6 +2575,289 @@ async fn share_links_follow_the_bind_without_a_base_url() { | |||
| 2559 | ); | 2575 | ); |
| 2560 | } | 2576 | } |
| 2561 | 2577 | ||
| 2578 | +/// Mints one link over `file` and returns the plaintext token — and the | ||
| 2579 | +/// mint must land back on the links section that renders its banner. | ||
| 2580 | +async fn minted_token(app: &TestApp, cookie: &str, file: &str) -> String { | ||
| 2581 | + let answer = app | ||
| 2582 | + .post( | ||
| 2583 | + "/api/share/link/create", | ||
| 2584 | + Some(cookie), | ||
| 2585 | + &[("kind", "file"), ("target_id", file), ("can_download", "1")], | ||
| 2586 | + ) | ||
| 2587 | + .await; | ||
| 2588 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 2589 | + assert!( | ||
| 2590 | + answer | ||
| 2591 | + .location | ||
| 2592 | + .as_deref() | ||
| 2593 | + .is_some_and(|location| location.contains("section=links")), | ||
| 2594 | + "create left the links section: {:?}", | ||
| 2595 | + answer.location | ||
| 2596 | + ); | ||
| 2597 | + created_token(answer.location.as_deref().unwrap()) | ||
| 2598 | +} | ||
| 2599 | + | ||
| 2600 | +/// The rail splits the page: every signed-in reader sees Profile and Share | ||
| 2601 | +/// links, an admin additionally Everyone and Server — and an admin URL a | ||
| 2602 | +/// non-admin pastes renders the profile, leaking no rows and no form. | ||
| 2603 | +#[tokio::test] | ||
| 2604 | +async fn settings_rail_gates_the_admin_sections() { | ||
| 2605 | + let app = TestApp::build().await; | ||
| 2606 | + let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2607 | + let bob = app.sign_in("sub-bob", "bob@in.test", "Bob").await; | ||
| 2608 | + | ||
| 2609 | + // An admin's rail carries all four sections, and the default page is | ||
| 2610 | + // the profile alone. | ||
| 2611 | + let page = app.get("/settings", Some(&admin)).await; | ||
| 2612 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2613 | + let body = page.text(); | ||
| 2614 | + for section in ["profile", "links", "everyone", "server"] { | ||
| 2615 | + assert!( | ||
| 2616 | + body.contains(&format!("/settings?section={section}")), | ||
| 2617 | + "admin rail lacks {section}: {body}" | ||
| 2618 | + ); | ||
| 2619 | + } | ||
| 2620 | + assert!(body.contains("name=\"ui\""), "{}", body); | ||
| 2621 | + assert!(!body.contains("member-table"), "{}", body); | ||
| 2622 | + assert!(!body.contains("/api/settings/base_url"), "{}", body); | ||
| 2623 | + | ||
| 2624 | + // A non-admin's rail stops at the reader sections. | ||
| 2625 | + let page = app.get("/settings", Some(&bob)).await; | ||
| 2626 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2627 | + let body = page.text(); | ||
| 2628 | + assert!(body.contains("/settings?section=profile"), "{}", body); | ||
| 2629 | + assert!(body.contains("/settings?section=links"), "{}", body); | ||
| 2630 | + assert!(!body.contains("/settings?section=everyone"), "{}", body); | ||
| 2631 | + assert!(!body.contains("/settings?section=server"), "{}", body); | ||
| 2632 | + | ||
| 2633 | + // An admin URL pasted by a non-admin answers the profile: no account | ||
| 2634 | + // rows, no address form, no origin. | ||
| 2635 | + for asked in ["everyone", "server"] { | ||
| 2636 | + let page = app | ||
| 2637 | + .get(&format!("/settings?section={asked}"), Some(&bob)) | ||
| 2638 | + .await; | ||
| 2639 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2640 | + let body = page.text(); | ||
| 2641 | + assert!(body.contains("name=\"ui\""), "not the profile: {body}"); | ||
| 2642 | + assert!(!body.contains("member-table"), "{body}"); | ||
| 2643 | + assert!(!body.contains("/api/settings/base_url"), "{body}"); | ||
| 2644 | + } | ||
| 2645 | +} | ||
| 2646 | + | ||
| 2647 | +/// Each section renders alone on its own `?section=` pair — the profile's | ||
| 2648 | +/// preferences form, the links panel, the Everyone register, the server | ||
| 2649 | +/// address form — and never a row or form belonging to another. | ||
| 2650 | +#[tokio::test] | ||
| 2651 | +async fn admin_settings_sections_render_alone() { | ||
| 2652 | + let app = TestApp::build().await; | ||
| 2653 | + let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2654 | + let owner = owner_of(&app, "sub-admin").await; | ||
| 2655 | + let file = file_id(&app, &owner, "notes.txt", b"hello in").await; | ||
| 2656 | + app.store | ||
| 2657 | + .create_share_link(&owner, ShareKind::File, &file, true, None, None) | ||
| 2658 | + .await | ||
| 2659 | + .unwrap(); | ||
| 2660 | + | ||
| 2661 | + let body = app.get("/settings?section=profile", Some(&admin)).await.text(); | ||
| 2662 | + assert!(body.contains("name=\"ui\""), "{body}"); | ||
| 2663 | + assert!(!body.contains("/api/share/link/revoke"), "{body}"); | ||
| 2664 | + assert!(!body.contains("member-table"), "{body}"); | ||
| 2665 | + assert!(!body.contains("/api/settings/base_url"), "{body}"); | ||
| 2666 | + | ||
| 2667 | + let body = app.get("/settings?section=links", Some(&admin)).await.text(); | ||
| 2668 | + assert!(body.contains("action=\"/api/share/link/revoke\""), "{body}"); | ||
| 2669 | + assert!(!body.contains("name=\"ui\""), "{body}"); | ||
| 2670 | + assert!(!body.contains("member-table"), "{body}"); | ||
| 2671 | + assert!(!body.contains("/api/settings/base_url"), "{body}"); | ||
| 2672 | + | ||
| 2673 | + let body = app.get("/settings?section=everyone", Some(&admin)).await.text(); | ||
| 2674 | + assert!(body.contains("member-table"), "{body}"); | ||
| 2675 | + assert!(body.contains("ada@in.test"), "{body}"); | ||
| 2676 | + assert!(!body.contains("name=\"ui\""), "{body}"); | ||
| 2677 | + assert!(!body.contains("/api/share/link/revoke"), "{body}"); | ||
| 2678 | + assert!(!body.contains("/api/settings/base_url"), "{body}"); | ||
| 2679 | + | ||
| 2680 | + let body = app.get("/settings?section=server", Some(&admin)).await.text(); | ||
| 2681 | + assert!(body.contains("action=\"/api/settings/base_url\""), "{body}"); | ||
| 2682 | + // The effective origin shows before anything is stored: the bind. | ||
| 2683 | + assert!(body.contains("http://127.0.0.1:7655"), "{body}"); | ||
| 2684 | + assert!(!body.contains("name=\"ui\""), "{body}"); | ||
| 2685 | + assert!(!body.contains("member-table"), "{body}"); | ||
| 2686 | + assert!(!body.contains("/api/share/link/revoke"), "{body}"); | ||
| 2687 | +} | ||
| 2688 | + | ||
| 2689 | +/// The admin's server-address form: a valid origin stores the `base_url` | ||
| 2690 | +/// setting and every newly minted link carries it; a value with no scheme | ||
| 2691 | +/// or a trailing slash is refused with the setting untouched; saving empty | ||
| 2692 | +/// clears it and the links fall back to the address bound. A non-admin is | ||
| 2693 | +/// refused before anything is read. | ||
| 2694 | +#[tokio::test] | ||
| 2695 | +async fn server_address_setting_drives_share_links() { | ||
| 2696 | + let app = TestApp::build().await; | ||
| 2697 | + let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2698 | + let bob = app.sign_in("sub-bob", "bob@in.test", "Bob").await; | ||
| 2699 | + let owner = owner_of(&app, "sub-admin").await; | ||
| 2700 | + let file = file_id(&app, &owner, "notes.txt", b"hello in").await; | ||
| 2701 | + | ||
| 2702 | + let answer = app | ||
| 2703 | + .post( | ||
| 2704 | + "/api/settings/base_url", | ||
| 2705 | + Some(&bob), | ||
| 2706 | + &[("base_url", "https://bob.example.net")], | ||
| 2707 | + ) | ||
| 2708 | + .await; | ||
| 2709 | + assert!( | ||
| 2710 | + answer.refused("forbidden", "base_url"), | ||
| 2711 | + "{:?}", | ||
| 2712 | + answer.location | ||
| 2713 | + ); | ||
| 2714 | + assert_eq!(app.store.get_setting("base_url").await.unwrap(), None); | ||
| 2715 | + | ||
| 2716 | + let answer = app | ||
| 2717 | + .post( | ||
| 2718 | + "/api/settings/base_url", | ||
| 2719 | + Some(&admin), | ||
| 2720 | + &[("base_url", "https://files.example.com")], | ||
| 2721 | + ) | ||
| 2722 | + .await; | ||
| 2723 | + assert!(answer.accepted(), "save refused: {:?}", answer.location); | ||
| 2724 | + assert!( | ||
| 2725 | + answer.location.as_deref().is_some_and(|location| { | ||
| 2726 | + location.contains("section=server") && location.contains("saved=base_url") | ||
| 2727 | + }), | ||
| 2728 | + "{:?}", | ||
| 2729 | + answer.location | ||
| 2730 | + ); | ||
| 2731 | + assert_eq!( | ||
| 2732 | + app.store.get_setting("base_url").await.unwrap().as_deref(), | ||
| 2733 | + Some("https://files.example.com") | ||
| 2734 | + ); | ||
| 2735 | + let token = minted_token(&app, &admin, &file).await; | ||
| 2736 | + let page = app | ||
| 2737 | + .get( | ||
| 2738 | + &format!("/settings?section=links&created={token}"), | ||
| 2739 | + Some(&admin), | ||
| 2740 | + ) | ||
| 2741 | + .await; | ||
| 2742 | + assert!( | ||
| 2743 | + page | ||
| 2744 | + .text() | ||
| 2745 | + .contains(&format!("https://files.example.com/s/{token}")), | ||
| 2746 | + "{}", | ||
| 2747 | + page.text() | ||
| 2748 | + ); | ||
| 2749 | + | ||
| 2750 | + // No scheme, or a trailing slash: refused, the stored value untouched. | ||
| 2751 | + for bad in ["files.example.com", "https://files.example.com/"] { | ||
| 2752 | + let answer = app | ||
| 2753 | + .post("/api/settings/base_url", Some(&admin), &[("base_url", bad)]) | ||
| 2754 | + .await; | ||
| 2755 | + assert!( | ||
| 2756 | + answer.refused("bad-base-url", "base_url"), | ||
| 2757 | + "{bad}: {:?}", | ||
| 2758 | + answer.location | ||
| 2759 | + ); | ||
| 2760 | + } | ||
| 2761 | + assert_eq!( | ||
| 2762 | + app.store.get_setting("base_url").await.unwrap().as_deref(), | ||
| 2763 | + Some("https://files.example.com"), | ||
| 2764 | + "a refused save changed the setting" | ||
| 2765 | + ); | ||
| 2766 | + | ||
| 2767 | + // Empty clears: the links fall back to the address bound. | ||
| 2768 | + let answer = app | ||
| 2769 | + .post("/api/settings/base_url", Some(&admin), &[("base_url", "")]) | ||
| 2770 | + .await; | ||
| 2771 | + assert!(answer.accepted(), "clear refused: {:?}", answer.location); | ||
| 2772 | + assert_eq!( | ||
| 2773 | + app.store.get_setting("base_url").await.unwrap().as_deref(), | ||
| 2774 | + Some("") | ||
| 2775 | + ); | ||
| 2776 | + let token = minted_token(&app, &admin, &file).await; | ||
| 2777 | + let page = app | ||
| 2778 | + .get( | ||
| 2779 | + &format!("/settings?section=links&created={token}"), | ||
| 2780 | + Some(&admin), | ||
| 2781 | + ) | ||
| 2782 | + .await; | ||
| 2783 | + let body = page.text(); | ||
| 2784 | + assert!( | ||
| 2785 | + body.contains(&format!("http://127.0.0.1:7655/s/{token}")), | ||
| 2786 | + "{body}" | ||
| 2787 | + ); | ||
| 2788 | + assert!(!body.contains("https://files.example.com"), "{body}"); | ||
| 2789 | +} | ||
| 2790 | + | ||
| 2791 | +/// Clearing a stored origin falls back to the config's `base_url` when the | ||
| 2792 | +/// file sets one: the setting wins only while it is non-empty. | ||
| 2793 | +#[tokio::test] | ||
| 2794 | +async fn cleared_setting_falls_back_to_the_configured_base_url() { | ||
| 2795 | + let app = TestApp::build_with(Some("https://cfg.example.com")).await; | ||
| 2796 | + let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2797 | + let owner = owner_of(&app, "sub-admin").await; | ||
| 2798 | + let file = file_id(&app, &owner, "notes.txt", b"hello in").await; | ||
| 2799 | + | ||
| 2800 | + let answer = app | ||
| 2801 | + .post( | ||
| 2802 | + "/api/settings/base_url", | ||
| 2803 | + Some(&admin), | ||
| 2804 | + &[("base_url", "https://override.example.com")], | ||
| 2805 | + ) | ||
| 2806 | + .await; | ||
| 2807 | + assert!(answer.accepted(), "save refused: {:?}", answer.location); | ||
| 2808 | + let token = minted_token(&app, &admin, &file).await; | ||
| 2809 | + let page = app | ||
| 2810 | + .get( | ||
| 2811 | + &format!("/settings?section=links&created={token}"), | ||
| 2812 | + Some(&admin), | ||
| 2813 | + ) | ||
| 2814 | + .await; | ||
| 2815 | + assert!( | ||
| 2816 | + page | ||
| 2817 | + .text() | ||
| 2818 | + .contains(&format!("https://override.example.com/s/{token}")), | ||
| 2819 | + "{}", | ||
| 2820 | + page.text() | ||
| 2821 | + ); | ||
| 2822 | + | ||
| 2823 | + let answer = app | ||
| 2824 | + .post("/api/settings/base_url", Some(&admin), &[("base_url", "")]) | ||
| 2825 | + .await; | ||
| 2826 | + assert!(answer.accepted(), "clear refused: {:?}", answer.location); | ||
| 2827 | + let token = minted_token(&app, &admin, &file).await; | ||
| 2828 | + let page = app | ||
| 2829 | + .get( | ||
| 2830 | + &format!("/settings?section=links&created={token}"), | ||
| 2831 | + Some(&admin), | ||
| 2832 | + ) | ||
| 2833 | + .await; | ||
| 2834 | + let body = page.text(); | ||
| 2835 | + assert!( | ||
| 2836 | + body.contains(&format!("https://cfg.example.com/s/{token}")), | ||
| 2837 | + "{body}" | ||
| 2838 | + ); | ||
| 2839 | + assert!(!body.contains("override.example.com"), "{body}"); | ||
| 2840 | +} | ||
| 2841 | + | ||
| 2842 | +/// A revoke lands back on the links section that hosts its rows, even for | ||
| 2843 | +/// a post arriving without a `Referer` to return to. | ||
| 2844 | +#[tokio::test] | ||
| 2845 | +async fn revoke_redirects_land_on_the_links_section() { | ||
| 2846 | + let app = TestApp::build().await; | ||
| 2847 | + let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2848 | + let answer = app | ||
| 2849 | + .post("/api/share/link/revoke", Some(&admin), &[("id", "never-real")]) | ||
| 2850 | + .await; | ||
| 2851 | + assert!( | ||
| 2852 | + answer | ||
| 2853 | + .location | ||
| 2854 | + .as_deref() | ||
| 2855 | + .is_some_and(|location| location.contains("/settings?section=links")), | ||
| 2856 | + "{:?}", | ||
| 2857 | + answer.location | ||
| 2858 | + ); | ||
| 2859 | +} | ||
| 2860 | + | ||
| 2562 | /// The revoke control is one inline quiet button at the row's end, like | 2861 | /// The revoke control is one inline quiet button at the row's end, like |
| 2563 | /// the modal's remove-access rows — not a full-width block of its own. | 2862 | /// the modal's remove-access rows — not a full-width block of its own. |
| 2564 | #[tokio::test] | 2863 | #[tokio::test] |
| @@ -2572,7 +2871,7 @@ async fn the_settings_revoke_button_sits_inline_in_its_row() { | |||
| 2572 | .await | 2871 | .await |
| 2573 | .unwrap(); | 2872 | .unwrap(); |
| 2574 | 2873 | ||
| 2575 | - let body = app.get("/settings", Some(&admin)).await.text(); | 2874 | + let body = app.get("/settings?section=links", Some(&admin)).await.text(); |
| 2576 | let row_at = body | 2875 | let row_at = body |
| 2577 | .find("<div class=\"member-row\">") | 2876 | .find("<div class=\"member-row\">") |
| 2578 | .expect("no share-link row"); | 2877 | .expect("no share-link row"); |
| @@ -3529,11 +3828,20 @@ async fn settings_panels_nest_inside_the_stage() { | |||
| 3529 | .find("<main class=\"settings-stage") | 3828 | .find("<main class=\"settings-stage") |
| 3530 | .expect("no settings-stage"); | 3829 | .expect("no settings-stage"); |
| 3531 | let close = body.find("</main>").expect("no main close"); | 3830 | let close = body.find("</main>").expect("no main close"); |
| 3532 | - for marker in ["panel-head", "member-table", "name=\"ui\""] { | 3831 | + for marker in ["panel-head", "name=\"ui\""] { |
| 3533 | let at = body.find(marker).unwrap_or_else(|| panic!("no {marker}")); | 3832 | let at = body.find(marker).unwrap_or_else(|| panic!("no {marker}")); |
| 3534 | assert!(stage < at && at < close, "{marker} escapes the stage"); | 3833 | assert!(stage < at && at < close, "{marker} escapes the stage"); |
| 3535 | } | 3834 | } |
| 3536 | - // The admin register is a table now: one named column per fact. | 3835 | + // The admin register keeps its named columns, on its own section. |
| 3836 | + let page = app.get("/settings?section=everyone", Some(&admin)).await; | ||
| 3837 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 3838 | + let body = page.text(); | ||
| 3839 | + let stage = body | ||
| 3840 | + .find("<main class=\"settings-stage") | ||
| 3841 | + .expect("no settings-stage"); | ||
| 3842 | + let close = body.find("</main>").expect("no main close"); | ||
| 3843 | + let at = body.find("member-table").expect("no member-table"); | ||
| 3844 | + assert!(stage < at && at < close, "member-table escapes the stage"); | ||
| 3537 | assert!(body.contains("<th class=\"member-col-name\""), "{body}"); | 3845 | assert!(body.contains("<th class=\"member-col-name\""), "{body}"); |
| 3538 | } | 3846 | } |
| 3539 | 3847 | ||
| @@ -3685,7 +3993,7 @@ async fn settings_quota_button_wears_the_quiet_class() { | |||
| 3685 | let admin = app | 3993 | let admin = app |
| 3686 | .sign_in("sub-quota-btn", "quotabtn@in.test", "QuotaBtn") | 3994 | .sign_in("sub-quota-btn", "quotabtn@in.test", "QuotaBtn") |
| 3687 | .await; | 3995 | .await; |
| 3688 | - let page = app.get("/settings", Some(&admin)).await; | 3996 | + let page = app.get("/settings?section=everyone", Some(&admin)).await; |
| 3689 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 3997 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 3690 | let body = page.text(); | 3998 | let body = page.text(); |
| 3691 | // The Set-the-quota submit is a house button in a field row, not a | 3999 | // The Set-the-quota submit is a house button in a field row, not a |