forge
Explore
Log in

Don't you dare go Hollow

A status rule can watch every column

Browse files at this commit

88075f7d2b254861773024ded0e27d3af38eb4f6Ahmet Kaan GümüşParent: 4471b60
  • feat
    • a status rule can watch every column
Show full message
✨ feat(rules): a status rule can watch every column

The column select's first option now sends no column, and a status trigger
with none watches the whole board — every crossing fires it, so one rule
covers all columns instead of one rule per column.

Stored as its own trigger kind rather than a status row with a null column:
the schema ties `status` to a column it names, and a kind of its own keeps
that check honest without rebuilding `mail_rule` under a live ledger.
crates/izlek-core/src/mail.rsmodified+15 -4
@@ -214,7 +214,11 @@ impl Engine {
214 continue;214 continue;
215 }215 }
216 match &rule.trigger {216 match &rule.trigger {
217- Trigger::StatusBecomes(column) if *column == transition.to_column => {217+ Trigger::StatusBecomes(column)
218+ if column
219+ .as_deref()
220+ .is_none_or(|watched| watched == transition.to_column) =>
221+ {
218 self.owe(rule, &event, &transition.task_id, &mut report)222 self.owe(rule, &event, &transition.task_id, &mut report)
219 .await?;223 .await?;
220 }224 }
@@ -224,7 +228,11 @@ impl Engine {
224 }228 }
225 }229 }
226 Trigger::StatusBecomes(watched) => {230 Trigger::StatusBecomes(watched) => {
227- let detail = format!("moved:{}:{}", transition.to_column, watched);231+ let detail = format!(
232+ "moved:{}:{}",
233+ transition.to_column,
234+ watched.as_deref().unwrap_or("any")
235+ );
228 self.store236 self.store
229 .record_mail_decision(237 .record_mail_decision(
230 &rule.id,238 &rule.id,
@@ -295,7 +303,8 @@ impl Engine {
295 self.owe(rule, &event, task_id, &mut report).await?;303 self.owe(rule, &event, task_id, &mut report).await?;
296 }304 }
297 Trigger::StatusBecomes(watched) => {305 Trigger::StatusBecomes(watched) => {
298- let detail = format!("unblocked:{}", watched);306+ let detail =
307+ format!("unblocked:{}", watched.as_deref().unwrap_or("any"));
299 self.store308 self.store
300 .record_mail_decision(309 .record_mail_decision(
301 &rule.id,310 &rule.id,
@@ -423,7 +432,9 @@ impl Engine {
423 continue;432 continue;
424 }433 }
425 let watches = match &rule.trigger {434 let watches = match &rule.trigger {
426- Trigger::StatusBecomes(column) => format!("status:{}", column),435+ Trigger::StatusBecomes(column) => {
436+ format!("status:{}", column.as_deref().unwrap_or("any"))
437+ }
427 Trigger::Unblocked => "unblocked".to_string(),438 Trigger::Unblocked => "unblocked".to_string(),
428 other => activity_kind_for(other)439 other => activity_kind_for(other)
429 .map(|kind| format!("kind:{}", kind.as_str()))440 .map(|kind| format!("kind:{}", kind.as_str()))
crates/izlek-core/src/store/mod.rsmodified+3 -2
@@ -250,8 +250,9 @@ pub struct CommentWritten {
250 pub enum Trigger {250 pub enum Trigger {
251 /// A card crossed into this column. The crossing is the fact, not the251 /// A card crossed into this column. The crossing is the fact, not the
252 /// card's current column: a card that goes Review -> Done -> Review has252 /// card's current column: a card that goes Review -> Done -> Review has
253- /// crossed into Done once.253+ /// crossed into Done once. `None` watches every column — any crossing at
254- StatusBecomes(String),254+ /// all fires it, which is how one rule covers a whole board.
255+ StatusBecomes(Option<String>),
255 /// A task whose last blocker just finished, so the people on it can start.256 /// A task whose last blocker just finished, so the people on it can start.
256 Unblocked,257 Unblocked,
257 Created,258 Created,
crates/izlek-core/src/store/turso_store.rsmodified+8 -2
@@ -249,7 +249,12 @@ const SEND_COLUMNS: &str = "id, rule_id, event_id, task_id, recipient, state, at
249 249
250 fn trigger_parts(trigger: &Trigger) -> (&'static str, Option<String>) {250 fn trigger_parts(trigger: &Trigger) -> (&'static str, Option<String>) {
251 match trigger {251 match trigger {
252- Trigger::StatusBecomes(column) => ("status", Some(column.clone())),252+ // The every-column rule is its own stored kind rather than a status
253+ // row with no column: the schema's check ties `status` to a column
254+ // it names, and a kind of its own keeps that check honest without
255+ // rebuilding the table under a live ledger.
256+ Trigger::StatusBecomes(Some(column)) => ("status", Some(column.clone())),
257+ Trigger::StatusBecomes(None) => ("status_any", None),
253 Trigger::Unblocked => ("unblocked", None),258 Trigger::Unblocked => ("unblocked", None),
254 Trigger::Created => ("created", None),259 Trigger::Created => ("created", None),
255 Trigger::Assigned => ("assigned", None),260 Trigger::Assigned => ("assigned", None),
@@ -279,7 +284,8 @@ fn rule_from(row: &Row) -> Result<MailRule> {
279 let kind = text(row, 2)?;284 let kind = text(row, 2)?;
280 let column = opt_text(row, 3)?;285 let column = opt_text(row, 3)?;
281 let trigger = match (kind.as_str(), column) {286 let trigger = match (kind.as_str(), column) {
282- ("status", Some(column)) => Trigger::StatusBecomes(column),287+ ("status", Some(column)) => Trigger::StatusBecomes(Some(column)),
288+ ("status_any", None) => Trigger::StatusBecomes(None),
283 ("unblocked", None) => Trigger::Unblocked,289 ("unblocked", None) => Trigger::Unblocked,
284 ("created", None) => Trigger::Created,290 ("created", None) => Trigger::Created,
285 ("assigned", None) => Trigger::Assigned,291 ("assigned", None) => Trigger::Assigned,
crates/izlek-core/tests/store.rsmodified+71 -3
@@ -3470,7 +3470,7 @@ async fn a_rule(store: &TursoStore, workspace: &str, column: &str, subject: &str
3470 store3470 store
3471 .create_mail_rule(3471 .create_mail_rule(
3472 &board.id,3472 &board.id,
3473- &Trigger::StatusBecomes(column_id),3473+ &Trigger::StatusBecomes(Some(column_id)),
3474 subject,3474 subject,
3475 Audience::Assignees,3475 Audience::Assignees,
3476 OffsetDateTime::now_utc(),3476 OffsetDateTime::now_utc(),
@@ -4105,7 +4105,7 @@ async fn a_rule_can_opt_the_task_key_into_its_own_mail() {
4105 let opted_in = store4105 let opted_in = store
4106 .create_mail_rule(4106 .create_mail_rule(
4107 &board.id,4107 &board.id,
4108- &Trigger::StatusBecomes(column_named(&store, &workspace, "Done").await),4108+ &Trigger::StatusBecomes(Some(column_named(&store, &workspace, "Done").await)),
4109 "Task completed, with details",4109 "Task completed, with details",
4110 Audience::Assignees,4110 Audience::Assignees,
4111 OffsetDateTime::now_utc(),4111 OffsetDateTime::now_utc(),
@@ -4604,7 +4604,7 @@ async fn the_actor_comes_off_the_board_audience_too_and_the_rest_still_get_it()
4604 store4604 store
4605 .create_mail_rule(4605 .create_mail_rule(
4606 &board.id,4606 &board.id,
4607- &Trigger::StatusBecomes(column_id),4607+ &Trigger::StatusBecomes(Some(column_id)),
4608 "Task completed",4608 "Task completed",
4609 Audience::Board,4609 Audience::Board,
4610 OffsetDateTime::now_utc(),4610 OffsetDateTime::now_utc(),
@@ -5586,3 +5586,71 @@ async fn a_tasks_activity_reads_newest_first() {
5586 assert_eq!(activity.first().map(|line| line.kind.clone()), Some(ActivityKind::Commented), "{activity:?}");5586 assert_eq!(activity.first().map(|line| line.kind.clone()), Some(ActivityKind::Commented), "{activity:?}");
5587 assert_eq!(activity.last().map(|line| line.kind.clone()), Some(ActivityKind::Created), "{activity:?}");5587 assert_eq!(activity.last().map(|line| line.kind.clone()), Some(ActivityKind::Created), "{activity:?}");
5588 }5588 }
5589+
5590+/// A status rule with no column watches the whole board: every crossing fires
5591+/// it, not just the one into a named column.
5592+#[tokio::test]
5593+async fn a_status_rule_with_no_column_fires_on_every_crossing() {
5594+ let (dir, store, workspace, admin) = shared().await;
5595+ let mate = member(&store, &workspace, "emre@izlek.sh", "Emre").await;
5596+ let board = store.board(&workspace).await.unwrap().unwrap();
5597+ let task = add_task(&store, &workspace, "Backlog", "Ship it", None, &admin).await;
5598+ store.assign_task(&task, &mate).await.unwrap();
5599+
5600+ store
5601+ .create_mail_rule(
5602+ &board.id,
5603+ &Trigger::StatusBecomes(None),
5604+ "It moved",
5605+ Audience::Assignees,
5606+ OffsetDateTime::now_utc(),
5607+ false,
5608+ )
5609+ .await
5610+ .unwrap();
5611+
5612+ let mailer = Remembering::taking_everything();
5613+ let engine = Engine::new(store.clone(), mailer.clone(), "https://izlek.sh");
5614+
5615+ let first = moved_to(&store, &workspace, &task, "Backlog", "In Progress", &admin).await;
5616+ engine.on_transition(&first).await.unwrap();
5617+ let second = moved_to(&store, &workspace, &task, "In Progress", "Done", &admin).await;
5618+ engine.on_transition(&second).await.unwrap();
5619+
5620+ let sent = mailer.sent();
5621+ assert_eq!(
5622+ sent.iter().filter(|mail| mail.subject == "It moved").count(),
5623+ 2,
5624+ "both crossings fired the every-column rule: {sent:?}"
5625+ );
5626+ let _ = std::fs::remove_dir_all(&dir);
5627+}
5628+
5629+/// The every-column rule round-trips through the store: it is written with no
5630+/// column and read back as one, not as a rule pointing at a column named "".
5631+#[tokio::test]
5632+async fn an_every_column_rule_survives_the_round_trip() {
5633+ let (dir, store, workspace, admin) = shared().await;
5634+ let board = store.board(&workspace).await.unwrap().unwrap();
5635+ let rule = store
5636+ .create_mail_rule(
5637+ &board.id,
5638+ &Trigger::StatusBecomes(None),
5639+ "It moved",
5640+ Audience::Assignees,
5641+ OffsetDateTime::now_utc(),
5642+ false,
5643+ )
5644+ .await
5645+ .unwrap();
5646+ let read = store
5647+ .mail_rules(&board.id)
5648+ .await
5649+ .unwrap()
5650+ .into_iter()
5651+ .find(|stored| stored.id == rule.id)
5652+ .expect("the rule is on the board");
5653+ assert_eq!(read.trigger, Trigger::StatusBecomes(None));
5654+ let _ = admin;
5655+ let _ = std::fs::remove_dir_all(&dir);
5656+}
crates/izlek-web/src/i18n.rsmodified+6 -0
@@ -215,6 +215,8 @@ pub enum Key {
215 AudienceBoard,215 AudienceBoard,
216 AudienceCreator,216 AudienceCreator,
217 WhenStatusBecomes,217 WhenStatusBecomes,
218+ WhenStatusChanges,
219+ AnyColumn,
218 WhenTaskStopsBeingBlocked,220 WhenTaskStopsBeingBlocked,
219 WhenTaskCreated,221 WhenTaskCreated,
220 WhenSomeoneAssigned,222 WhenSomeoneAssigned,
@@ -700,6 +702,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
700 (AudienceCreator, Tr) => "oluşturanı",702 (AudienceCreator, Tr) => "oluşturanı",
701 (WhenStatusBecomes, En) => "When status becomes",703 (WhenStatusBecomes, En) => "When status becomes",
702 (WhenStatusBecomes, Tr) => "Durum şuna dönüştüğünde",704 (WhenStatusBecomes, Tr) => "Durum şuna dönüştüğünde",
705+ (WhenStatusChanges, En) => "When status changes",
706+ (WhenStatusChanges, Tr) => "Durum değiştiğinde",
707+ (AnyColumn, En) => "Any column",
708+ (AnyColumn, Tr) => "Herhangi bir sütun",
703 (WhenTaskStopsBeingBlocked, En) => "When a task stops being",709 (WhenTaskStopsBeingBlocked, En) => "When a task stops being",
704 (WhenTaskStopsBeingBlocked, Tr) => "Bir görev şu olmaktan çıktığında",710 (WhenTaskStopsBeingBlocked, Tr) => "Bir görev şu olmaktan çıktığında",
705 (WhenTaskCreated, En) => "When a task is created",711 (WhenTaskCreated, En) => "When a task is created",
crates/izlek-web/src/rules.rsmodified+26 -14
@@ -101,16 +101,16 @@ fn audience_kind(audience: Audience) -> &'static str {
101 }101 }
102 102
103 /// Parses a trigger from the words a form sends: the trigger's own kind, and103 /// Parses a trigger from the words a form sends: the trigger's own kind, and
104-/// a column id only a status trigger carries. Every other trigger must arrive104+/// a column id only a status trigger carries. A status trigger with no column
105-/// with no column — a column id on, say, "created" is a form gone wrong, not105+/// is the every-column rule. Every other trigger must arrive with no column —
106-/// something to guess past.106+/// a column id on, say, "created" is a form gone wrong, not something to
107+/// guess past.
107 ///108 ///
108 /// Shared by `create_rule` and `update_rule` so the vocabulary is matched109 /// Shared by `create_rule` and `update_rule` so the vocabulary is matched
109 /// once.110 /// once.
110 fn trigger_of(kind: &str, column_id: Option<String>) -> Option<Trigger> {111 fn trigger_of(kind: &str, column_id: Option<String>) -> Option<Trigger> {
111 match (kind, column_id) {112 match (kind, column_id) {
112- ("status", Some(column_id)) => Some(Trigger::StatusBecomes(column_id)),113+ ("status", column_id) => Some(Trigger::StatusBecomes(column_id)),
113- ("status", None) => None,
114 ("unblocked", None) => Some(Trigger::Unblocked),114 ("unblocked", None) => Some(Trigger::Unblocked),
115 ("created", None) => Some(Trigger::Created),115 ("created", None) => Some(Trigger::Created),
116 ("assigned", None) => Some(Trigger::Assigned),116 ("assigned", None) => Some(Trigger::Assigned),
@@ -170,7 +170,16 @@ fn sentence_of(
170 lang: Lang,170 lang: Lang,
171 ) -> (String, String, String, Option<String>) {171 ) -> (String, String, String, Option<String>) {
172 match trigger {172 match trigger {
173- Trigger::StatusBecomes(column_id) => (173+ // No column is every column, and "becomes <a column>" has nothing to
174+ // name then — the sentence changes shape rather than printing a word
175+ // for "any".
176+ Trigger::StatusBecomes(None) => (
177+ t(lang, Key::WhenStatusChanges).to_string(),
178+ String::new(),
179+ "status".to_string(),
180+ None,
181+ ),
182+ Trigger::StatusBecomes(Some(column_id)) => (
174 t(lang, Key::WhenStatusBecomes).to_string(),183 t(lang, Key::WhenStatusBecomes).to_string(),
175 columns184 columns
176 .iter()185 .iter()
@@ -433,10 +442,11 @@ async fn create_rule(cx: &Cx, Form(input): Form<CreateRuleForm>) -> Redirect {
433 } else {442 } else {
434 Some(input.column_id)443 Some(input.column_id)
435 };444 };
436- if input.trigger == "status" {445+ // A status rule may name no column at all — that one watches every
437- let Some(column_id) = &column_id else {446+ // column. A named one still has to be this board's own.
438- return redirect(cx, Some(Refusal::Forbidden));447+ if input.trigger == "status"
439- };448+ && let Some(column_id) = &column_id
449+ {
440 let columns = match store.columns(&board.id).await {450 let columns = match store.columns(&board.id).await {
441 Ok(columns) => columns,451 Ok(columns) => columns,
442 Err(_) => return redirect(cx, Some(Refusal::Unavailable)),452 Err(_) => return redirect(cx, Some(Refusal::Unavailable)),
@@ -520,10 +530,11 @@ async fn update_rule(cx: &Cx, Form(input): Form<UpdateRuleForm>) -> Redirect {
520 } else {530 } else {
521 Some(input.column_id)531 Some(input.column_id)
522 };532 };
523- if input.trigger == "status" {533+ // A status rule may name no column at all — that one watches every
524- let Some(column_id) = &column_id else {534+ // column. A named one still has to be this board's own.
525- return redirect(cx, Some(Refusal::Forbidden));535+ if input.trigger == "status"
526- };536+ && let Some(column_id) = &column_id
537+ {
527 let columns = match store.columns(&board.id).await {538 let columns = match store.columns(&board.id).await {
528 Ok(columns) => columns,539 Ok(columns) => columns,
529 Err(_) => return redirect(cx, Some(Refusal::Unavailable)),540 Err(_) => return redirect(cx, Some(Refusal::Unavailable)),
@@ -690,6 +701,7 @@ async fn rule_form(
690 <label class="rule-field">701 <label class="rule-field">
691 <span class="field-label">(t(lang, Key::ColumnLabel))</span>702 <span class="field-label">(t(lang, Key::ColumnLabel))</span>
692 <select class="field-input" name="column_id">703 <select class="field-input" name="column_id">
704+ <option value="" selected=(column_id.is_empty())>(t(lang, Key::AnyColumn))</option>
693 for column in columns {705 for column in columns {
694 <option value=(column.id.clone()) selected=(column.id == column_id)>(column.name.clone())</option>706 <option value=(column.id.clone()) selected=(column.id == column_id)>(column.name.clone())</option>
695 }707 }
crates/izlek-web/tests/http.rsmodified+45 -1
@@ -5735,7 +5735,7 @@ async fn a_task_with_a_notification(app: &App, admin_cookie: &str, subject: &str
5735 .store5735 .store
5736 .create_mail_rule(5736 .create_mail_rule(
5737 &board.id,5737 &board.id,
5738- &Trigger::StatusBecomes(columns[1].clone()),5738+ &Trigger::StatusBecomes(Some(columns[1].clone())),
5739 subject,5739 subject,
5740 Audience::Assignees,5740 Audience::Assignees,
5741 time::OffsetDateTime::now_utc(),5741 time::OffsetDateTime::now_utc(),
@@ -6343,3 +6343,47 @@ async fn a_workbook_opens_as_a_table_and_its_other_sheet_is_one_link_away() {
6343 .await;6343 .await;
6344 assert!(String::from_utf8_lossy(&past_the_end.bytes).contains("Cable"));6344 assert!(String::from_utf8_lossy(&past_the_end.bytes).contains("Cable"));
6345 }6345 }
6346+
6347+/// A status rule can watch the whole board: the column select's first option
6348+/// sends no column, and the rule reads back as a sentence about status
6349+/// changing rather than becoming one named column.
6350+#[tokio::test]
6351+async fn a_status_rule_may_watch_every_column() {
6352+ let app = App::open().await;
6353+ let admin_cookie = admin(&app).await;
6354+
6355+ let answer = app
6356+ .post(
6357+ "/api/create_rule",
6358+ Some(&admin_cookie),
6359+ &[
6360+ ("trigger", "status"),
6361+ ("column_id", ""),
6362+ ("subject", "It moved"),
6363+ ("audience", "assignees"),
6364+ ],
6365+ )
6366+ .await;
6367+ assert_eq!(answer.status, StatusCode::SEE_OTHER);
6368+ assert_eq!(answer.body, "null", "the rule was refused: {}", answer.body);
6369+
6370+ let seen = app
6371+ .post("/api/current_rules", Some(&admin_cookie), &[])
6372+ .await;
6373+ assert!(
6374+ seen.body.contains("\"when\":\"When status changes\""),
6375+ "{}",
6376+ seen.body
6377+ );
6378+ assert!(
6379+ seen.body.contains("\"column_id\":null"),
6380+ "the every-column rule names no column: {}",
6381+ seen.body
6382+ );
6383+
6384+ // The composer offers it: the column select carries the any option, and
6385+ // it is the one selected while the rule names no column.
6386+ let page = app.get("/rules", Some(&admin_cookie)).await;
6387+ let html = String::from_utf8_lossy(&page.bytes);
6388+ assert!(html.contains("Any column"), "no any-column option: {html}");
6389+}