From 794c3a4ba91fcccf6a6ea568c8b9a0c94428a5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 3 Sep 2026 08:04:22 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20confirm=20disclosures,=20split=20From?= =?UTF-8?q?=20name,=20and=20the=20live=20channel=20=E2=80=94=20iz=20parity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Row actions are two-step disclosures now (iz's confirm-details idiom): Disable/Enable and Delete open a panel naming the cost, and only the button inside it acts. No script required; outside-click/Escape closing rides the live script. - The sender's From splits into name + address like iz's; the header is built from the two, never hand-typed as one string. - The live channel, ported from iz: /admin/live SSE ticks (no data on the wire, ever), a 50-minute window so reconnects re-authenticate, and a shutdown watch so one open tab per admin cannot stall a restart. The client refetches and swaps the panel column, suspending while a field has focus. Every event log ticks it, so Users and Logs update the moment anything happens — including the mail chip after a save's background probe. Verified: suite 39 green; driven with two tabs — an invite's row and an accepted member appear without a reload, Logs grows 21→22 on a triggered check, and Delete needs its confirm step. --- Cargo.lock | 1 + crates/im-core/src/settings.rs | 26 +++++- crates/im-web/Cargo.toml | 2 + crates/im-web/assets/main.css | 38 +++++++++ crates/im-web/src/admin.rs | 143 +++++++++++++++++++++++++++------ crates/im-web/src/auth.rs | 12 +-- crates/im-web/src/live.rs | 104 ++++++++++++++++++++++++ crates/im-web/src/mailer.rs | 2 +- crates/im-web/src/main.rs | 19 +++-- crates/im-web/src/oidc.rs | 3 +- crates/im-web/src/server.rs | 17 ++++ style/main.scss | 34 ++++++++ 12 files changed, 359 insertions(+), 42 deletions(-) create mode 100644 crates/im-web/src/live.rs diff --git a/Cargo.lock b/Cargo.lock index 0bc3871..7edf8be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1823,6 +1823,7 @@ version = "0.1.0" dependencies = [ "base64 0.22.1", "data-encoding", + "futures-util", "grass", "http", "im-core", diff --git a/crates/im-core/src/settings.rs b/crates/im-core/src/settings.rs index 257668c..d6af118 100644 --- a/crates/im-core/src/settings.rs +++ b/crates/im-core/src/settings.rs @@ -13,7 +13,12 @@ pub struct Smtp { pub host: String, pub port: u16, pub username: String, + /// The address mail goes out as. pub from: String, + /// The name the address wears in a mail client's list — iz keeps the two + /// apart, and so do we: "im " is a header built from two settings, + /// not one string somebody has to get right. + pub from_name: String, pub password: Option, } @@ -21,6 +26,15 @@ impl Smtp { pub fn configured(&self) -> bool { !self.host.is_empty() && self.port > 0 && !self.from.is_empty() } + + /// The From header: `Name
` when a name is set, the bare + /// address otherwise. + pub fn from_header(&self) -> String { + match self.from_name.trim() { + "" => self.from.clone(), + name => format!("{name} <{}>", self.from), + } + } } async fn get(store: &Store, key: &str) -> Result> { @@ -62,6 +76,7 @@ pub async fn smtp(store: &Store) -> Result { .unwrap_or(587); let username = get(store, "smtp_username").await?.unwrap_or_default(); let from = get(store, "smtp_from").await?.unwrap_or_default(); + let from_name = get(store, "smtp_from_name").await?.unwrap_or_default(); let password = get(store, "smtp_password") .await? .and_then(|sealed| secret::open(store.key(), &sealed)) @@ -71,6 +86,7 @@ pub async fn smtp(store: &Store) -> Result { port, username, from, + from_name, password, }) } @@ -180,7 +196,7 @@ pub async fn set_smtp(store: &Store, smtp: &Smtp, password: Option<&str>) -> Res "smtp_port", "smtp_username", "smtp_from", - "smtp_password", + "smtp_from_name", "smtp_check_at", "smtp_check_ms", "smtp_check_error", @@ -199,6 +215,7 @@ pub async fn set_smtp(store: &Store, smtp: &Smtp, password: Option<&str>) -> Res set(store, "smtp_port", &smtp.port.to_string()).await?; set(store, "smtp_username", &smtp.username).await?; set(store, "smtp_from", &smtp.from).await?; + set(store, "smtp_from_name", &smtp.from_name).await?; if let Some(password) = password { if !password.is_empty() { set( @@ -227,7 +244,8 @@ mod tests { host: "smtp.example.com".into(), port: 465, username: "im".into(), - from: "im ".into(), + from: "auth@example.com".into(), + from_name: "im".into(), password: None, }; set_smtp(&store, &value, Some("s3cret")).await.unwrap(); @@ -259,6 +277,7 @@ mod tests { port: 465, username: String::new(), from: "a@b.c".into(), + from_name: String::new(), password: None, }; set_smtp(&store, &value, Some("s3cret")).await.unwrap(); @@ -282,7 +301,8 @@ mod tests { host: "smtp.example.com".into(), port: 587, username: "auth@example.com".into(), - from: "im ".into(), + from: "auth@example.com".into(), + from_name: "im".into(), password: None, }; set_smtp(&store, &value, Some("s3cret")).await.unwrap(); diff --git a/crates/im-web/Cargo.toml b/crates/im-web/Cargo.toml index a018371..8a2dfb7 100644 --- a/crates/im-web/Cargo.toml +++ b/crates/im-web/Cargo.toml @@ -17,7 +17,9 @@ topcoat = { version = "0.6.2", default-features = false, features = [ "discover", "serve", "compression", + "sse", ] } +futures-util = { version = "0.3", default-features = false } im-core = { workspace = true, features = ["server"] } serde.workspace = true serde_json.workspace = true diff --git a/crates/im-web/assets/main.css b/crates/im-web/assets/main.css index cc8bc61..74bfec9 100644 --- a/crates/im-web/assets/main.css +++ b/crates/im-web/assets/main.css @@ -546,6 +546,44 @@ body:has(.admin-shell) { background: var(--danger-tint-alt); } +.admin-confirm { + position: relative; +} +.admin-confirm summary { + list-style: none; +} +.admin-confirm summary::-webkit-details-marker { + display: none; +} +.admin-confirm[open] summary { + background: var(--panel-sunken); +} + +.admin-confirm-pop { + position: absolute; + right: 0; + top: calc(100% + 6px); + z-index: 30; + width: 240px; + padding: 12px; + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: var(--radius); + display: flex; + flex-direction: column; + gap: 8px; + font-size: 12px; +} +.admin-confirm-pop .admin-action { + width: 100%; + height: 30px; +} + +.admin-confirm-title { + font-weight: 600; + color: var(--ink); +} + input[type=checkbox] { accent-color: var(--accent); } diff --git a/crates/im-web/src/admin.rs b/crates/im-web/src/admin.rs index 9db20d5..7a7669a 100644 --- a/crates/im-web/src/admin.rs +++ b/crates/im-web/src/admin.rs @@ -45,6 +45,63 @@ fn escape(raw: &str) -> String { .replace('"', """) } +/// One row action as a two-step disclosure — iz's `confirm-details` idiom: +/// the summary is the word ("Delete"), the opened panel says what it costs +/// and holds the button that actually does it. Works with no script at all; +/// the live script adds outside-click closing. +fn confirm_action( + id: &str, + action: &str, + word: &str, + extra_class: &str, + title: &str, + cost: &str, + confirm: &str, +) -> String { + format!( + r#"
{word}
{title}
{cost}
"# + ) +} +/// The panel's live wiring, the client half of `live.rs`. One EventSource +/// per tab; a tick re-fetches the page and swaps the panel's body. iz's +/// lesson is honored in miniature: the swap must not throw away what someone +/// is doing, so a focused field suspends the refresh until the next tick, +/// and the morph is one innerHTML swap of the column — small DOM, no diffing +/// library needed. +/// +/// The same script closes an open confirm disclosure on outside click and +/// Escape — the one bit of behavior the no-script markup cannot do itself. +const LIVE_SCRIPT: &str = r#""#; + fn back(cx: &Cx, section: &str, extra: &str) -> Result { ( StatusCode::SEE_OTHER, @@ -136,6 +193,7 @@ async fn admin_page(cx: &Cx) -> Result { (topcoat::view::Unescaped::new_unchecked(banner)) } (topcoat::view::Unescaped::new_unchecked(section_html)) + (topcoat::view::Unescaped::new_unchecked(LIVE_SCRIPT.to_string())) }; @@ -191,17 +249,43 @@ async fn users_section( r#"you"#.to_string() } else { let id = escape(&user.id.to_string()); + let email = escape(&user.email); + // Every row action is a two-step disclosure — iz's + // confirm-details idiom: the summary is the word, the panel holds + // the button that actually does it. No script required; the live + // script adds outside-click closing on top. let toggle = if user.disabled { - format!( - r#"
"# + confirm_action( + &id, + "/admin/enable", + "Enable", + "", + &format!("Enable {email}?"), + "They can sign in again.", + "Confirm enable", ) } else { - format!( - r#"
"# + confirm_action( + &id, + "/admin/disable", + "Disable", + "", + &format!("Disable {email}?"), + "They cannot sign in, and every live session ends.", + "Confirm disable", ) }; + let remove = confirm_action( + &id, + "/admin/delete", + "Delete", + " admin-danger", + &format!("Delete {email}?"), + "The account, its sessions and every app token go with it. The address can be invited again, as somebody new.", + "Confirm delete", + ); format!( - r#"{toggle}
"# + r#"{toggle}
{remove}"# ) }; rows.push_str(&format!( @@ -322,8 +406,10 @@ async fn mail_section(cx: &Cx) -> Result { - + + {lede_html} @@ -335,6 +421,7 @@ async fn mail_section(cx: &Cx) -> Result { escape(&smtp.host), smtp.port, escape(&smtp.username), + escape(&smtp.from_name), escape(&smtp.from) )) } @@ -393,8 +480,8 @@ async fn invite(cx: &Cx, Form(input): Form) -> Result { let mailed = mailer::send_invite(store, &app(cx).config.issuer, &email, token.expose()) .await .is_ok(); - events::log( - store, + server::log_event( + cx, "invite_created", Some(&me.email), Some(&format!( @@ -429,7 +516,7 @@ async fn uninvite(cx: &Cx, Form(input): Form) -> Result }; let store = &app(cx).store; let email = accounts::revoke_invite(store, &input.invite).await?; - events::log(store, "invite_revoked", Some(&me.email), email.as_deref()).await; + server::log_event(cx, "invite_revoked", Some(&me.email), email.as_deref()).await; back(cx, "users", "&ok=uninvited") } @@ -448,7 +535,7 @@ async fn delete(cx: &Cx, Form(input): Form) -> Result { .await? .map(|u| u.email); accounts::delete_user(store, &user_id).await?; - events::log(store, "user_deleted", Some(&me.email), email.as_deref()).await; + server::log_event(cx, "user_deleted", Some(&me.email), email.as_deref()).await; back(cx, "users", "&ok=deleted") } @@ -488,7 +575,7 @@ async fn password(cx: &Cx, Form(input): Form) -> Result if let Some(token) = server::presented_session(cx) { im_core::sessions::revoke_user_sessions_except(store, &me.id, &token).await?; } - events::log(store, "password_changed", Some(&me.email), None).await; + server::log_event(cx, "password_changed", Some(&me.email), None).await; back(cx, "account", "&ok=password") } #[derive(Deserialize)] @@ -508,8 +595,8 @@ async fn revoke(cx: &Cx, Form(input): Form) -> Result { let email = accounts::user_by_id(store, &user_id) .await? .map(|u| u.email); - events::log( - store, + server::log_event( + cx, "sessions_revoked", Some(&me.email), Some(&format!( @@ -546,8 +633,8 @@ async fn set_disabled(cx: &Cx, input: UserAction, disabled: bool) -> Result, + #[serde(default)] + from_name: String, from: String, } @@ -589,13 +678,14 @@ async fn smtp_save(cx: &Cx, Form(input): Form) -> Result { port: input.port, username: input.username.trim().to_string(), from: input.from.trim().to_string(), + from_name: input.from_name.trim().to_string(), password: None, }; settings::set_smtp(store, &value, input.password.as_deref()).await?; - events::log(store, "smtp_updated", Some(&me.email), None).await; + server::log_event(cx, "smtp_updated", Some(&me.email), None).await; // The saved sender gets re-probed in the background — the standing line // on the Mail section catches up on the next view, like izlek's panel. - tokio::spawn(probe(store_of(cx))); + tokio::spawn(probe(store_of(cx), app(cx).live.clone())); back(cx, "mail", "&ok=smtp") } @@ -607,12 +697,12 @@ async fn smtp_test(cx: &Cx) -> Result { }; match mailer::send_test(&app(cx).store, &me.email).await { Ok(()) => { - events::log(&app(cx).store, "smtp_test_sent", Some(&me.email), None).await; + server::log_event(cx, "smtp_test_sent", Some(&me.email), None).await; back(cx, "mail", "&ok=smtp_test") } Err(e) => { - events::log( - &app(cx).store, + server::log_event( + cx, "smtp_test_failed", Some(&me.email), Some(&e.to_string()), @@ -638,8 +728,8 @@ async fn smtp_check(cx: &Cx) -> Result { Ok(me) => me, Err(redirect) => return Ok(redirect), }; - probe(store_of(cx)).await; - events::log(&app(cx).store, "smtp_checked", Some(&me.email), None).await; + probe(store_of(cx), app(cx).live.clone()).await; + server::log_event(cx, "smtp_checked", Some(&me.email), None).await; back(cx, "mail", "") } @@ -651,7 +741,10 @@ fn store_of(cx: &Cx) -> std::sync::Arc { /// and the after-save probe: a saved sender is re-probed in the background, /// so the standing line catches up on the next view without making the save /// itself wait on a mail server. -async fn probe(store: std::sync::Arc) { +async fn probe( + store: std::sync::Arc, + live: tokio::sync::broadcast::Sender<()>, +) { let check = match mailer::check(&store).await { Ok(took_ms) => settings::SenderCheck { at: time::OffsetDateTime::now_utc(), @@ -667,4 +760,6 @@ async fn probe(store: std::sync::Arc) { if let Err(problem) = settings::record_check(&store, &check).await { eprintln!("im: failed to record the sender check: {problem}"); } + // The chip changed; watching tabs re-read it on the next tick. + let _ = live.send(()); } diff --git a/crates/im-web/src/auth.rs b/crates/im-web/src/auth.rs index 049ebc2..fce9214 100644 --- a/crates/im-web/src/auth.rs +++ b/crates/im-web/src/auth.rs @@ -76,7 +76,7 @@ async fn login(cx: &Cx, Form(input): Form) -> Redirect { Err(_) => { // The failure is logged against the address tried, never the // password — and never whether the address exists. - im_core::events::log(store, "login_fail", Some(&input.email), None).await; + server::log_event(cx, "login_fail", Some(&input.email), None).await; see(format!("/login?error=bad_login&back={}", urlencode(&back))) } } @@ -112,14 +112,14 @@ async fn login_totp(cx: &Cx, Form(input): Form) -> Redirect { None => false, }; if !ok { - im_core::events::log(store, "totp_fail", None, Some("login")).await; + server::log_event(cx, "totp_fail", None, Some("login")).await; return see("/login/totp?error=bad_code".to_string()); } let token = im_core::sessions::create_session(store, &user_id).await?; let email = accounts::user_by_id(store, &user_id) .await? .map(|u| u.email); - im_core::events::log(store, "login_ok", email.as_deref(), Some("2fa")).await; + server::log_event(cx, "login_ok", email.as_deref(), Some("2fa")).await; server::clear_pending_cookie(cx); server::set_session_cookie(cx, token.expose()); see(pending.back) @@ -175,7 +175,7 @@ async fn invite(cx: &Cx, Form(input): Form) -> Redirect { im_core::totp::set_totp(store, &user.id, &secret).await?; let sealed = server::mint_pending(cx, &user.id, PendingPurpose::Enroll, "/".to_string()); server::set_pending_cookie(cx, sealed); - im_core::events::log(store, "invite_accepted", Some(&user.email), None).await; + server::log_event(cx, "invite_accepted", Some(&user.email), None).await; see("/enroll".to_string()) } @@ -200,7 +200,7 @@ async fn enroll(cx: &Cx, Form(input): Form) -> Redirect { let email = accounts::user_by_id(store, &user_id) .await? .map(|u| u.email); - im_core::events::log(store, "enrolled", email.as_deref(), None).await; + server::log_event(cx, "enrolled", email.as_deref(), None).await; server::clear_pending_cookie(cx); server::set_session_cookie(cx, token.expose()); // A migrated user who was mid-`/authorize` continues to their app; a @@ -221,7 +221,7 @@ async fn logout(cx: &Cx) -> Redirect { .await? .map(|u| u.email); im_core::sessions::revoke_session(&server::app(cx).store, &token).await?; - im_core::events::log(&server::app(cx).store, "logout", email.as_deref(), None).await; + server::log_event(cx, "logout", email.as_deref(), None).await; } server::clear_session_cookie(cx); see("/".to_string()) diff --git a/crates/im-web/src/live.rs b/crates/im-web/src/live.rs new file mode 100644 index 0000000..111445f --- /dev/null +++ b/crates/im-web/src/live.rs @@ -0,0 +1,104 @@ +//! The live channel: one long-lived connection per open admin tab, carrying +//! the news that something changed — ported from iz's `live.rs`. +//! +//! What travels here is a bare tick and nothing else — never a row, never a +//! name. The client is told only *that* the panel moved, and re-fetches it +//! through the ordinary route, where the ordinary admin gate answers. The +//! route itself is admin-gated, and the whole panel behind it is admin-only, +//! so there is no per-topic filtering to get wrong. + +use std::time::{Duration, Instant}; + +use futures_util::StreamExt; +use tokio::sync::broadcast::error::RecvError; +use topcoat::context::Cx; +use topcoat::router::content::sse::{Event, KeepAlive, Sse}; +use topcoat::router::response::{IntoResponse, Response}; +use topcoat::router::{StatusCode, route}; + +use crate::server; + +/// How long one connection is held before the server ends it and the browser +/// opens another. The session is resolved once, at connect, and never again +/// for the life of the stream — the reconnect is what re-authenticates, so a +/// session revoked mid-stream goes quiet within one window rather than never. +const WINDOW: Duration = Duration::from_secs(50 * 60); + +/// Tells a live stream that the process is going down. +/// +/// Without this, stopping the server takes as long as its graceful shutdown +/// allows: the server stops accepting connections and then waits for +/// in-flight requests to finish, and an open live stream is an in-flight +/// request that intends to sit there for the whole window. Every open admin +/// tab is one. So the streams are told, and they end; the browser reconnects +/// when the server comes back, which is what it does after any dropped +/// connection. +#[derive(Clone)] +pub struct Shutdown(pub tokio::sync::watch::Receiver); + +#[route(GET "/admin/live")] +async fn live(cx: &Cx) -> topcoat::Result { + // Resolved once, here, and never again for the life of this connection. + let Ok(_admin) = server::current_user(cx) + .await + .filter(|user| user.admin) + .ok_or(()) + else { + return (StatusCode::UNAUTHORIZED, "").into_response(cx); + }; + let rx = server::app(cx).live.subscribe(); + let stopping = topcoat::context::try_app_context::(cx).map(|s| s.0.clone()); + let deadline = Instant::now() + WINDOW; + + let events = futures_util::stream::unfold( + (rx, deadline, stopping), + |(mut rx, deadline, mut stopping)| async move { + loop { + // Already going down: end, so this connection is not one the + // shutdown has to sit and wait out. + if stopping.as_ref().is_some_and(|watch| *watch.borrow()) { + return None; + } + let left = deadline.saturating_duration_since(Instant::now()); + if left.is_zero() { + return None; + } + // Three things end the wait: an announcement, the window + // running out, and the server being told to stop. The third + // is watched rather than polled, so SIGTERM is felt at once. + let heard = tokio::time::timeout(left, async { + match stopping.as_mut() { + Some(watch) => tokio::select! { + _ = watch.changed() => None, + got = rx.recv() => Some(got), + }, + None => Some(rx.recv().await), + } + }) + .await; + match heard { + // The window closed, or the server is stopping. Ending + // the stream is the point: the browser reconnects by + // itself and authenticates again. + Err(_) | Ok(None) => return None, + // The broadcaster is gone, which means the process is + // going with it. + Ok(Some(Err(RecvError::Closed))) => return None, + // This reader fell behind and announcements were dropped. + // Which ones is unknowable, so the tick says "re-read + // everything" — the client refetches the whole page, so + // a lagged tick and a plain tick are the same frame. + Ok(Some(Err(RecvError::Lagged(_)))) | Ok(Some(Ok(()))) => {} + } + return Some(( + Ok::<_, std::convert::Infallible>(Event::new().data("{}")), + (rx, deadline, stopping), + )); + } + }, + ); + + Sse::new(events.boxed()) + .keep_alive(KeepAlive::new()) + .into_response(cx) +} diff --git a/crates/im-web/src/mailer.rs b/crates/im-web/src/mailer.rs index 7c94fcb..53edd7f 100644 --- a/crates/im-web/src/mailer.rs +++ b/crates/im-web/src/mailer.rs @@ -53,7 +53,7 @@ async fn send(store: &Store, to: &str, subject: &str, body: String) -> Result<() let smtp = settings::smtp(store).await?; let message = lettre::Message::builder() .from( - smtp.from + smtp.from_header() .parse() .map_err(|e| MailError::Backend(format!("smtp from: {e}")))?, ) diff --git a/crates/im-web/src/main.rs b/crates/im-web/src/main.rs index ee0835a..c1e8706 100644 --- a/crates/im-web/src/main.rs +++ b/crates/im-web/src/main.rs @@ -14,6 +14,7 @@ mod admin; mod auth; mod config; mod layout; +mod live; mod mailer; mod oidc; mod pages; @@ -204,19 +205,21 @@ async fn create_client(config: Config, name: &str, uris: &[String]) { println!(" client_secret {}", secret.expose()); println!(" (the secret is shown once; its digest is all the database keeps)"); } - async fn serve(config: Config) { for line in config.report() { println!("im {line}"); } let store = open_store(&config).await; + let (live, _) = tokio::sync::broadcast::channel(64); + // Told when the process is stopping, so the live streams end instead of + // being waited out — see `live::Shutdown`. + let (stop, stopping) = tokio::sync::watch::channel(false); let app = server::App { store, config: config.clone(), + live, }; - // The bundle beside the executable is the only stylesheet this process - // can serve — `topcoat asset bundle -p im-web` produces it. let bundle = topcoat::asset::AssetBundle::load().unwrap_or_else(|err| { eprintln!("im: the asset bundle beside the executable failed to load: {err}"); eprintln!("im: run `topcoat asset bundle -p im-web` first"); @@ -228,6 +231,7 @@ async fn serve(config: Config) { .cookies() .assets(bundle) .app_context(app) + .app_context(live::Shutdown(stopping)) .build(); // `topcoat::start` binds HOST/PORT from the environment; the listen @@ -236,14 +240,15 @@ async fn serve(config: Config) { let listener = tokio::net::TcpListener::bind(config.listen) .await .expect("failed to bind the listen address"); - topcoat::serve_until(listener, router, shutdown_signal()) + topcoat::serve_until(listener, router, shutdown_signal(stop)) .await .expect("server error"); } /// Resolves when the process is asked to stop: Ctrl+C, or `SIGTERM` from a -/// service manager. -async fn shutdown_signal() { +/// service manager. The live streams hear it first, so the graceful shutdown +/// does not sit waiting on one long-lived connection per open tab. +async fn shutdown_signal(stop: tokio::sync::watch::Sender) { let ctrl_c = async { tokio::signal::ctrl_c() .await @@ -262,4 +267,6 @@ async fn shutdown_signal() { () = ctrl_c => {}, () = terminate => {}, } + // Streams end on their own; the browser reconnects when we are back. + let _ = stop.send(true); } diff --git a/crates/im-web/src/oidc.rs b/crates/im-web/src/oidc.rs index bd41993..e25f169 100644 --- a/crates/im-web/src/oidc.rs +++ b/crates/im-web/src/oidc.rs @@ -302,8 +302,7 @@ async fn exchange(cx: &Cx, Form(input): Form) -> Result { &consumed.session_hash, ) .await?; - im_core::events::log( - &app(cx).store, + server::log_event(cx, "code_exchanged", Some(&user.email), Some(&format!("via {}", client.name)), diff --git a/crates/im-web/src/server.rs b/crates/im-web/src/server.rs index 0cca7d2..5f8e0db 100644 --- a/crates/im-web/src/server.rs +++ b/crates/im-web/src/server.rs @@ -26,6 +26,23 @@ pub const PENDING_MINUTES: i64 = 10; pub struct App { pub store: Arc, pub config: Config, + /// The live channel's ticker: any mutation announces itself here, and + /// every open admin tab re-reads what it is showing. Carries no data — + /// a tick says "re-fetch", nothing more. + pub live: tokio::sync::broadcast::Sender<()>, +} + +/// Announce that the panel's data moved. Sends are lossy on purpose: nobody +/// listening is not an error, and a lagging tab gets a resync tick. +pub fn note(cx: &Cx) { + let _ = app(cx).live.send(()); +} + +/// Log the event, then tick the live channel — the two travel together so +/// the Logs page (and any watching panel) catches up without a reload. +pub async fn log_event(cx: &Cx, kind: &str, actor: Option<&str>, detail: Option<&str>) { + im_core::events::log(&app(cx).store, kind, actor, detail).await; + note(cx); } pub fn app(cx: &Cx) -> &App { diff --git a/style/main.scss b/style/main.scss index 58d1141..af4da63 100644 --- a/style/main.scss +++ b/style/main.scss @@ -586,6 +586,40 @@ body:has(.admin-shell) { &:hover { background: var(--danger-tint-alt); } } +// The two-step row action, iz's confirm-details: the summary wears the +// button skin; the popover names the cost and holds the real button. +.admin-confirm { + position: relative; + + summary { + list-style: none; + + &::-webkit-details-marker { display: none; } + } + + &[open] summary { background: var(--panel-sunken); } +} + +.admin-confirm-pop { + position: absolute; + right: 0; + top: calc(100% + 6px); + z-index: 30; + width: 240px; + padding: 12px; + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: var(--radius); + display: flex; + flex-direction: column; + gap: 8px; + font-size: 12px; + + .admin-action { width: 100%; height: 30px; } +} + +.admin-confirm-title { font-weight: 600; color: var(--ink); } + input[type="checkbox"] { accent-color: var(--accent); } @media (max-width: 720px) {