Renames, deadlines and deletions reach the mail engine
Browse files at this commit1f3547b7729e73770bec9d6ddae60f37613007dfParent: b29a66e- feat
- renames, deadlines and deletions reach the mail engine
4 changed files +50 -23
- crates/izlek-core/src/store/mod.rs +7 -2
- crates/izlek-core/src/store/turso_store.rs +16 -15
- crates/izlek-core/tests/store.rs +19 -2
- crates/izlek-web/src/detail.rs +8 -4
crates/izlek-core/src/store/mod.rsmodified+7 -2
| @@ -421,6 +421,9 @@ pub struct Deletion { | |||
| 421 | /// The recorded freeing, written only when something was actually freed: | 421 | /// The recorded freeing, written only when something was actually freed: |
| 422 | /// a delete that frees nobody is not an event any rule can fire on. | 422 | /// a delete that frees nobody is not an event any rule can fire on. |
| 423 | pub event: Option<Freeing>, | 423 | pub event: Option<Freeing>, |
| 424 | + /// The id of the Deleted activity row, always written, so the mail engine | ||
| 425 | + /// can fire on it the same way it does the rest of a task's trail. | ||
| 426 | + pub activity_id: String, | ||
| 424 | } | 427 | } |
| 425 | 428 | ||
| 426 | /// One row of a task's activity trail, as an event a rule can fire on. Covers | 429 | /// One row of a task's activity trail, as an event a rule can fire on. Covers |
| @@ -702,7 +705,9 @@ pub trait Store: BoardReads + DetailReads + 'static { | |||
| 702 | async fn delete_attachment(&self, id: &str) -> Result<bool>; | 705 | async fn delete_attachment(&self, id: &str) -> Result<bool>; |
| 703 | 706 | ||
| 704 | /// Writes the title, description and deadline the detail screen saved, and | 707 | /// Writes the title, description and deadline the detail screen saved, and |
| 705 | - /// records one activity line per field that actually changed. | 708 | + /// records one activity line per field that actually changed. Returns the |
| 709 | + /// ids of the activity rows it wrote, in write order — empty when nothing | ||
| 710 | + /// changed — so the caller can hand each to the mail engine. | ||
| 706 | async fn save_task( | 711 | async fn save_task( |
| 707 | &self, | 712 | &self, |
| 708 | task_id: &str, | 713 | task_id: &str, |
| @@ -711,7 +716,7 @@ pub trait Store: BoardReads + DetailReads + 'static { | |||
| 711 | deadline: Option<time::Date>, | 716 | deadline: Option<time::Date>, |
| 712 | actor_id: &str, | 717 | actor_id: &str, |
| 713 | at: OffsetDateTime, | 718 | at: OffsetDateTime, |
| 714 | - ) -> Result<()>; | 719 | + ) -> Result<Vec<String>>; |
| 715 | 720 | ||
| 716 | /// Moves a task into a column and records the crossing, both in one | 721 | /// Moves a task into a column and records the crossing, both in one |
| 717 | /// transaction, so a transition never exists without the move that caused | 722 | /// transaction, so a transition never exists without the move that caused |
crates/izlek-core/src/store/turso_store.rsmodified+16 -15
| @@ -1561,7 +1561,7 @@ impl Store for TursoStore { | |||
| 1561 | deadline: Option<Date>, | 1561 | deadline: Option<Date>, |
| 1562 | actor_id: &str, | 1562 | actor_id: &str, |
| 1563 | at: OffsetDateTime, | 1563 | at: OffsetDateTime, |
| 1564 | - ) -> Result<()> { | 1564 | + ) -> Result<Vec<String>> { |
| 1565 | let deadline = deadline.map(day_text).transpose()?; | 1565 | let deadline = deadline.map(day_text).transpose()?; |
| 1566 | let stamp = stamp(at)?; | 1566 | let stamp = stamp(at)?; |
| 1567 | 1567 | ||
| @@ -1582,7 +1582,7 @@ impl Store for TursoStore { | |||
| 1582 | ) | 1582 | ) |
| 1583 | .await?; | 1583 | .await?; |
| 1584 | let Some(row) = rows.next().await? else { | 1584 | let Some(row) = rows.next().await? else { |
| 1585 | - return Ok(false); | 1585 | + return Ok(None); |
| 1586 | }; | 1586 | }; |
| 1587 | let was_title = row.get::<String>(0)?; | 1587 | let was_title = row.get::<String>(0)?; |
| 1588 | let was_description = row.get::<String>(1)?; | 1588 | let was_description = row.get::<String>(1)?; |
| @@ -1609,28 +1609,24 @@ impl Store for TursoStore { | |||
| 1609 | None => lines.push((ActivityKind::DeadlineCleared.as_str(), String::new())), | 1609 | None => lines.push((ActivityKind::DeadlineCleared.as_str(), String::new())), |
| 1610 | } | 1610 | } |
| 1611 | } | 1611 | } |
| 1612 | + let mut ids = Vec::with_capacity(lines.len()); | ||
| 1612 | for (kind, detail) in lines { | 1613 | for (kind, detail) in lines { |
| 1614 | + let id = Uuid::new_v4().to_string(); | ||
| 1613 | tx.execute( | 1615 | tx.execute( |
| 1614 | "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \ | 1616 | "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \ |
| 1615 | VALUES (?1, ?2, ?3, ?4, ?5, ?6)", | 1617 | VALUES (?1, ?2, ?3, ?4, ?5, ?6)", |
| 1616 | - params![ | 1618 | + params![id.clone(), task_id, actor_id, kind, detail, stamp.clone()], |
| 1617 | - Uuid::new_v4().to_string(), | ||
| 1618 | - task_id, | ||
| 1619 | - actor_id, | ||
| 1620 | - kind, | ||
| 1621 | - detail, | ||
| 1622 | - stamp.clone() | ||
| 1623 | - ], | ||
| 1624 | ) | 1619 | ) |
| 1625 | .await?; | 1620 | .await?; |
| 1621 | + ids.push(id); | ||
| 1626 | } | 1622 | } |
| 1627 | - Ok::<_, turso::Error>(true) | 1623 | + Ok::<_, turso::Error>(Some(ids)) |
| 1628 | } | 1624 | } |
| 1629 | .await; | 1625 | .await; |
| 1630 | 1626 | ||
| 1631 | match written { | 1627 | match written { |
| 1632 | - Ok(true) => tx.commit().await.map_err(backend), | 1628 | + Ok(Some(ids)) => tx.commit().await.map(|_| ids).map_err(backend), |
| 1633 | - Ok(false) => { | 1629 | + Ok(None) => { |
| 1634 | let _ = tx.rollback().await; | 1630 | let _ = tx.rollback().await; |
| 1635 | Err(StoreError::NotFound) | 1631 | Err(StoreError::NotFound) |
| 1636 | } | 1632 | } |
| @@ -1870,11 +1866,12 @@ impl Store for TursoStore { | |||
| 1870 | params![task_id, stamp.clone()], | 1866 | params![task_id, stamp.clone()], |
| 1871 | ) | 1867 | ) |
| 1872 | .await?; | 1868 | .await?; |
| 1869 | + let deleted_activity_id = Uuid::new_v4().to_string(); | ||
| 1873 | tx.execute( | 1870 | tx.execute( |
| 1874 | "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \ | 1871 | "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \ |
| 1875 | VALUES (?1, ?2, ?3, ?4, '', ?5)", | 1872 | VALUES (?1, ?2, ?3, ?4, '', ?5)", |
| 1876 | params![ | 1873 | params![ |
| 1877 | - Uuid::new_v4().to_string(), | 1874 | + deleted_activity_id.clone(), |
| 1878 | task_id, | 1875 | task_id, |
| 1879 | actor_id, | 1876 | actor_id, |
| 1880 | ActivityKind::Deleted.as_str(), | 1877 | ActivityKind::Deleted.as_str(), |
| @@ -1948,7 +1945,11 @@ impl Store for TursoStore { | |||
| 1948 | .await?; | 1945 | .await?; |
| 1949 | Some(event) | 1946 | Some(event) |
| 1950 | }; | 1947 | }; |
| 1951 | - Ok::<_, turso::Error>(Some(Deletion { freed, event })) | 1948 | + Ok::<_, turso::Error>(Some(Deletion { |
| 1949 | + freed, | ||
| 1950 | + event, | ||
| 1951 | + activity_id: deleted_activity_id, | ||
| 1952 | + })) | ||
| 1952 | } | 1953 | } |
| 1953 | .await; | 1954 | .await; |
| 1954 | 1955 | ||
crates/izlek-core/tests/store.rsmodified+19 -2
| @@ -2375,6 +2375,10 @@ async fn deleting_a_task_frees_what_was_waiting_on_it() { | |||
| 2375 | deletion.event.is_some(), | 2375 | deletion.event.is_some(), |
| 2376 | "a delete that freed somebody is an event the rules can fire on" | 2376 | "a delete that freed somebody is an event the rules can fire on" |
| 2377 | ); | 2377 | ); |
| 2378 | + match store.event(&deletion.activity_id).await.unwrap() { | ||
| 2379 | + Some(Event::Happened(ev)) => assert_eq!(ev.kind, ActivityKind::Deleted), | ||
| 2380 | + other => panic!("expected a Happened Deleted event, got {other:?}"), | ||
| 2381 | + } | ||
| 2378 | 2382 | ||
| 2379 | // The deleted task is gone from the board and from the edges it stood in. | 2383 | // The deleted task is gone from the board and from the edges it stood in. |
| 2380 | let board = board_of(store, &workspace).await; | 2384 | let board = board_of(store, &workspace).await; |
| @@ -2433,7 +2437,7 @@ async fn saving_a_task_records_only_what_changed() { | |||
| 2433 | let store = &scratch.store; | 2437 | let store = &scratch.store; |
| 2434 | let task = add_task(store, &workspace, "Backlog", "first title", None, &admin).await; | 2438 | let task = add_task(store, &workspace, "Backlog", "first title", None, &admin).await; |
| 2435 | 2439 | ||
| 2436 | - store | 2440 | + let ids = store |
| 2437 | .save_task( | 2441 | .save_task( |
| 2438 | &task, | 2442 | &task, |
| 2439 | "first title", | 2443 | "first title", |
| @@ -2444,6 +2448,7 @@ async fn saving_a_task_records_only_what_changed() { | |||
| 2444 | ) | 2448 | ) |
| 2445 | .await | 2449 | .await |
| 2446 | .unwrap(); | 2450 | .unwrap(); |
| 2451 | + assert_eq!(ids, Vec::<String>::new(), "a save that changed nothing writes nothing"); | ||
| 2447 | let detail = load_detail(store, &workspace, &task) | 2452 | let detail = load_detail(store, &workspace, &task) |
| 2448 | .await | 2453 | .await |
| 2449 | .unwrap() | 2454 | .unwrap() |
| @@ -2455,7 +2460,7 @@ async fn saving_a_task_records_only_what_changed() { | |||
| 2455 | "a save that changed nothing says nothing" | 2460 | "a save that changed nothing says nothing" |
| 2456 | ); | 2461 | ); |
| 2457 | 2462 | ||
| 2458 | - store | 2463 | + let ids = store |
| 2459 | .save_task( | 2464 | .save_task( |
| 2460 | &task, | 2465 | &task, |
| 2461 | "second title", | 2466 | "second title", |
| @@ -2466,6 +2471,18 @@ async fn saving_a_task_records_only_what_changed() { | |||
| 2466 | ) | 2471 | ) |
| 2467 | .await | 2472 | .await |
| 2468 | .unwrap(); | 2473 | .unwrap(); |
| 2474 | + let expected_kinds = [ | ||
| 2475 | + ActivityKind::Retitled, | ||
| 2476 | + ActivityKind::Described, | ||
| 2477 | + ActivityKind::DeadlineSet, | ||
| 2478 | + ]; | ||
| 2479 | + assert_eq!(ids.len(), expected_kinds.len()); | ||
| 2480 | + for (id, kind) in ids.iter().zip(expected_kinds) { | ||
| 2481 | + match store.event(id).await.unwrap() { | ||
| 2482 | + Some(Event::Happened(ev)) => assert_eq!(ev.kind, kind), | ||
| 2483 | + other => panic!("expected a Happened event for {id}, got {other:?}"), | ||
| 2484 | + } | ||
| 2485 | + } | ||
| 2469 | let detail = load_detail(store, &workspace, &task) | 2486 | let detail = load_detail(store, &workspace, &task) |
| 2470 | .await | 2487 | .await |
| 2471 | .unwrap() | 2488 | .unwrap() |
crates/izlek-web/src/detail.rsmodified+8 -4
| @@ -222,8 +222,8 @@ pub async fn save_task( | |||
| 222 | }, | 222 | }, |
| 223 | }; | 223 | }; |
| 224 | 224 | ||
| 225 | - accounts() | 225 | + let store = accounts().store().clone(); |
| 226 | - .store() | 226 | + let activity_ids = store |
| 227 | .save_task( | 227 | .save_task( |
| 228 | &task_id, | 228 | &task_id, |
| 229 | &title, | 229 | &title, |
| @@ -234,6 +234,9 @@ pub async fn save_task( | |||
| 234 | ) | 234 | ) |
| 235 | .await | 235 | .await |
| 236 | .map_err(|e| ServerFnError::new(e.to_string()))?; | 236 | .map_err(|e| ServerFnError::new(e.to_string()))?; |
| 237 | + for activity_id in activity_ids { | ||
| 238 | + crate::server::mail().after_activity(store.clone(), activity_id); | ||
| 239 | + } | ||
| 237 | Ok(None) | 240 | Ok(None) |
| 238 | } | 241 | } |
| 239 | 242 | ||
| @@ -478,8 +481,8 @@ pub async fn delete_task(task_id: String) -> Result<Option<Refusal>, ServerFnErr | |||
| 478 | Ok(pair) => pair, | 481 | Ok(pair) => pair, |
| 479 | Err(refusal) => return Ok(Some(refusal)), | 482 | Err(refusal) => return Ok(Some(refusal)), |
| 480 | }; | 483 | }; |
| 481 | - let deletion = accounts() | 484 | + let store = accounts().store().clone(); |
| 482 | - .store() | 485 | + let deletion = store |
| 483 | .delete_task(&task_id, &user.id, OffsetDateTime::now_utc()) | 486 | .delete_task(&task_id, &user.id, OffsetDateTime::now_utc()) |
| 484 | .await | 487 | .await |
| 485 | .map_err(|e| ServerFnError::new(e.to_string()))?; | 488 | .map_err(|e| ServerFnError::new(e.to_string()))?; |
| @@ -489,6 +492,7 @@ pub async fn delete_task(task_id: String) -> Result<Option<Refusal>, ServerFnErr | |||
| 489 | if let Some(freeing) = deletion.event { | 492 | if let Some(freeing) = deletion.event { |
| 490 | crate::server::mail().after_freeing(freeing, deletion.freed); | 493 | crate::server::mail().after_freeing(freeing, deletion.freed); |
| 491 | } | 494 | } |
| 495 | + crate::server::mail().after_activity(store, deletion.activity_id); | ||
| 492 | Ok(None) | 496 | Ok(None) |
| 493 | } | 497 | } |
| 494 | 498 | ||