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