From bcc7fa7ca14ace8a329847f079377a75dde97a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 26 Aug 2026 16:48:54 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(rules):=20the=20admin's=20mail?= =?UTF-8?q?=20rules=20screen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One sentence per rule, from the MailRules artboard: a switch, "When status becomes send to ", the last-sent stamp and a delete. Writing rules is the admin's alone and the guard sits in each handler, not in the sidebar: a rule sends mail from the one workspace sender on everyone's behalf, so a Member reaching the endpoint directly is refused there. A rule id arriving from the browser is checked against this workspace's own board, and "not a rule" and "not your rule" answer the same way, so the endpoint never confirms that someone else's rule exists. The composer is a
whose open state and subject field the component owns, so a rule that has just been written leaves a closed, empty composer behind instead of the sentence you already sent. Nine endpoint tests cover the pair of guards, the refusals (empty subject, a column off another board, an audience the screen never offers, a foreign rule id) and the round trip through create, switch off, and delete. EVIDENCE: nine browser screenshots from the verify harness run | release server on 127.0.0.1:3111, machine-driven clicks: opened the composer, typed a subject, pressed Add rule, toggled the switch off and on, pressed Delete, reopened the composer | the row rendered the sentence with "never sent", greyed when off, came back when on, vanished on delete leaving the empty-state line, and the reopened composer was empty --- crates/dizey-web/src/app.rs | 2 + crates/dizey-web/src/auth.rs | 5 + crates/dizey-web/src/lib.rs | 1 + crates/dizey-web/src/rules.rs | 532 +++++++++++++++++++++++++++++++ crates/dizey-web/src/settings.rs | 3 + crates/dizey-web/tests/http.rs | 324 +++++++++++++++++++ style/main.scss | 158 +++++++++ 7 files changed, 1025 insertions(+) create mode 100644 crates/dizey-web/src/rules.rs diff --git a/crates/dizey-web/src/app.rs b/crates/dizey-web/src/app.rs index 263480c..213fffe 100644 --- a/crates/dizey-web/src/app.rs +++ b/crates/dizey-web/src/app.rs @@ -4,6 +4,7 @@ use leptos_router::components::{Route, Router, Routes}; use leptos_router::{SsrMode, path}; use crate::pages::{Join, Landing}; +use crate::rules::RulesPage; use crate::settings::SettingsPage; /// The HTML document the server streams. `cargo-leptos` writes the bundle to @@ -48,6 +49,7 @@ pub fn App() -> impl IntoView { + diff --git a/crates/dizey-web/src/auth.rs b/crates/dizey-web/src/auth.rs index 9175db7..f3190d1 100644 --- a/crates/dizey-web/src/auth.rs +++ b/crates/dizey-web/src/auth.rs @@ -46,6 +46,8 @@ pub enum Refusal { BadSender(String), /// A comment with nothing in it. EmptyComment, + /// A rule with no subject line: the mail it sends would arrive blank. + EmptySubject, /// The date field did not hold a date. BadDeadline, /// The link asked for would put a task behind itself. @@ -85,6 +87,7 @@ impl Refusal { } Refusal::BadSender(problem) => problem.clone(), Refusal::EmptyComment => "Write something first.".to_string(), + Refusal::EmptySubject => "Give the rule a subject line.".to_string(), Refusal::BadDeadline => "That is not a date.".to_string(), Refusal::Cycle => "That link would put this task behind itself.".to_string(), Refusal::MovedAlready => { @@ -127,6 +130,7 @@ impl Refusal { Refusal::BadFileType => "bad-file-type", Refusal::BadSender(_) => "bad-sender", Refusal::EmptyComment => "empty-comment", + Refusal::EmptySubject => "empty-subject", Refusal::BadDeadline => "bad-deadline", Refusal::Cycle => "cycle", Refusal::MovedAlready => "moved-already", @@ -151,6 +155,7 @@ impl Refusal { "link-not-usable" => Refusal::LinkNotUsable, "empty-title" => Refusal::EmptyTitle, "empty-comment" => Refusal::EmptyComment, + "empty-subject" => Refusal::EmptySubject, "bad-deadline" => Refusal::BadDeadline, "cycle" => Refusal::Cycle, "moved-already" => Refusal::MovedAlready, diff --git a/crates/dizey-web/src/lib.rs b/crates/dizey-web/src/lib.rs index 64e3b43..086085a 100644 --- a/crates/dizey-web/src/lib.rs +++ b/crates/dizey-web/src/lib.rs @@ -7,6 +7,7 @@ pub mod auth; pub mod board; pub mod detail; pub mod pages; +pub mod rules; pub mod settings; #[cfg(feature = "ssr")] pub mod server; diff --git a/crates/dizey-web/src/rules.rs b/crates/dizey-web/src/rules.rs new file mode 100644 index 0000000..4747138 --- /dev/null +++ b/crates/dizey-web/src/rules.rs @@ -0,0 +1,532 @@ +//! Mail rules, from the MailRules artboard. +//! +//! The screen is the admin's, and so is every call behind it: a rule sends mail +//! on everyone's behalf, from the one workspace sender, so writing one is not +//! something a Member may do even if they reach the endpoint directly. The +//! chip in the artboard says "Admin only"; the guard is in the handlers. + +use leptos::prelude::*; +use serde::{Deserialize, Serialize}; + +use crate::auth::{Me, Refusal}; + +/// One rule as the screen reads it: a sentence, a switch and a stamp. +/// +/// The trigger arrives already split into the words the artboard prints — +/// "When status becomes" / "Done" — because the two halves are chosen from +/// different vocabularies and only the server knows the column names. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct RuleLine { + pub id: String, + /// "When status becomes", or "When a task stops being". + pub when: String, + /// "Done", or "blocked". + pub what: String, + pub subject: String, + /// "assignees", or "everyone on board". + pub audience: String, + pub enabled: bool, + /// `Aug 24 14:02`, or nothing when no mail from this rule has ever been + /// accepted by the mail server. + pub last_sent: Option, +} + +/// A column, for the composer's status list. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct ColumnChoice { + pub id: String, + pub name: String, +} + +/// The screen in one answer. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct RulesSnapshot { + pub me: Me, + pub rules: Vec, + pub columns: Vec, + /// Whether a sender is connected. Rules that fire with no sender queue + /// rather than fail, and the screen says so instead of leaving somebody to + /// wonder why nothing arrived. + pub sender_connected: bool, +} + +/// The word for an audience, as the artboard writes it. +#[cfg(feature = "ssr")] +fn audience_word(audience: dizey_core::store::Audience) -> &'static str { + use dizey_core::store::Audience; + match audience { + Audience::Assignees => "assignees", + Audience::Board => "everyone on board", + } +} + +/// Every rule on the board, switched-off ones included, with the columns a new +/// rule may name. +#[server] +pub async fn current_rules() -> Result, ServerFnError> { + use crate::server::{accounts, require_admin}; + use dizey_core::store::Trigger; + + let user = match require_admin().await { + Ok(user) => user, + Err(refusal) => return Ok(Err(refusal)), + }; + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + let Some(board) = store.board(&user.workspace_id).await.map_err(fail)? else { + return Ok(Err(Refusal::Unavailable)); + }; + let columns = store.columns(&board.id).await.map_err(fail)?; + let rules = store.mail_rules(&board.id).await.map_err(fail)?; + let last_sent = store.mail_rule_last_sent(&board.id).await.map_err(fail)?; + let sender_connected = store + .workspace() + .await + .map_err(fail)? + .as_ref() + .map(crate::settings::Sender::of) + .is_some_and(|sender| sender.is_connected()); + + let lines = rules + .into_iter() + .map(|rule| { + let (when, what) = match &rule.trigger { + Trigger::StatusBecomes(column_id) => ( + "When status becomes".to_string(), + columns + .iter() + .find(|column| &column.id == column_id) + .map(|column| column.name.clone()) + // A rule can outlive the column it names. Saying so is + // better than printing an id nobody can read. + .unwrap_or_else(|| "a column that is gone".to_string()), + ), + Trigger::Unblocked => ( + "When a task stops being".to_string(), + "blocked".to_string(), + ), + }; + RuleLine { + when, + what, + subject: rule.subject.clone(), + audience: audience_word(rule.audience).to_string(), + enabled: rule.enabled, + last_sent: last_sent + .iter() + .find(|(id, _)| id == &rule.id) + .map(|(_, at)| dizey_core::detail::moment_label(*at)), + id: rule.id, + } + }) + .collect(); + + Ok(Ok(RulesSnapshot { + me: Me { + id: user.id, + display_name: user.display_name, + email: user.email, + role: user.role, + }, + rules: lines, + columns: columns + .into_iter() + .map(|column| ColumnChoice { id: column.id, name: column.name }) + .collect(), + sender_connected, + })) +} + +/// Writes one rule. +/// +/// `trigger` is "status" or "unblocked"; `column_id` is only read for the +/// first, and is checked against this workspace's own board rather than +/// trusted — a column id from somewhere else would otherwise be a way to hang +/// a rule off another workspace's board. +#[server] +pub async fn create_rule( + trigger: String, + column_id: String, + subject: String, + audience: String, +) -> Result, ServerFnError> { + use crate::server::{accounts, require_admin}; + use dizey_core::store::{Audience, Trigger}; + + let user = match require_admin().await { + Ok(user) => user, + Err(refusal) => return Ok(Some(refusal)), + }; + let subject = subject.trim().to_string(); + if subject.is_empty() { + return Ok(Some(Refusal::EmptySubject)); + } + let audience = match audience.as_str() { + "assignees" => Audience::Assignees, + "board" => Audience::Board, + _ => return Ok(Some(Refusal::Forbidden)), + }; + + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + let Some(board) = store.board(&user.workspace_id).await.map_err(fail)? else { + return Ok(Some(Refusal::Unavailable)); + }; + let trigger = match trigger.as_str() { + "unblocked" => Trigger::Unblocked, + "status" => { + let columns = store.columns(&board.id).await.map_err(fail)?; + if !columns.iter().any(|column| column.id == column_id) { + return Ok(Some(Refusal::Forbidden)); + } + Trigger::StatusBecomes(column_id) + } + _ => return Ok(Some(Refusal::Forbidden)), + }; + + store + .create_mail_rule( + &board.id, + &trigger, + &subject, + audience, + time::OffsetDateTime::now_utc(), + ) + .await + .map_err(fail)?; + Ok(None) +} + +/// Turns one rule on or off. Switching off stops it firing from here on; mail +/// it already owes has been written to the ledger and is still owed. +#[server] +pub async fn set_rule_enabled( + rule_id: String, + enabled: String, +) -> Result, ServerFnError> { + let store = match rule_of_this_workspace(&rule_id).await { + Ok(store) => store, + Err(refusal) => return Ok(Some(refusal)), + }; + store + .set_mail_rule_enabled(&rule_id, enabled == "true") + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + Ok(None) +} + +/// Removes a rule. What it has already sent stays in the ledger: the rule is +/// gone, the record of what went out is not. +#[server] +pub async fn delete_rule(rule_id: String) -> Result, ServerFnError> { + let store = match rule_of_this_workspace(&rule_id).await { + Ok(store) => store, + Err(refusal) => return Ok(Some(refusal)), + }; + store + .delete_mail_rule(&rule_id) + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + Ok(None) +} + +/// The admin's store, once the rule id has been shown to name a rule on this +/// workspace's own board. +/// +/// A rule id is opaque and arrives from the browser, so "not yours" and "not a +/// rule" are the same answer: neither tells the caller whether the id exists +/// somewhere else. +#[cfg(feature = "ssr")] +async fn rule_of_this_workspace( + rule_id: &str, +) -> Result, Refusal> { + use crate::server::{accounts, require_admin}; + + let user = require_admin().await?; + let store = accounts().store().clone(); + let board = store + .board(&user.workspace_id) + .await + .map_err(|_| Refusal::Unavailable)? + .ok_or(Refusal::Unavailable)?; + let rule = store + .mail_rule(rule_id) + .await + .map_err(|_| Refusal::Unavailable)? + .ok_or(Refusal::NotFound)?; + if rule.board_id != board.id { + return Err(Refusal::NotFound); + } + Ok(store) +} + +#[component] +pub fn RulesPage() -> impl IntoView { + let rules = Resource::new(|| (), |_| async move { current_rules().await }); + + view! { + }> + {move || Suspend::new(async move { + match rules.await { + Ok(Ok(snapshot)) => { + view! { + + } + .into_any() + } + Ok(Err(refusal)) => { + view! { +
+

