forge
Explore
Log in

Don't you dare go Hollow

A writer may delete, softly, after being told what goes

Browse files at this commit

9b4b86ead56a74c370ed5dcc734bc151ee976e5dAhmet Kaan GümüşParent: b0f8661
  • feat
    • a writer may delete, softly, after being told what goes
Show full message
🔥 feat(delete): a writer may delete, softly, after being told what goes

The delete policy is removed — column, enum, trait parameter and branch. It was
a setting with no screen: configurable-looking, unreachable, and hiding a
destructive default in the schema. A writer may delete.

What makes that safe is not a role but the two things around it. The delete is
soft: the task keeps a deleted_at, and its comments and both directions of its
edges stay in the table. Every read already joins the task and filters
deleted_at, so a deleted task's links stop applying without being destroyed, and
the freed-tasks calculation is unchanged — a soft-deleted task is gone from the
board, so what it blocked really is unblocked.

And it asks first. `what_delete_costs` is a read that reports the key, the
title, the comment count, the number of links that stop applying and the keys of
the tasks that would be freed; the modal says those out loud, in the artboard's
language, before the red button appears. The artboard drew no confirmation,
which was a gap in the mockup rather than a rule: this action reaches other
people's tasks and, from slice 7, sends mail.

Nothing in the UI restores a deleted task. `deleted_at` is what makes a mistake
recoverable by hand today; a restore surface can wait until someone asks.
crates/dizey-core/migrations/0001_init.sqlmodified+1 -3
@@ -20,9 +20,7 @@ CREATE TABLE workspace (
2020 attachment_limit_bytes INTEGER NOT NULL DEFAULT 26214400,
2121 photo_limit_bytes INTEGER NOT NULL DEFAULT 2097152,
2222 -- JSON array of allowed extensions. An empty array means every type.
23- allowed_file_types TEXT NOT NULL DEFAULT '[]',
24- -- 'anyone' | 'admin'
25- who_can_delete_tasks TEXT NOT NULL DEFAULT 'anyone'
23+ allowed_file_types TEXT NOT NULL DEFAULT '[]'
2624 );
2725
2826 CREATE TABLE user (
crates/dizey-core/src/detail.rsmodified+13 -0
@@ -60,6 +60,19 @@ impl DependencyEdge {
6060 }
6161 }
6262
63+/// What deleting a task would take with it. The confirmation step says this
64+/// out loud before the button fires.
65+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
66+pub struct DeletionCost {
67+ pub task_key: String,
68+ pub title: String,
69+ pub comment_count: u32,
70+ /// Links in either direction that stop applying.
71+ pub link_count: u32,
72+ /// Keys of the tasks that would have nothing in front of them afterwards.
73+ pub frees: Vec<String>,
74+}
75+
6376 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6477 pub struct Comment {
6578 pub id: String,
crates/dizey-core/src/store/mod.rsmodified+5 -29
@@ -10,7 +10,7 @@ use time::OffsetDateTime;
1010
1111 use crate::Role;
1212 use crate::board::{BoardReads, TaskRow};
13-use crate::detail::{ActivityKind, DetailReads};
13+use crate::detail::{ActivityKind, DeletionCost, DetailReads};
1414
1515 pub mod turso_store;
1616
@@ -51,33 +51,6 @@ pub struct Workspace {
5151 pub attachment_limit_bytes: u64,
5252 pub photo_limit_bytes: u64,
5353 pub allowed_file_types: Vec<String>,
54- pub who_can_delete_tasks: DeletePolicy,
55-}
56-
57-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
58-#[serde(rename_all = "snake_case")]
59-pub enum DeletePolicy {
60- /// Anyone who can write tasks may delete one.
61- Anyone,
62- /// Only the admin.
63- Admin,
64-}
65-
66-impl DeletePolicy {
67- pub fn as_str(self) -> &'static str {
68- match self {
69- DeletePolicy::Anyone => "anyone",
70- DeletePolicy::Admin => "admin",
71- }
72- }
73-
74- pub fn parse(raw: &str) -> Result<Self> {
75- match raw {
76- "anyone" => Ok(DeletePolicy::Anyone),
77- "admin" => Ok(DeletePolicy::Admin),
78- other => Err(StoreError::Corrupt(format!("delete policy {other:?}"))),
79- }
80- }
8154 }
8255
8356 /// An account. `password_hash` is `None` for an invited member who has not
@@ -202,7 +175,6 @@ pub trait Store: BoardReads + DetailReads + 'static {
202175 attachment_limit_bytes: u64,
203176 photo_limit_bytes: u64,
204177 allowed_file_types: &[String],
205- who_can_delete_tasks: DeletePolicy,
206178 ) -> Result<()>;
207179
208180 // -- users -------------------------------------------------------------
@@ -371,6 +343,10 @@ pub trait Store: BoardReads + DetailReads + 'static {
371343
372344 /// Appends one line to a task's activity trail. `actor_id` is `None` when
373345 /// the system did it rather than a person.
346+ /// What a delete would take with it, for the confirmation step. Reads
347+ /// only; nothing here writes.
348+ async fn deletion_cost(&self, task_id: &str) -> Result<Option<DeletionCost>>;
349+
374350 async fn record_activity(
375351 &self,
376352 task_id: &str,
crates/dizey-core/src/store/turso_store.rsmodified+81 -15
@@ -12,12 +12,12 @@ use turso::transaction::TransactionBehavior;
1212 use turso::{Builder, Connection, Row, Value, params};
1313 use uuid::Uuid;
1414
15-use super::{
16- DeletePolicy, NewTask, NewUser, Result, Session, SigninLink, Store, StoreError, User, Workspace,
17-};
15+use super::{NewTask, NewUser, Result, Session, SigninLink, Store, StoreError, User, Workspace};
1816 use crate::Role;
1917 use crate::board::{BoardMeta, BoardReads, Column, Person, TaskRow};
20-use crate::detail::{ActivityEntry, ActivityKind, Comment, DependencyEdge, DetailReads, TaskFacts};
18+use crate::detail::{
19+ ActivityEntry, ActivityKind, Comment, DeletionCost, DependencyEdge, DetailReads, TaskFacts,
20+};
2121 use time::Date;
2222 use time::format_description::BorrowedFormatItem;
2323 use time::macros::format_description;
@@ -216,13 +216,12 @@ fn workspace_from(row: &Row) -> Result<Workspace> {
216216 attachment_limit_bytes: row.get::<i64>(8).map_err(backend)?.max(0) as u64,
217217 allowed_file_types,
218218 photo_limit_bytes: row.get::<i64>(10).map_err(backend)?.max(0) as u64,
219- who_can_delete_tasks: DeletePolicy::parse(&text(row, 11)?)?,
220219 })
221220 }
222221
223222 const WORKSPACE_COLUMNS: &str = "id, name, created_at, smtp_host, smtp_port, smtp_username, \
224223 smtp_from_name, smtp_from_address, attachment_limit_bytes, allowed_file_types, \
225- photo_limit_bytes, who_can_delete_tasks";
224+ photo_limit_bytes";
226225
227226 fn user_from(row: &Row) -> Result<User> {
228227 Ok(User {
@@ -439,19 +438,17 @@ impl Store for TursoStore {
439438 attachment_limit_bytes: u64,
440439 photo_limit_bytes: u64,
441440 allowed_file_types: &[String],
442- who_can_delete_tasks: DeletePolicy,
443441 ) -> Result<()> {
444442 let types = serde_json::to_string(allowed_file_types)
445443 .map_err(|e| StoreError::Corrupt(format!("allowed_file_types: {e}")))?;
446444 self.conn
447445 .execute(
448446 "UPDATE workspace SET attachment_limit_bytes = ?1, photo_limit_bytes = ?2, \
449- allowed_file_types = ?3, who_can_delete_tasks = ?4 WHERE id = ?5",
447+ allowed_file_types = ?3 WHERE id = ?4",
450448 params![
451449 attachment_limit_bytes as i64,
452450 photo_limit_bytes as i64,
453451 types,
454- who_can_delete_tasks.as_str(),
455452 workspace_id
456453 ],
457454 )
@@ -1208,12 +1205,9 @@ impl Store for TursoStore {
12081205 }
12091206 drop(rows);
12101207
1211- tx.execute(
1212- "DELETE FROM task_dependency \
1213- WHERE blocked_task_id = ?1 OR blocking_task_id = ?1",
1214- params![task_id],
1215- )
1216- .await?;
1208+ // The edges and the comments stay in the table: the delete is a
1209+ // soft one, and every read filters on the task's deleted_at, so a
1210+ // deleted task's links stop applying without being destroyed.
12171211 tx.execute(
12181212 "UPDATE task SET deleted_at = ?2, updated_at = ?2 WHERE id = ?1",
12191213 params![task_id, stamp.clone()],
@@ -1286,6 +1280,78 @@ impl Store for TursoStore {
12861280 }
12871281 }
12881282
1283+ async fn deletion_cost(&self, task_id: &str) -> Result<Option<DeletionCost>> {
1284+ let mut rows = self
1285+ .conn
1286+ .query(
1287+ "SELECT task_key, title FROM task WHERE id = ?1 AND deleted_at IS NULL",
1288+ params![task_id],
1289+ )
1290+ .await
1291+ .map_err(backend)?;
1292+ let Some(row) = rows.next().await.map_err(backend)? else {
1293+ return Ok(None);
1294+ };
1295+ let task_key = text(&row, 0)?;
1296+ let title = text(&row, 1)?;
1297+ drop(rows);
1298+
1299+ // Both counts in one sweep: the confirmation says what goes, and it
1300+ // should not cost three round trips to say it.
1301+ let mut rows = self
1302+ .conn
1303+ .query(
1304+ "SELECT (SELECT COUNT(*) FROM comment WHERE task_id = ?1), \
1305+ (SELECT COUNT(*) FROM task_dependency d JOIN task t \
1306+ ON t.id = CASE WHEN d.blocked_task_id = ?1 \
1307+ THEN d.blocking_task_id ELSE d.blocked_task_id END \
1308+ WHERE (d.blocked_task_id = ?1 OR d.blocking_task_id = ?1) \
1309+ AND d.cleared_at IS NULL AND t.deleted_at IS NULL)",
1310+ params![task_id],
1311+ )
1312+ .await
1313+ .map_err(backend)?;
1314+ let (comment_count, link_count) = match rows.next().await.map_err(backend)? {
1315+ Some(row) => (
1316+ row.get::<i64>(0).map_err(backend)?.max(0) as u32,
1317+ row.get::<i64>(1).map_err(backend)?.max(0) as u32,
1318+ ),
1319+ None => (0, 0),
1320+ };
1321+ drop(rows);
1322+
1323+ // Who would be left with nothing in front of them. The same reading the
1324+ // delete itself uses: an uncleared edge to a live task is what counts.
1325+ let mut rows = self
1326+ .conn
1327+ .query(
1328+ "SELECT t.task_key FROM task_dependency d \
1329+ JOIN task t ON t.id = d.blocked_task_id \
1330+ WHERE d.blocking_task_id = ?1 AND d.cleared_at IS NULL \
1331+ AND t.deleted_at IS NULL \
1332+ AND NOT EXISTS ( \
1333+ SELECT 1 FROM task_dependency o \
1334+ JOIN task b ON b.id = o.blocking_task_id \
1335+ WHERE o.blocked_task_id = t.id AND o.blocking_task_id <> ?1 \
1336+ AND o.cleared_at IS NULL AND b.deleted_at IS NULL)",
1337+ params![task_id],
1338+ )
1339+ .await
1340+ .map_err(backend)?;
1341+ let mut frees = Vec::new();
1342+ while let Some(row) = rows.next().await.map_err(backend)? {
1343+ frees.push(text(&row, 0)?);
1344+ }
1345+
1346+ Ok(Some(DeletionCost {
1347+ task_key,
1348+ title,
1349+ comment_count,
1350+ link_count,
1351+ frees,
1352+ }))
1353+ }
1354+
12891355 async fn record_activity(
12901356 &self,
12911357 task_id: &str,
crates/dizey-core/tests/store.rsmodified+61 -10
@@ -8,7 +8,7 @@ use std::path::PathBuf;
88
99 use dizey_core::Role;
1010 use dizey_core::auth::{Token, hash_password};
11-use dizey_core::store::{DeletePolicy, NewUser, Store, StoreError, TursoStore, User};
11+use dizey_core::store::{NewUser, Store, StoreError, TursoStore, User};
1212 use time::{Duration, OffsetDateTime};
1313 use uuid::Uuid;
1414
@@ -213,7 +213,6 @@ async fn workspace_defaults_match_the_settings_screen() {
213213 ws.allowed_file_types.is_empty(),
214214 "every type until narrowed"
215215 );
216- assert_eq!(ws.who_can_delete_tasks, DeletePolicy::Anyone);
217216 assert!(ws.smtp_host.is_none());
218217 }
219218
@@ -258,20 +257,13 @@ async fn limits_round_trip_including_the_file_type_list() {
258257 let types = vec!["png".to_string(), "pdf".to_string()];
259258 scratch
260259 .store
261- .set_limits(
262- &ws_id,
263- 10 * 1024 * 1024,
264- 512 * 1024,
265- &types,
266- DeletePolicy::Admin,
267- )
260+ .set_limits(&ws_id, 10 * 1024 * 1024, 512 * 1024, &types)
268261 .await
269262 .unwrap();
270263 let ws = scratch.store.workspace().await.unwrap().unwrap();
271264 assert_eq!(ws.attachment_limit_bytes, 10 * 1024 * 1024);
272265 assert_eq!(ws.photo_limit_bytes, 512 * 1024);
273266 assert_eq!(ws.allowed_file_types, types);
274- assert_eq!(ws.who_can_delete_tasks, DeletePolicy::Admin);
275267 }
276268
277269 #[tokio::test]
@@ -2118,3 +2110,62 @@ async fn a_task_detail_costs_seven_queries_whatever_it_carries() {
21182110 "the round trips a detail costs must not follow what it carries"
21192111 );
21202112 }
2113+
2114+#[tokio::test]
2115+async fn a_delete_says_what_it_would_take_with_it() {
2116+ let (scratch, workspace, admin) = workspace_with_admin().await;
2117+ let store = &scratch.store;
2118+ let now = OffsetDateTime::now_utc();
2119+
2120+ let doomed = add_task(store, &workspace, "Backlog", "doomed", None, &admin).await;
2121+ let other = add_task(store, &workspace, "Backlog", "other", None, &admin).await;
2122+ let freed = add_task(store, &workspace, "Backlog", "freed", None, &admin).await;
2123+ let still_stuck = add_task(store, &workspace, "Backlog", "stuck", None, &admin).await;
2124+ store.add_dependency(&freed, &doomed, now).await.unwrap();
2125+ store
2126+ .add_dependency(&still_stuck, &doomed, now)
2127+ .await
2128+ .unwrap();
2129+ store
2130+ .add_dependency(&still_stuck, &other, now)
2131+ .await
2132+ .unwrap();
2133+ store
2134+ .add_comment(&doomed, &admin, "one", now)
2135+ .await
2136+ .unwrap();
2137+ store
2138+ .add_comment(&doomed, &admin, "two", now)
2139+ .await
2140+ .unwrap();
2141+
2142+ let cost = store.deletion_cost(&doomed).await.unwrap().unwrap();
2143+ assert_eq!(cost.title, "doomed");
2144+ assert_eq!(cost.comment_count, 2);
2145+ assert_eq!(cost.link_count, 2, "both tasks waiting on this one");
2146+
2147+ // The same reading the delete itself takes: only the task with nothing
2148+ // else in front of it is named.
2149+ let freed_key = key_of(store, &workspace, "freed").await;
2150+ assert_eq!(cost.frees, vec![freed_key]);
2151+
2152+ // And it is a preview: nothing was written.
2153+ assert_eq!(
2154+ store.delete_task(&doomed, &admin, now).await.unwrap(),
2155+ vec![freed.clone()]
2156+ );
2157+ assert!(store.deletion_cost(&doomed).await.unwrap().is_none());
2158+}
2159+
2160+/// The key the board shows for a task with this title.
2161+async fn key_of(store: &TursoStore, workspace: &str, title: &str) -> String {
2162+ let board = board_of(store, workspace).await;
2163+ board
2164+ .columns
2165+ .iter()
2166+ .flat_map(|column| column.cards.iter())
2167+ .find(|card| card.title == title)
2168+ .expect("no such card")
2169+ .task_key
2170+ .clone()
2171+}
crates/dizey-web/src/detail.rsmodified+108 -34
@@ -7,7 +7,7 @@
77 //! authorization question, not a validation one.
88
99 use dizey_core::board::Person;
10-use dizey_core::detail::{Comment, DependencyEdge, TaskDetail};
10+use dizey_core::detail::{Comment, DeletionCost, DependencyEdge, TaskDetail};
1111 use leptos::prelude::*;
1212 use serde::{Deserialize, Serialize};
1313 use time::Date;
@@ -34,7 +34,7 @@ pub struct DetailSnapshot {
3434 pub linkable: Vec<LinkTarget>,
3535 pub may_write: bool,
3636 pub may_comment: bool,
37- /// The workspace's delete policy, already applied to this person.
37+ /// Whether this person may delete the task. A writer may.
3838 pub may_delete: bool,
3939 }
4040
@@ -83,7 +83,6 @@ mod guard {
8383 pub async fn fetch_task(task_id: String) -> Result<Result<DetailSnapshot, Refusal>, ServerFnError> {
8484 use crate::server::{accounts, require_user};
8585 use dizey_core::detail::load;
86- use dizey_core::store::DeletePolicy;
8786 use time::OffsetDateTime;
8887
8988 let user = match require_user().await {
@@ -123,25 +122,16 @@ pub async fn fetch_task(task_id: String) -> Result<Result<DetailSnapshot, Refusa
123122 linkable.sort_by(|a, b| a.task_key.cmp(&b.task_key));
124123 }
125124
125+ // A writer may delete. The delete is soft and the confirmation says what
126+ // goes with it, which is what makes that safe — not a role.
126127 let may_write = user.role.can_write_tasks();
127- let policy = store
128- .workspace()
129- .await
130- .map_err(fail)?
131- .map(|workspace| workspace.who_can_delete_tasks)
132- .unwrap_or(DeletePolicy::Admin);
133- let may_delete = may_write
134- && match policy {
135- DeletePolicy::Anyone => true,
136- DeletePolicy::Admin => user.role.can_administer(),
137- };
138128
139129 Ok(Ok(DetailSnapshot {
140130 detail,
141131 linkable,
142132 may_write,
143133 may_comment: user.role.can_comment(),
144- may_delete,
134+ may_delete: may_write,
145135 me: Me {
146136 id: user.id,
147137 display_name: user.display_name,
@@ -398,34 +388,45 @@ pub async fn post_comment(task_id: String, body: String) -> Result<Option<Refusa
398388 Ok(None)
399389 }
400390
401-/// Deletes a task, subject to the workspace's policy. Whatever was waiting only
402-/// on it becomes unblocked, and the store records that.
391+/// What a delete would take with it, for the confirmation step. Reads only.
392+#[server]
393+pub async fn what_delete_costs(
394+ task_id: String,
395+) -> Result<Result<DeletionCost, Refusal>, ServerFnError> {
396+ use crate::server::accounts;
397+
398+ if let Err(refusal) = guard::writer_and_task(&task_id).await {
399+ return Ok(Err(refusal));
400+ }
401+ match accounts()
402+ .store()
403+ .deletion_cost(&task_id)
404+ .await
405+ .map_err(|e| ServerFnError::new(e.to_string()))?
406+ {
407+ Some(cost) => Ok(Ok(cost)),
408+ None => Ok(Err(Refusal::NotFound)),
409+ }
410+}
411+
412+/// Deletes a task. A writer may: the delete is soft — the row keeps a
413+/// `deleted_at`, its comments and its edges stay in the table — so a mistake is
414+/// recoverable by hand. Whatever was waiting only on it becomes unblocked, and
415+/// the store records that.
403416 #[server]
404417 pub async fn delete_task(task_id: String) -> Result<Option<Refusal>, ServerFnError> {
405418 use crate::server::accounts;
406- use dizey_core::store::DeletePolicy;
407419 use time::OffsetDateTime;
408420
409421 let (user, _) = match guard::writer_and_task(&task_id).await {
410422 Ok(pair) => pair,
411423 Err(refusal) => return Ok(Some(refusal)),
412424 };
413- let store = accounts().store().clone();
414- let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string());
415- let policy = store
416- .workspace()
417- .await
418- .map_err(fail)?
419- .map(|workspace| workspace.who_can_delete_tasks)
420- .unwrap_or(DeletePolicy::Admin);
421- if matches!(policy, DeletePolicy::Admin) && !user.role.can_administer() {
422- return Ok(Some(Refusal::Forbidden));
423- }
424-
425- store
425+ accounts()
426+ .store()
426427 .delete_task(&task_id, &user.id, OffsetDateTime::now_utc())
427428 .await
428- .map_err(fail)?;
429+ .map_err(|e| ServerFnError::new(e.to_string()))?;
429430 Ok(None)
430431 }
431432
@@ -536,6 +537,10 @@ fn DetailScreen(
536537 let comment = ServerAction::<PostComment>::new();
537538 let link = ServerAction::<LinkTasks>::new();
538539 let remove = ServerAction::<DeleteTask>::new();
540+ // Deleting is two steps: ask what it would cost, then say it out loud and
541+ // let the person decide. The artboard's red button had no confirmation and
542+ // this action reaches other people's tasks.
543+ let ask = ServerAction::<WhatDeleteCosts>::new();
539544 // Every action that lands re-reads the task and the board behind it.
540545 for value in [save.value(), comment.value(), link.value()] {
541546 Effect::new(move |_| {
@@ -793,16 +798,85 @@ fn DetailScreen(
793798
794799 {problem}
795800
801+ {move || {
802+ ask.value()
803+ .get()
804+ .and_then(|answer| answer.ok().and_then(|inner| inner.ok()))
805+ .map(|cost| {
806+ let DeletionCost { task_key, title, comment_count, link_count, frees } = cost;
807+ let freed = frees.join(", ");
808+ view! {
809+ <div class="confirm">
810+ <div class="confirm-title">
811+ {format!("Delete {task_key} — {title}?")}
812+ </div>
813+ <ul class="confirm-list">
814+ {(comment_count > 0)
815+ .then(|| {
816+ view! {
817+ <li>
818+ {if comment_count == 1 {
819+ "1 comment goes with it".to_string()
820+ } else {
821+ format!("{comment_count} comments go with it")
822+ }}
823+ </li>
824+ }
825+ })}
826+ {(link_count > 0)
827+ .then(|| {
828+ view! {
829+ <li>
830+ {if link_count == 1 {
831+ "1 dependency stops applying".to_string()
832+ } else {
833+ format!("{link_count} dependencies stop applying")
834+ }}
835+ </li>
836+ }
837+ })}
838+ {(!freed.is_empty())
839+ .then(|| {
840+ view! { <li>{format!("{freed} stops being blocked")}</li> }
841+ })}
842+ </ul>
843+ <div class="confirm-note">
844+ "The task keeps its record in the database, but nothing in Dizey brings it back."
845+ </div>
846+ <div class="confirm-row">
847+ <button
848+ class="detail-cancel"
849+ type="button"
850+ on:click=move |_| ask.value().set(None)
851+ >
852+ "Keep it"
853+ </button>
854+ <ActionForm action=remove attr:class="detail-delete-form">
855+ <input type="hidden" name="task_id" value=move || id.get_value()/>
856+ <button
857+ class="detail-delete detail-delete-sure"
858+ type="submit"
859+ disabled=move || remove.pending().get()
860+ >
861+ {format!("Delete {task_key}")}
862+ </button>
863+ </ActionForm>
864+ </div>
865+ </div>
866+ }
867+ })
868+ }}
869+
796870 <footer class="detail-foot">
797871 {may_delete
798872 .then(|| {
799873 view! {
800- <ActionForm action=remove attr:class="detail-delete-form">
874+ <ActionForm action=ask attr:class="detail-delete-form">
801875 <input type="hidden" name="task_id" value=move || id.get_value()/>
802876 <button
803877 class="detail-delete"
804878 type="submit"
805- disabled=move || remove.pending().get()
879+ disabled=move || ask.pending().get()
806880 >
807881 "Delete task"
808882 </button>
crates/dizey-web/tests/http.rsmodified+39 -30
@@ -28,23 +28,18 @@ use uuid::Uuid;
2828 struct App {
2929 dir: PathBuf,
3030 router: Router,
31- /// The same store the router talks to, so a test can set a workspace
32- /// setting that has no screen yet.
33- store: Arc<TursoStore>,
3431 }
3532
3633 impl App {
3734 async fn open() -> Self {
3835 let dir = std::env::temp_dir().join(format!("dizey-http-{}", Uuid::new_v4()));
3936 std::fs::create_dir_all(&dir).unwrap();
40- let store = Arc::new(
41- TursoStore::open(dir.join("dizey.db").to_str().unwrap())
42- .await
43- .unwrap(),
44- );
37+ let store = TursoStore::open(dir.join("dizey.db").to_str().unwrap())
38+ .await
39+ .unwrap();
4540 let options = LeptosOptions::builder().output_name("dizey").build();
46- let router = dizey_web::server::router(Accounts::new(store.clone()), options);
47- Self { dir, router, store }
41+ let router = dizey_web::server::router(Accounts::new(Arc::new(store)), options);
42+ Self { dir, router }
4843 }
4944
5045 /// Posts a form to a server function, as the browser does, and returns the
@@ -472,28 +467,33 @@ async fn a_viewer_who_posts_a_delete_anyway_is_refused() {
472467 }
473468
474469 #[tokio::test]
475-async fn a_member_cannot_delete_when_the_workspace_says_admins_only() {
476- use dizey_core::store::{DeletePolicy, Store};
477-
470+async fn a_member_may_delete_and_the_delete_is_soft() {
478471 let app = App::open().await;
479472 let admin = admin(&app).await;
480473 let member = invited(&app, &admin, "rae@dizey.sh", "Rae Okonkwo", Role::Member).await;
481474 let column = first_column(&app, &admin).await;
482- let task = a_task(&app, &admin, &column, "Not yours to remove").await;
483-
484- // The workspace ships as 'anyone'; the settings screen that flips this is a
485- // later slice, so the test sets it the way that screen will.
486- let workspace = app.store.workspace().await.unwrap().unwrap();
487- app.store
488- .set_limits(
489- &workspace.id,
490- workspace.attachment_limit_bytes,
491- workspace.photo_limit_bytes,
492- &workspace.allowed_file_types,
493- DeletePolicy::Admin,
475+ let task = a_task(&app, &admin, &column, "Mistyped in a hurry").await;
476+
477+ // What it would cost is a read: it says so and writes nothing.
478+ let answer = app
479+ .post(
480+ path::<dizey_web::detail::WhatDeleteCosts>(),
481+ Some(&member),
482+ &[("task_id", &task)],
494483 )
495- .await
496- .unwrap();
484+ .await;
485+ assert!(
486+ answer.body.contains("Mistyped in a hurry"),
487+ "{}",
488+ answer.body
489+ );
490+ let answer = app
491+ .post(path::<dizey_web::board::CurrentBoard>(), Some(&admin), &[])
492+ .await;
493+ assert!(
494+ answer.body.contains("Mistyped in a hurry"),
495+ "asking cost deleted it"
496+ );
497497
498498 let answer = app
499499 .post(
@@ -502,14 +502,23 @@ async fn a_member_cannot_delete_when_the_workspace_says_admins_only() {
502502 &[("task_id", &task)],
503503 )
504504 .await;
505- assert_eq!(answer.body, "\"Forbidden\"");
505+ assert_eq!(answer.body, "null", "a member was refused: {}", answer.body);
506506
507+ // Gone from the board, and gone from the detail: soft is not visible.
507508 let answer = app
508509 .post(path::<dizey_web::board::CurrentBoard>(), Some(&admin), &[])
509510 .await;
510511 assert!(
511- answer.body.contains("Not yours to remove"),
512- "the refused delete happened anyway: {}",
512+ !answer.body.contains("Mistyped in a hurry"),
513+ "{}",
513514 answer.body
514515 );
516+ let answer = app
517+ .post(
518+ path::<dizey_web::detail::FetchTask>(),
519+ Some(&admin),
520+ &[("task_id", &task)],
521+ )
522+ .await;
523+ assert_eq!(answer.body, "{\"Err\":\"NotFound\"}");
515524 }
style/main.scssmodified+42 -0
@@ -1006,3 +1006,45 @@ a {
10061006 padding: 6px 12px;
10071007 cursor: pointer;
10081008 }
1009+
1010+.confirm {
1011+ margin-top: 18px;
1012+ padding: 14px 16px;
1013+ background: #fdf6f2;
1014+ border: 1px solid #e8c9b8;
1015+ border-radius: var(--radius);
1016+}
1017+
1018+.confirm-title {
1019+ font-size: 14px;
1020+ font-weight: 600;
1021+ color: #a04a24;
1022+}
1023+
1024+.confirm-list {
1025+ margin: 8px 0 0;
1026+ padding-left: 18px;
1027+ font-size: 13px;
1028+ line-height: 1.6;
1029+ color: #3d3a34;
1030+}
1031+
1032+.confirm-note {
1033+ margin-top: 8px;
1034+ font-size: 12px;
1035+ color: var(--muted);
1036+}
1037+
1038+.confirm-row {
1039+ display: flex;
1040+ align-items: center;
1041+ justify-content: flex-end;
1042+ gap: 8px;
1043+ margin-top: 12px;
1044+}
1045+
1046+.detail-delete-sure {
1047+ color: #fffefb;
1048+ background: #a04a24;
1049+ border-color: #a04a24;
1050+}