{refusal.message()}

+

+ "Back to the board" +

+
+ } + .into_any() + } + Err(_) => { + view! { +
+

"Something went wrong. Reload the page."

+
+ } + .into_any() + } + } + })} +
+ } +} + +#[component] +fn RulesScreen(snapshot: RulesSnapshot, on_change: Callback<()>) -> impl IntoView { + let me = snapshot.me.clone(); + let sender_connected = snapshot.sender_connected; + let empty = snapshot.rules.is_empty(); + let rows = snapshot + .rules + .into_iter() + .map(|rule| view! { }) + .collect_view(); + + view! { +
+
+ "dizey" + +
+
+ "Mail rules" +
+ + {me.display_name.clone()} + +
+ +
+ + +
+
+

"Mail rules"

+ "Admin only" + + "One sentence per rule. A rule fires when a task on this board matches it. Only the admin writes them — a rule sends mail on everyone's behalf, from the one workspace sender." + +
+ + {(!sender_connected) + .then(|| { + view! { +

+ "No sender is connected yet, so nothing leaves the machine. Rules still fire and the mail they owe waits in the queue until you connect one in " + "Settings" + "." +

+ } + })} + + + +
+ {rows} + {empty + .then(|| { + view! { +

+ "No rules yet. Nothing on this board sends mail until you write one." +

+ } + })} +
+
+
+ } +} + +/// The "New rule" control and the sentence it builds. +/// +/// It is a `
` rather than a signal-driven panel so that a browser with +/// no script can still open it and post the form. +#[component] +fn Composer(columns: Vec, on_change: Callback<()>) -> impl IntoView { + let action = ServerAction::::new(); + let value = action.value(); + // The composer owns its own open state rather than letting `
` + // keep it: a rule that has just been written should leave a closed, empty + // composer behind, not the sentence you already sent sitting in the field. + let open = RwSignal::new(false); + let subject = RwSignal::new(String::new()); + Effect::new(move |_| { + if matches!(value.get(), Some(Ok(None))) { + subject.set(String::new()); + open.set(false); + on_change.run(()); + } + }); + let refusal = move || match value.get() { + Some(Ok(Some(refusal))) => Some(refusal.message()), + Some(Err(_)) => Some(Refusal::Unavailable.message()), + _ => None, + }; + let options = columns + .into_iter() + .map(|column| view! { }) + .collect_view(); + + view! { +
+ + "New rule" + + + + + + +
+ {move || { + refusal() + .map(|message| view! { {message} }) + }} + +
+ + "A Viewer is never mailed by a rule, on any audience, and neither is whoever caused the event." + +
+
+ } +} + +#[component] +fn RuleRow(rule: RuleLine, on_change: Callback<()>) -> impl IntoView { + let toggle = ServerAction::::new(); + let remove = ServerAction::::new(); + let toggled = toggle.value(); + Effect::new(move |_| { + if matches!(toggled.get(), Some(Ok(None))) { + on_change.run(()); + } + }); + let removed = remove.value(); + Effect::new(move |_| { + if matches!(removed.get(), Some(Ok(None))) { + on_change.run(()); + } + }); + + let RuleLine { id, when, what, subject, audience, enabled, last_sent } = rule; + let stamp = last_sent + .map(|moment| format!("last sent {moment}")) + .unwrap_or_else(|| "never sent".to_string()); + let row_class = if enabled { "rule-row" } else { "rule-row rule-row-off" }; + let switch_class = if enabled { "rule-switch rule-switch-on" } else { "rule-switch" }; + let switch_label = if enabled { "Switch this rule off" } else { "Switch this rule on" }; + // Each form carries the id in its own hidden field, and each of those + // fields owns its copy: the two live in separate closures. + let toggle_id = id.clone(); + let delete_id = id; + + view! { +
+ + + + + + +
+ {when} + {what} + "send" + {subject} + "to" + {audience} +
+ + {stamp} + + + + + +
+ } +} diff --git a/crates/dizey-web/src/settings.rs b/crates/dizey-web/src/settings.rs index 7691d9f..140da13 100644 --- a/crates/dizey-web/src/settings.rs +++ b/crates/dizey-web/src/settings.rs @@ -597,6 +597,9 @@ fn SettingsScreen( "Board" + + "Mail rules" + "Settings" diff --git a/crates/dizey-web/tests/http.rs b/crates/dizey-web/tests/http.rs index d0d85a7..c65c899 100644 --- a/crates/dizey-web/tests/http.rs +++ b/crates/dizey-web/tests/http.rs @@ -1643,3 +1643,327 @@ async fn testing_a_sender_that_was_never_filled_in_says_so_rather_than_sending() .await; assert!(!seen.body.contains("\"test\":{"), "{}", seen.body); } + +/// Writes one rule as the admin, and reports whether the server took it. +async fn rule_written(app: &App, admin: &str, column_id: &str, subject: &str) -> bool { + let answer = app + .post( + path::(), + Some(admin), + &[ + ("trigger", "status"), + ("column_id", column_id), + ("subject", subject), + ("audience", "assignees"), + ], + ) + .await; + answer.status == StatusCode::OK && answer.body == "null" +} + +/// The id of the one rule the workspace has. +async fn only_rule(app: &App, admin: &str) -> String { + let answer = app + .post(path::(), Some(admin), &[]) + .await; + answer + .body + .split("\"rules\":[") + .nth(1) + .and_then(|rest| rest.split("\"id\":\"").nth(1)) + .and_then(|rest| rest.split('"').next()) + .unwrap_or_else(|| panic!("no rule id in {}", answer.body)) + .to_string() +} + +#[tokio::test] +async fn an_admin_writes_a_rule_and_reads_it_back_as_a_sentence() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app, &admin_cookie).await; + + assert!(rule_written(&app, &admin_cookie, &column, "Task completed").await); + + let answer = app + .post( + path::(), + Some(&admin_cookie), + &[], + ) + .await; + assert!( + answer.body.contains("\"when\":\"When status becomes\""), + "{}", + answer.body + ); + assert!( + answer.body.contains("\"subject\":\"Task completed\""), + "{}", + answer.body + ); + assert!( + answer.body.contains("\"audience\":\"assignees\""), + "{}", + answer.body + ); + // Nothing has been sent, and the row says so rather than nothing at all. + assert!(answer.body.contains("\"last_sent\":null"), "{}", answer.body); +} + +#[tokio::test] +async fn a_rule_with_no_subject_is_refused_and_says_why() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app, &admin_cookie).await; + + let answer = app + .post( + path::(), + Some(&admin_cookie), + &[ + ("trigger", "status"), + ("column_id", &column), + ("subject", " "), + ("audience", "assignees"), + ], + ) + .await; + assert!(answer.body.contains("EmptySubject"), "{}", answer.body); +} + +#[tokio::test] +async fn a_rule_may_not_be_hung_off_a_column_that_is_not_on_this_board() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + + let answer = app + .post( + path::(), + Some(&admin_cookie), + &[ + ("trigger", "status"), + ("column_id", &Uuid::new_v4().to_string()), + ("subject", "Task completed"), + ("audience", "assignees"), + ], + ) + .await; + assert!(answer.body.contains("Forbidden"), "{}", answer.body); + + let seen = app + .post( + path::(), + Some(&admin_cookie), + &[], + ) + .await; + assert!(seen.body.contains("\"rules\":[]"), "{}", seen.body); +} + +#[tokio::test] +async fn an_audience_the_screen_never_offers_is_refused() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app, &admin_cookie).await; + + let answer = app + .post( + path::(), + Some(&admin_cookie), + &[ + ("trigger", "status"), + ("column_id", &column), + ("subject", "Task completed"), + ("audience", "everyone-everywhere"), + ], + ) + .await; + assert!(answer.body.contains("Forbidden"), "{}", answer.body); +} + +#[tokio::test] +async fn switching_a_rule_off_leaves_it_listed_and_switched_off() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app, &admin_cookie).await; + assert!(rule_written(&app, &admin_cookie, &column, "Task completed").await); + let rule = only_rule(&app, &admin_cookie).await; + + let answer = app + .post( + path::(), + Some(&admin_cookie), + &[("rule_id", &rule), ("enabled", "false")], + ) + .await; + assert_eq!(answer.body, "null", "{}", answer.body); + + // The screen lists what exists, not what is live. + let seen = app + .post( + path::(), + Some(&admin_cookie), + &[], + ) + .await; + assert!(seen.body.contains("\"enabled\":false"), "{}", seen.body); + assert!( + seen.body.contains("\"subject\":\"Task completed\""), + "{}", + seen.body + ); +} + +#[tokio::test] +async fn a_rule_id_this_workspace_does_not_own_is_refused() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let stranger = Uuid::new_v4().to_string(); + + for path in [ + path::(), + path::(), + ] { + let answer = app + .post( + path, + Some(&admin_cookie), + &[("rule_id", &stranger), ("enabled", "false")], + ) + .await; + assert!(answer.body.contains("NotFound"), "{path}: {}", answer.body); + } +} + +#[tokio::test] +async fn deleting_a_rule_takes_it_off_the_screen() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app, &admin_cookie).await; + assert!(rule_written(&app, &admin_cookie, &column, "Task completed").await); + let rule = only_rule(&app, &admin_cookie).await; + + let answer = app + .post( + path::(), + Some(&admin_cookie), + &[("rule_id", &rule)], + ) + .await; + assert_eq!(answer.body, "null", "{}", answer.body); + + let seen = app + .post( + path::(), + Some(&admin_cookie), + &[], + ) + .await; + assert!(seen.body.contains("\"rules\":[]"), "{}", seen.body); +} + +#[tokio::test] +async fn only_an_admin_may_read_or_write_the_rules() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app, &admin_cookie).await; + assert!(rule_written(&app, &admin_cookie, &column, "Task completed").await); + let rule = only_rule(&app, &admin_cookie).await; + + let member = invited(&app, &admin_cookie, "emre@dizey.sh", "Emre", Role::Member).await; + let viewer = invited(&app, &admin_cookie, "pinar@dizey.sh", "Pinar", Role::Viewer).await; + + for who in [&member, &viewer] { + let read = app + .post(path::(), Some(who), &[]) + .await; + assert!(read.body.contains("Forbidden"), "{}", read.body); + + let written = app + .post( + path::(), + Some(who), + &[ + ("trigger", "status"), + ("column_id", &column), + ("subject", "Mail everyone about me"), + ("audience", "board"), + ], + ) + .await; + assert!(written.body.contains("Forbidden"), "{}", written.body); + + let switched = app + .post( + path::(), + Some(who), + &[("rule_id", &rule), ("enabled", "false")], + ) + .await; + assert!(switched.body.contains("Forbidden"), "{}", switched.body); + + let deleted = app + .post( + path::(), + Some(who), + &[("rule_id", &rule)], + ) + .await; + assert!(deleted.body.contains("Forbidden"), "{}", deleted.body); + } + + // And the rule is untouched: still there, still on. + let seen = app + .post( + path::(), + Some(&admin_cookie), + &[], + ) + .await; + assert!(seen.body.contains("\"enabled\":true"), "{}", seen.body); + assert!( + !seen.body.contains("Mail everyone about me"), + "{}", + seen.body + ); +} + +#[tokio::test] +async fn a_signed_out_browser_may_not_touch_the_rules() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app, &admin_cookie).await; + assert!(rule_written(&app, &admin_cookie, &column, "Task completed").await); + let rule = only_rule(&app, &admin_cookie).await; + + for (path, form) in [ + ( + path::(), + vec![] as Vec<(&str, &str)>, + ), + ( + path::(), + vec![ + ("trigger", "status"), + ("column_id", column.as_str()), + ("subject", "Task completed"), + ("audience", "assignees"), + ], + ), + ( + path::(), + vec![("rule_id", rule.as_str()), ("enabled", "false")], + ), + ( + path::(), + vec![("rule_id", rule.as_str())], + ), + ] { + let answer = app.post(path, None, &form).await; + assert!( + answer.body.contains("SignInFirst"), + "{path}: {}", + answer.body + ); + } +} diff --git a/style/main.scss b/style/main.scss index d54b88b..cbfe5b8 100644 --- a/style/main.scss +++ b/style/main.scss @@ -1803,3 +1803,161 @@ a { &:hover { color: var(--accent-ink); } } + +// --- Mail rules (MailRules artboard) --------------------------------------- + +// Text only a screen reader needs: the switch says what it does in a word the +// eye reads from its position, and the ear cannot. +.visually-hidden { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + padding: 0; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; +} + +.rules-quiet { + margin: 0; + font-size: 13px; + color: var(--muted); +} + +.rule-list { + display: flex; + flex-direction: column; + gap: 10px; +} + +.rule-row { + display: flex; + align-items: center; + gap: 14px; + padding: 16px; + background: var(--surface); + border: 1px solid var(--border); + border-radius: 8px; + + // A rule that is switched off is still listed — the screen shows what + // exists, not what is live — and reads as the quieter of the two. + &-off { + background: #faf9f4; + opacity: 0.75; + } +} + +.rule-switch-form { display: flex; flex-shrink: 0; } + +.rule-switch { + width: 36px; + height: 20px; + padding: 0; + border: none; + border-radius: 10px; + background: #d5d1c7; + position: relative; + cursor: pointer; + + &-knob { + position: absolute; + top: 2px; + left: 2px; + width: 16px; + height: 16px; + border-radius: 50%; + background: var(--surface); + } + + &-on { + background: var(--accent); + .rule-switch-knob { left: auto; right: 2px; } + } +} + +.rule-sentence { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 8px; + flex-grow: 1; + min-width: 0; + font-size: 13px; + color: #3d3a34; +} + +// One chosen word inside the sentence: a column, a subject, an audience. +.rule-term { + display: inline-flex; + align-items: center; + padding: 3px 8px; + background: var(--accent-tint); + border: 1px solid #d8dce6; + border-radius: 5px; + font-weight: 500; +} + +.rule-row-off .rule-term { + background: #f1efe8; + border-color: var(--border-strong); +} + +.rule-stamp { + flex-shrink: 0; + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); +} + +.rule-delete { + flex-shrink: 0; + height: 32px; + padding: 0 12px; + background: transparent; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + color: var(--muted); + font-family: var(--font-sans); + font-size: 12px; + font-weight: 600; + cursor: pointer; + + &:hover { background: #f1efe8; color: #a04a24; } +} + +.rule-new { + background: var(--surface); + border: 1px solid var(--border); + border-radius: 10px; +} + +.rule-new-open { + display: flex; + align-items: center; + height: 44px; + padding: 0 16px; + font-size: 13px; + font-weight: 600; + color: var(--accent-ink); + cursor: pointer; + list-style: none; + + &::marker, &::-webkit-details-marker { display: none; } + &::before { content: '+'; margin-right: 8px; font-size: 15px; } +} + +.rule-new-body { + display: flex; + flex-direction: column; + gap: 14px; + padding: 0 16px 16px; + border-top: 1px solid var(--border); + padding-top: 16px; +} + +.rule-field { + display: flex; + flex-direction: column; + gap: 6px; +}