forge
Explore
Log in

Don't you dare go Hollow

The task detail, and the refusals behind it

Browse files at this commit

b0f8661c6ef561a574a8372f4dff13692ee689e3Ahmet Kaan GümüşParent: 1efe924
  • feat
    • the task detail, and the refusals behind it
Show full message
✨ feat(web): the task detail, and the refusals behind it

The TaskDetail artboard as a modal — the `esc` chip says the board is still
there behind it, so it is not a route. A card is the way in: it carries the
button role and answers Enter and Space, because the artboard draws no separate
control.

One call brings the screen and every change re-reads it, so what is shown is
what the store says. Status is deliberately read-only here: the column a task
sits in changes by moving it, and that transition is the next slice — the mail
rules will want to watch it.

Every mutation is guarded twice: `require_writer`, then the task itself checked
against the asker's workspace. A task id in a form is an authorization question.
A viewer's comment and a viewer's delete are refused in the handler, not merely
left undrawn, and the tests assert nothing was written afterwards. A link that
would close a circle comes back as `Cycle` from the store's own transaction. An
id from another workspace answers `NotFound` — the same answer an id that never
existed gets.

The assignee picker offers only people who can hold work, checked again on the
way in: the form's user_id is not trusted to be one of them.

Also the queued restyle of the unassigned card: a dashed circle at the avatar's
22px where the avatar sits, so the card's bottom row does not reflow when
someone is assigned. Accessible name "nobody assigned".
crates/dizey-web/src/auth.rsmodified+16 -10
@@ -26,6 +26,15 @@ pub enum Refusal {
26 LinkNotUsable,26 LinkNotUsable,
27 /// A card with no title is not a card.27 /// A card with no title is not a card.
28 EmptyTitle,28 EmptyTitle,
29+ /// A comment with nothing in it.
30+ EmptyComment,
31+ /// The date field did not hold a date.
32+ BadDeadline,
33+ /// The link asked for would put a task behind itself.
34+ Cycle,
35+ /// No such task — or none this account may see. Deliberately one answer for
36+ /// both.
37+ NotFound,
29 Unavailable,38 Unavailable,
30 }39 }
31 40
@@ -42,10 +51,13 @@ impl Refusal {
42 Refusal::AlreadyClaimed => "This workspace already has an owner.".to_string(),51 Refusal::AlreadyClaimed => "This workspace already has an owner.".to_string(),
43 Refusal::AddressTaken => "That address already has an account.".to_string(),52 Refusal::AddressTaken => "That address already has an account.".to_string(),
44 Refusal::LinkNotUsable => {53 Refusal::LinkNotUsable => {
45- "This link no longer works. Ask the admin to send another."54+ "This link no longer works. Ask the admin to send another.".to_string()
46- .to_string()
47 }55 }
48 Refusal::EmptyTitle => "Give the task a title.".to_string(),56 Refusal::EmptyTitle => "Give the task a title.".to_string(),
57+ Refusal::EmptyComment => "Write something first.".to_string(),
58+ Refusal::BadDeadline => "That is not a date.".to_string(),
59+ Refusal::Cycle => "That link would put this task behind itself.".to_string(),
60+ Refusal::NotFound => "No such task.".to_string(),
49 Refusal::Unavailable => "Something went wrong. Try again.".to_string(),61 Refusal::Unavailable => "Something went wrong. Try again.".to_string(),
50 }62 }
51 }63 }
@@ -189,17 +201,11 @@ pub async fn redeem_link(
189 /// Signing in. Answers the same whether the address is unknown, has no password201 /// Signing in. Answers the same whether the address is unknown, has no password
190 /// yet, or the password is wrong.202 /// yet, or the password is wrong.
191 #[server]203 #[server]
192-pub async fn sign_in(204+pub async fn sign_in(email: String, password: String) -> Result<Option<Refusal>, ServerFnError> {
193- email: String,
194- password: String,
195-) -> Result<Option<Refusal>, ServerFnError> {
196 use crate::server::{accounts, client_label, set_session_cookie};205 use crate::server::{accounts, client_label, set_session_cookie};
197 use dizey_core::accounts::SESSION_LIFETIME;206 use dizey_core::accounts::SESSION_LIFETIME;
198 207
199- match accounts()208+ match accounts().sign_in(&email, &password, &client_label()).await {
200- .sign_in(&email, &password, &client_label())
201- .await
202- {
203 Ok(signed_in) => {209 Ok(signed_in) => {
204 set_session_cookie(signed_in.session_token.expose(), SESSION_LIFETIME);210 set_session_cookie(signed_in.session_token.expose(), SESSION_LIFETIME);
205 Ok(None)211 Ok(None)
crates/dizey-web/src/board.rsmodified+55 -11
@@ -162,16 +162,15 @@ fn BoardScreen(
162 let filter = RwSignal::new(Filter::All);162 let filter = RwSignal::new(Filter::All);
163 // Which column has its composer open, if any.163 // Which column has its composer open, if any.
164 let composing = RwSignal::new(None::<String>);164 let composing = RwSignal::new(None::<String>);
165+ // Which card is open in the detail modal, if any.
166+ let opened = RwSignal::new(None::<String>);
165 let may_write = me.role.can_write_tasks();167 let may_write = me.role.can_write_tasks();
166 let my_id = StoredValue::new(me.id.clone());168 let my_id = StoredValue::new(me.id.clone());
167 169
168 // The New task button opens the composer in the first column, which is170 // The New task button opens the composer in the first column, which is
169 // where a new card belongs when nobody has said otherwise.171 // where a new card belongs when nobody has said otherwise.
170- let first_column_id = StoredValue::new(172+ let first_column_id =
171- view.columns173+ StoredValue::new(view.columns.first().map(|column| column.column.id.clone()));
172- .first()
173- .map(|column| column.column.id.clone()),
174- );
175 174
176 let overdue = view.overdue_count(today);175 let overdue = view.overdue_count(today);
177 let blocked = view.blocked_count();176 let blocked = view.blocked_count();
@@ -224,7 +223,12 @@ fn BoardScreen(
224 </header>223 </header>
225 <div class="column-cards">224 <div class="column-cards">
226 <For each=move || shown.get() key=|card: &TaskCard| card.id.clone() let:card>225 <For each=move || shown.get() key=|card: &TaskCard| card.id.clone() let:card>
227- <Card card=card today=today done_column=is_done_column/>226+ <Card
227+ card=card
228+ today=today
229+ done_column=is_done_column
230+ on_open=move |task_id| opened.set(Some(task_id))
231+ />
228 </For>232 </For>
229 <Show when=move || may_write && is_composing()>233 <Show when=move || may_write && is_composing()>
230 <Composer234 <Composer
@@ -302,6 +306,19 @@ fn BoardScreen(
302 </div>306 </div>
303 }307 }
304 })}308 })}
309+ {move || {
310+ opened
311+ .get()
312+ .map(|task_id| {
313+ view! {
314+ <crate::detail::TaskDetailModal
315+ task_id=task_id
316+ on_close=move || opened.set(None)
317+ on_change=on_change
318+ />
319+ }
320+ })
321+ }}
305 </main>322 </main>
306 }323 }
307 }324 }
@@ -320,7 +337,12 @@ fn FilterTab(filter: RwSignal<Filter>, this: Filter, label: &'static str) -> imp
320 }337 }
321 338
322 #[component]339 #[component]
323-fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView {340+fn Card(
341+ card: TaskCard,
342+ today: Date,
343+ done_column: bool,
344+ on_open: impl Fn(String) + Copy + Send + Sync + 'static,
345+) -> impl IntoView {
324 let blocks = card.blocks.len();346 let blocks = card.blocks.len();
325 let blocked_by = card.blocked_by.join(", ");347 let blocked_by = card.blocked_by.join(", ");
326 let deadline = card.deadline_label(today);348 let deadline = card.deadline_label(today);
@@ -328,9 +350,25 @@ fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView {
328 let dated = card.deadline.is_some() || card.is_done();350 let dated = card.deadline.is_some() || card.is_done();
329 let comments = card.comment_count;351 let comments = card.comment_count;
330 let assignees = card.assignees.clone();352 let assignees = card.assignees.clone();
353+ let id = StoredValue::new(card.id.clone());
354+ let open = move || on_open(id.get_value());
331 355
332 view! {356 view! {
333- <article class="card" class:card-done=done_column>357+ // The whole card is the way in: the artboard has no separate control,
358+ // so the card itself carries the role and answers the keyboard.
359+ <article
360+ class="card"
361+ class:card-done=done_column
362+ role="button"
363+ tabindex="0"
364+ on:click=move |_| open()
365+ on:keydown=move |event| {
366+ if event.key() == "Enter" || event.key() == " " {
367+ event.prevent_default();
368+ open();
369+ }
370+ }
371+ >
334 <div class="card-keys">372 <div class="card-keys">
335 <span class="card-key">{card.task_key.clone()}</span>373 <span class="card-key">{card.task_key.clone()}</span>
336 {(blocks > 0)374 {(blocks > 0)
@@ -363,9 +401,15 @@ fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView {
363 .is_empty()401 .is_empty()
364 .then(|| {402 .then(|| {
365 view! {403 view! {
366- <span class="avatar avatar-none" title="Nobody is on this yet">404+ // An empty circle, the avatar's size, in the
367- "?"405+ // avatar's place: the card's bottom row does
368- </span>406+ // not reflow when someone is assigned.
407+ <span
408+ class="avatar avatar-none"
409+ role="img"
410+ aria-label="nobody assigned"
411+ title="Nobody assigned"
412+ ></span>
369 }413 }
370 })}414 })}
371 </div>415 </div>
crates/dizey-web/src/detail.rsadded+963 -0
@@ -0,0 +1,963 @@
1+//! The task detail modal, from the TaskDetail artboard.
2+//!
3+//! One server call brings the whole screen: the task, its assignees, both
4+//! directions of its dependencies, its comments and its activity. Every change
5+//! is its own call, and every one of them checks the task belongs to the
6+//! asker's workspace before it does anything — a task id in a form is an
7+//! authorization question, not a validation one.
8+
9+use dizey_core::board::Person;
10+use dizey_core::detail::{Comment, DependencyEdge, TaskDetail};
11+use leptos::prelude::*;
12+use serde::{Deserialize, Serialize};
13+use time::Date;
14+
15+use crate::auth::{Me, Refusal};
16+
17+/// A task this board could be linked to: enough to name it in the picker and
18+/// nothing more.
19+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
20+pub struct LinkTarget {
21+ pub id: String,
22+ pub task_key: String,
23+ pub title: String,
24+}
25+
26+/// One task detail's worth of state.
27+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
28+pub struct DetailSnapshot {
29+ pub detail: TaskDetail,
30+ pub me: Me,
31+ pub today: Date,
32+ /// What the "Link a task" picker may offer — never this task, never one it
33+ /// is already linked to.
34+ pub linkable: Vec<LinkTarget>,
35+ pub may_write: bool,
36+ pub may_comment: bool,
37+ /// The workspace's delete policy, already applied to this person.
38+ pub may_delete: bool,
39+}
40+
41+/// Which way round a dependency runs, as it travels in a form.
42+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
43+#[serde(rename_all = "snake_case")]
44+pub enum Direction {
45+ /// The other task must finish before this one can start.
46+ BlockedBy,
47+ /// The other task is waiting on this one.
48+ Blocks,
49+}
50+
51+#[cfg(feature = "ssr")]
52+mod guard {
53+ use crate::auth::Refusal;
54+ use dizey_core::detail::TaskFacts;
55+ use dizey_core::store::User;
56+
57+ /// The task, if this person's workspace is the one holding it. A task in
58+ /// another workspace is not found rather than forbidden: the answer says
59+ /// nothing about whether the id is real.
60+ pub async fn task_of(user: &User, task_id: &str) -> Result<TaskFacts, Refusal> {
61+ let store = crate::server::accounts().store().clone();
62+ match store.task(task_id).await {
63+ Ok(Some(facts)) if facts.workspace_id == user.workspace_id => Ok(facts),
64+ Ok(_) => Err(Refusal::NotFound),
65+ Err(error) => {
66+ eprintln!("store error: {error}");
67+ Err(Refusal::Unavailable)
68+ }
69+ }
70+ }
71+
72+ /// The writer behind this request and the task they named.
73+ pub async fn writer_and_task(task_id: &str) -> Result<(User, TaskFacts), Refusal> {
74+ let user = crate::server::require_writer().await?;
75+ let facts = task_of(&user, task_id).await?;
76+ Ok((user, facts))
77+ }
78+}
79+
80+/// Everything one task detail shows. A Viewer may read it; what they may not do
81+/// is refused in the calls below, not merely hidden from them here.
82+#[server]
83+pub async fn fetch_task(task_id: String) -> Result<Result<DetailSnapshot, Refusal>, ServerFnError> {
84+ use crate::server::{accounts, require_user};
85+ use dizey_core::detail::load;
86+ use dizey_core::store::DeletePolicy;
87+ use time::OffsetDateTime;
88+
89+ let user = match require_user().await {
90+ Ok(user) => user,
91+ Err(refusal) => return Ok(Err(refusal)),
92+ };
93+ let store = accounts().store().clone();
94+ let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string());
95+
96+ let Some(detail) = load(store.as_ref(), &user.workspace_id, &task_id)
97+ .await
98+ .map_err(fail)?
99+ else {
100+ return Ok(Err(Refusal::NotFound));
101+ };
102+
103+ // What the picker may offer: this board's other tasks, minus the ones
104+ // already on either end of a link with this one.
105+ let mut linkable = Vec::new();
106+ if let Some(board) = store.board(&user.workspace_id).await.map_err(fail)? {
107+ let taken: Vec<&str> = detail
108+ .blocked_by
109+ .iter()
110+ .chain(detail.blocks.iter())
111+ .map(|edge| edge.task_id.as_str())
112+ .collect();
113+ for task in store.tasks_for_board(&board.id).await.map_err(fail)? {
114+ if task.id == detail.id || taken.contains(&task.id.as_str()) {
115+ continue;
116+ }
117+ linkable.push(LinkTarget {
118+ id: task.id,
119+ task_key: task.task_key,
120+ title: task.title,
121+ });
122+ }
123+ linkable.sort_by(|a, b| a.task_key.cmp(&b.task_key));
124+ }
125+
126+ 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+ };
138+
139+ Ok(Ok(DetailSnapshot {
140+ detail,
141+ linkable,
142+ may_write,
143+ may_comment: user.role.can_comment(),
144+ may_delete,
145+ me: Me {
146+ id: user.id,
147+ display_name: user.display_name,
148+ email: user.email,
149+ role: user.role,
150+ },
151+ today: OffsetDateTime::now_utc().date(),
152+ }))
153+}
154+
155+/// Saves the title, the description and the deadline. Status is not here: the
156+/// column a task sits in is changed by moving it, which is the next slice.
157+#[server]
158+pub async fn save_task(
159+ task_id: String,
160+ title: String,
161+ description: String,
162+ deadline: String,
163+) -> Result<Option<Refusal>, ServerFnError> {
164+ use crate::server::accounts;
165+ use time::OffsetDateTime;
166+ use time::macros::format_description;
167+
168+ let (user, _) = match guard::writer_and_task(&task_id).await {
169+ Ok(pair) => pair,
170+ Err(refusal) => return Ok(Some(refusal)),
171+ };
172+ let title = title.trim().to_string();
173+ if title.is_empty() {
174+ return Ok(Some(Refusal::EmptyTitle));
175+ }
176+ let deadline = match deadline.trim() {
177+ "" => None,
178+ raw => match Date::parse(raw, format_description!("[year]-[month]-[day]")) {
179+ Ok(day) => Some(day),
180+ Err(_) => return Ok(Some(Refusal::BadDeadline)),
181+ },
182+ };
183+
184+ accounts()
185+ .store()
186+ .save_task(
187+ &task_id,
188+ &title,
189+ description.trim(),
190+ deadline,
191+ &user.id,
192+ OffsetDateTime::now_utc(),
193+ )
194+ .await
195+ .map_err(|e| ServerFnError::new(e.to_string()))?;
196+ Ok(None)
197+}
198+
199+/// Puts someone on a task. A Viewer can neither do this nor be the target: a
200+/// viewer cannot be given work.
201+#[server]
202+pub async fn assign(task_id: String, user_id: String) -> Result<Option<Refusal>, ServerFnError> {
203+ use crate::server::accounts;
204+ use dizey_core::detail::ActivityKind;
205+ use time::OffsetDateTime;
206+
207+ let (actor, _) = match guard::writer_and_task(&task_id).await {
208+ Ok(pair) => pair,
209+ Err(refusal) => return Ok(Some(refusal)),
210+ };
211+ let store = accounts().store().clone();
212+ let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string());
213+
214+ // The person named in the form is checked against this workspace, not
215+ // trusted, and a viewer is refused here rather than left out of the picker.
216+ let Some(person) = store.user(&user_id).await.map_err(fail)? else {
217+ return Ok(Some(Refusal::NotFound));
218+ };
219+ if person.workspace_id != actor.workspace_id {
220+ return Ok(Some(Refusal::NotFound));
221+ }
222+ if !person.role.can_be_assigned() {
223+ return Ok(Some(Refusal::Forbidden));
224+ }
225+
226+ store
227+ .assign_task(&task_id, &person.id)
228+ .await
229+ .map_err(fail)?;
230+ store
231+ .record_activity(
232+ &task_id,
233+ Some(&actor.id),
234+ &ActivityKind::Assigned,
235+ &person.display_name,
236+ OffsetDateTime::now_utc(),
237+ )
238+ .await
239+ .map_err(fail)?;
240+ Ok(None)
241+}
242+
243+#[server]
244+pub async fn unassign(task_id: String, user_id: String) -> Result<Option<Refusal>, ServerFnError> {
245+ use crate::server::accounts;
246+ use dizey_core::detail::ActivityKind;
247+ use time::OffsetDateTime;
248+
249+ let (actor, _) = match guard::writer_and_task(&task_id).await {
250+ Ok(pair) => pair,
251+ Err(refusal) => return Ok(Some(refusal)),
252+ };
253+ let store = accounts().store().clone();
254+ let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string());
255+
256+ let Some(person) = store.user(&user_id).await.map_err(fail)? else {
257+ return Ok(Some(Refusal::NotFound));
258+ };
259+ if person.workspace_id != actor.workspace_id {
260+ return Ok(Some(Refusal::NotFound));
261+ }
262+ store
263+ .unassign_task(&task_id, &person.id)
264+ .await
265+ .map_err(fail)?;
266+ store
267+ .record_activity(
268+ &task_id,
269+ Some(&actor.id),
270+ &ActivityKind::Unassigned,
271+ &person.display_name,
272+ OffsetDateTime::now_utc(),
273+ )
274+ .await
275+ .map_err(fail)?;
276+ Ok(None)
277+}
278+
279+/// Links two tasks. Both ends are checked against the asker's workspace, and a
280+/// link that would close a circle is refused by the store, inside the
281+/// transaction that would have written it.
282+#[server]
283+pub async fn link_tasks(
284+ task_id: String,
285+ other_id: String,
286+ direction: Direction,
287+) -> Result<Option<Refusal>, ServerFnError> {
288+ use crate::server::accounts;
289+ use dizey_core::detail::ActivityKind;
290+ use dizey_core::store::StoreError;
291+ use time::OffsetDateTime;
292+
293+ let (actor, _) = match guard::writer_and_task(&task_id).await {
294+ Ok(pair) => pair,
295+ Err(refusal) => return Ok(Some(refusal)),
296+ };
297+ let other = match guard::task_of(&actor, &other_id).await {
298+ Ok(facts) => facts,
299+ Err(refusal) => return Ok(Some(refusal)),
300+ };
301+
302+ let (blocked, blocking) = match direction {
303+ Direction::BlockedBy => (task_id.clone(), other_id.clone()),
304+ Direction::Blocks => (other_id.clone(), task_id.clone()),
305+ };
306+ let store = accounts().store().clone();
307+ let now = OffsetDateTime::now_utc();
308+ match store.add_dependency(&blocked, &blocking, now).await {
309+ Ok(()) => {}
310+ Err(StoreError::Cycle) => return Ok(Some(Refusal::Cycle)),
311+ Err(error) => return Err(ServerFnError::new(error.to_string())),
312+ }
313+ store
314+ .record_activity(
315+ &task_id,
316+ Some(&actor.id),
317+ &ActivityKind::Linked,
318+ &other.row.task_key,
319+ now,
320+ )
321+ .await
322+ .map_err(|e| ServerFnError::new(e.to_string()))?;
323+ Ok(None)
324+}
325+
326+/// Clears a link. The row stays, marked cleared, so the history — and the
327+/// rules engine — still has something to read.
328+#[server]
329+pub async fn unlink_tasks(
330+ task_id: String,
331+ other_id: String,
332+ direction: Direction,
333+) -> Result<Option<Refusal>, ServerFnError> {
334+ use crate::server::accounts;
335+ use dizey_core::detail::ActivityKind;
336+ use time::OffsetDateTime;
337+
338+ let (actor, _) = match guard::writer_and_task(&task_id).await {
339+ Ok(pair) => pair,
340+ Err(refusal) => return Ok(Some(refusal)),
341+ };
342+ let other = match guard::task_of(&actor, &other_id).await {
343+ Ok(facts) => facts,
344+ Err(refusal) => return Ok(Some(refusal)),
345+ };
346+
347+ let (blocked, blocking) = match direction {
348+ Direction::BlockedBy => (task_id.clone(), other_id.clone()),
349+ Direction::Blocks => (other_id.clone(), task_id.clone()),
350+ };
351+ let store = accounts().store().clone();
352+ let now = OffsetDateTime::now_utc();
353+ let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string());
354+ store
355+ .clear_dependency(&blocked, &blocking, now)
356+ .await
357+ .map_err(fail)?;
358+ store
359+ .record_activity(
360+ &task_id,
361+ Some(&actor.id),
362+ &ActivityKind::Unlinked,
363+ &other.row.task_key,
364+ now,
365+ )
366+ .await
367+ .map_err(fail)?;
368+ Ok(None)
369+}
370+
371+/// Writes a comment. The author is the session's user; there is no author field
372+/// on the form. A Viewer is refused here, not merely shown no textarea.
373+#[server]
374+pub async fn post_comment(task_id: String, body: String) -> Result<Option<Refusal>, ServerFnError> {
375+ use crate::server::{accounts, require_user};
376+ use time::OffsetDateTime;
377+
378+ let user = match require_user().await {
379+ Ok(user) => user,
380+ Err(refusal) => return Ok(Some(refusal)),
381+ };
382+ if !user.role.can_comment() {
383+ return Ok(Some(Refusal::Forbidden));
384+ }
385+ if let Err(refusal) = guard::task_of(&user, &task_id).await {
386+ return Ok(Some(refusal));
387+ }
388+ let body = body.trim();
389+ if body.is_empty() {
390+ return Ok(Some(Refusal::EmptyComment));
391+ }
392+
393+ accounts()
394+ .store()
395+ .add_comment(&task_id, &user.id, body, OffsetDateTime::now_utc())
396+ .await
397+ .map_err(|e| ServerFnError::new(e.to_string()))?;
398+ Ok(None)
399+}
400+
401+/// Deletes a task, subject to the workspace's policy. Whatever was waiting only
402+/// on it becomes unblocked, and the store records that.
403+#[server]
404+pub async fn delete_task(task_id: String) -> Result<Option<Refusal>, ServerFnError> {
405+ use crate::server::accounts;
406+ use dizey_core::store::DeletePolicy;
407+ use time::OffsetDateTime;
408+
409+ let (user, _) = match guard::writer_and_task(&task_id).await {
410+ Ok(pair) => pair,
411+ Err(refusal) => return Ok(Some(refusal)),
412+ };
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
426+ .delete_task(&task_id, &user.id, OffsetDateTime::now_utc())
427+ .await
428+ .map_err(fail)?;
429+ Ok(None)
430+}
431+
432+// -- the screen -------------------------------------------------------------
433+
434+/// The modal. `esc` closes it, as the artboard's chip says.
435+#[component]
436+pub fn TaskDetailModal(
437+ task_id: String,
438+ on_close: impl Fn() + Copy + Send + Sync + 'static,
439+ on_change: impl Fn() + Copy + Send + Sync + 'static,
440+) -> impl IntoView {
441+ let task_id = StoredValue::new(task_id);
442+ let detail = Resource::new(
443+ move || task_id.get_value(),
444+ |id| async move { fetch_task(id).await },
445+ );
446+ // Every change writes and then re-reads: the modal shows what the store
447+ // says, not what the browser hoped.
448+ let changed = move || {
449+ detail.refetch();
450+ on_change();
451+ };
452+
453+ view! {
454+ <div
455+ class="modal-scrim"
456+ on:click=move |_| on_close()
457+ on:keydown=move |event| {
458+ if event.key() == "Escape" {
459+ on_close();
460+ }
461+ }
462+ >
463+ <div
464+ class="modal"
465+ tabindex="-1"
466+ autofocus
467+ on:click=move |event| event.stop_propagation()
468+ on:keydown=move |event| {
469+ if event.key() == "Escape" {
470+ on_close();
471+ }
472+ }
473+ >
474+ <Suspense fallback=|| {
475+ view! { <div class="modal-loading"></div> }
476+ }>
477+ {move || Suspend::new(async move {
478+ match detail.await {
479+ Ok(Ok(snapshot)) => {
480+ view! {
481+ <DetailScreen
482+ snapshot=snapshot
483+ on_close=on_close
484+ on_change=changed
485+ />
486+ }
487+ .into_any()
488+ }
489+ Ok(Err(refusal)) => {
490+ view! { <p class="modal-note">{refusal.message()}</p> }.into_any()
491+ }
492+ Err(_) => {
493+ view! {
494+ <p class="modal-note">"Something went wrong. Reload the page."</p>
495+ }
496+ .into_any()
497+ }
498+ }
499+ })}
500+ </Suspense>
501+ </div>
502+ </div>
503+ }
504+}
505+
506+#[component]
507+fn DetailScreen(
508+ snapshot: DetailSnapshot,
509+ on_close: impl Fn() + Copy + Send + Sync + 'static,
510+ on_change: impl Fn() + Copy + Send + Sync + 'static,
511+) -> impl IntoView {
512+ let DetailSnapshot {
513+ detail,
514+ me: _,
515+ today,
516+ linkable,
517+ may_write,
518+ may_comment,
519+ may_delete,
520+ } = snapshot;
521+
522+ let id = StoredValue::new(detail.id.clone());
523+ let task_key = detail.task_key.clone();
524+ let title = detail.title.clone();
525+ let title_field = detail.title.clone();
526+ let description = detail.description.clone();
527+ let description_field = detail.description.clone();
528+ let status = detail.column.name.clone();
529+ let deadline_input = detail.deadline_input();
530+ let overdue = detail.is_overdue(today);
531+ let deadline_label = detail.deadline_label(today);
532+ let assignee_count = detail.assignees.len();
533+ let unassigned: Vec<Person> = detail.unassigned().cloned().collect();
534+
535+ let save = ServerAction::<SaveTask>::new();
536+ let comment = ServerAction::<PostComment>::new();
537+ let link = ServerAction::<LinkTasks>::new();
538+ let remove = ServerAction::<DeleteTask>::new();
539+ // Every action that lands re-reads the task and the board behind it.
540+ for value in [save.value(), comment.value(), link.value()] {
541+ Effect::new(move |_| {
542+ if matches!(value.get(), Some(Ok(None))) {
543+ on_change();
544+ }
545+ });
546+ }
547+ let removed = remove.value();
548+ Effect::new(move |_| {
549+ if matches!(removed.get(), Some(Ok(None))) {
550+ on_change();
551+ on_close();
552+ }
553+ });
554+
555+ let problem = move || {
556+ [save.value(), comment.value(), link.value(), remove.value()]
557+ .into_iter()
558+ .find_map(|value| value.get().and_then(|answer| answer.ok().flatten()))
559+ .map(|refusal| view! { <p class="modal-problem">{refusal.message()}</p> })
560+ };
561+
562+ view! {
563+ <header class="detail-head">
564+ <span class="detail-key">{task_key}</span>
565+ <h2 class="detail-title">{title}</h2>
566+ <div class="spacer"></div>
567+ <span class="detail-esc">"esc"</span>
568+ <button class="detail-close" type="button" on:click=move |_| on_close()>
569+ "✕"
570+ </button>
571+ </header>
572+
573+ <div class="detail-fields">
574+ <div class="detail-field">
575+ <span class="detail-label">"STATUS"</span>
576+ // Read-only this slice: moving a card is the transition the
577+ // mail rules watch, and it lands with the drag.
578+ <span class="detail-value">{status}</span>
579+ </div>
580+ <div class="detail-field">
581+ <span class="detail-label">
582+ {format!("ASSIGNEES — {assignee_count}")}
583+ </span>
584+ <div class="detail-assignees">
585+ {detail
586+ .assignees
587+ .iter()
588+ .map(|person| {
589+ view! {
590+ <AssigneeChip
591+ task_id=id
592+ person=person.clone()
593+ may_write=may_write
594+ on_change=on_change
595+ />
596+ }
597+ })
598+ .collect_view()}
599+ {may_write
600+ .then(|| {
601+ view! { <AssigneePicker task_id=id people=unassigned on_change=on_change/> }
602+ })}
603+ </div>
604+ </div>
605+ <div class="detail-field">
606+ <span class="detail-label">"DEADLINE"</span>
607+ <span class="detail-value" class:detail-overdue=overdue>
608+ {deadline_label}
609+ </span>
610+ </div>
611+ </div>
612+
613+ <ActionForm action=save attr:class="detail-form">
614+ <input type="hidden" name="task_id" value=move || id.get_value()/>
615+ <span class="detail-label">"TITLE"</span>
616+ <input
617+ class="detail-input"
618+ type="text"
619+ name="title"
620+ value=title_field
621+ required
622+ disabled=!may_write
623+ />
624+ <span class="detail-label">"DESCRIPTION"</span>
625+ <textarea
626+ class="detail-textarea"
627+ name="description"
628+ rows="4"
629+ disabled=!may_write
630+ prop:value=description_field
631+ >
632+ {description}
633+ </textarea>
634+ <span class="detail-label">"DEADLINE"</span>
635+ <input
636+ class="detail-input detail-date"
637+ type="date"
638+ name="deadline"
639+ value=deadline_input
640+ disabled=!may_write
641+ />
642+ {may_write
643+ .then(|| {
644+ view! {
645+ <div class="detail-form-row">
646+ <button
647+ class="detail-save"
648+ type="submit"
649+ disabled=move || save.pending().get()
650+ >
651+ "Save"
652+ </button>
653+ </div>
654+ }
655+ })}
656+ </ActionForm>
657+
658+ <section class="detail-section">
659+ <div class="detail-section-head">
660+ <span class="detail-label">"DEPENDENCIES"</span>
661+ </div>
662+ {(!detail.blocked_by.is_empty())
663+ .then(|| {
664+ view! {
665+ <div class="dep-group">
666+ <span class="dep-heading">"BLOCKED BY"</span>
667+ {detail
668+ .blocked_by
669+ .iter()
670+ .map(|edge| {
671+ view! {
672+ <DepRow
673+ task_id=id
674+ edge=edge.clone()
675+ direction=Direction::BlockedBy
676+ may_write=may_write
677+ on_change=on_change
678+ />
679+ }
680+ })
681+ .collect_view()}
682+ </div>
683+ }
684+ })}
685+ {(!detail.blocks.is_empty())
686+ .then(|| {
687+ view! {
688+ <div class="dep-group">
689+ <span class="dep-heading">"BLOCKS"</span>
690+ {detail
691+ .blocks
692+ .iter()
693+ .map(|edge| {
694+ view! {
695+ <DepRow
696+ task_id=id
697+ edge=edge.clone()
698+ direction=Direction::Blocks
699+ may_write=may_write
700+ on_change=on_change
701+ />
702+ }
703+ })
704+ .collect_view()}
705+ </div>
706+ }
707+ })}
708+ {(may_write && !linkable.is_empty())
709+ .then(|| {
710+ view! {
711+ <ActionForm action=link attr:class="dep-link">
712+ <input type="hidden" name="task_id" value=move || id.get_value()/>
713+ <select class="dep-select" name="other_id">
714+ {linkable
715+ .iter()
716+ .map(|target| {
717+ view! {
718+ <option value=target.id.clone()>
719+ {format!("{} {}", target.task_key, target.title)}
720+ </option>
721+ }
722+ })
723+ .collect_view()}
724+ </select>
725+ <select class="dep-select" name="direction">
726+ <option value="blocked_by">"blocks this task"</option>
727+ <option value="blocks">"waits on this task"</option>
728+ </select>
729+ <button class="dep-add" type="submit" disabled=move || link.pending().get()>
730+ "Link a task"
731+ </button>
732+ </ActionForm>
733+ }
734+ })}
735+ </section>
736+
737+ <section class="detail-section">
738+ <span class="detail-label">"COMMENTS"</span>
739+ {detail
740+ .comments
741+ .iter()
742+ .map(|entry| view! { <CommentRow comment=entry.clone()/> })
743+ .collect_view()}
744+ {may_comment
745+ .then(|| {
746+ view! {
747+ <ActionForm action=comment attr:class="comment-composer">
748+ <input type="hidden" name="task_id" value=move || id.get_value()/>
749+ <textarea
750+ class="comment-input"
751+ name="body"
752+ rows="3"
753+ placeholder="Write a comment…"
754+ required
755+ ></textarea>
756+ <div class="comment-row">
757+ <span class="comment-hint">"⌘↵ to post"</span>
758+ <div class="spacer"></div>
759+ <button
760+ class="comment-post"
761+ type="submit"
762+ disabled=move || comment.pending().get()
763+ >
764+ "Comment"
765+ </button>
766+ </div>
767+ </ActionForm>
768+ }
769+ })}
770+ </section>
771+
772+ <section class="detail-section">
773+ <span class="detail-label">"ACTIVITY"</span>
774+ {detail
775+ .activity
776+ .iter()
777+ .map(|entry| {
778+ let who = entry
779+ .actor
780+ .as_ref()
781+ .map(|person| person.display_name.clone())
782+ .unwrap_or_else(|| "Dizey".to_string());
783+ view! {
784+ <div class="activity-line">
785+ <span class="activity-stamp">{entry.moment()}</span>
786+ <strong class="activity-who">{who}</strong>
787+ <span class="activity-what">{entry.sentence()}</span>
788+ </div>
789+ }
790+ })
791+ .collect_view()}
792+ </section>
793+
794+ {problem}
795+
796+ <footer class="detail-foot">
797+ {may_delete
798+ .then(|| {
799+ view! {
800+ <ActionForm action=remove attr:class="detail-delete-form">
801+ <input type="hidden" name="task_id" value=move || id.get_value()/>
802+ <button
803+ class="detail-delete"
804+ type="submit"
805+ disabled=move || remove.pending().get()
806+ >
807+ "Delete task"
808+ </button>
809+ </ActionForm>
810+ }
811+ })}
812+ <div class="spacer"></div>
813+ <button class="detail-cancel" type="button" on:click=move |_| on_close()>
814+ "Close"
815+ </button>
816+ </footer>
817+ }
818+}
819+
820+#[component]
821+fn AssigneeChip(
822+ task_id: StoredValue<String>,
823+ person: Person,
824+ may_write: bool,
825+ on_change: impl Fn() + Copy + Send + Sync + 'static,
826+) -> impl IntoView {
827+ let action = ServerAction::<Unassign>::new();
828+ let value = action.value();
829+ Effect::new(move |_| {
830+ if matches!(value.get(), Some(Ok(None))) {
831+ on_change();
832+ }
833+ });
834+ let name = person.display_name.clone();
835+
836+ view! {
837+ <span class="assignee-chip">
838+ {name.clone()}
839+ {may_write
840+ .then(|| {
841+ view! {
842+ <ActionForm action=action attr:class="assignee-drop">
843+ <input type="hidden" name="task_id" value=move || task_id.get_value()/>
844+ <input type="hidden" name="user_id" value=person.id.clone()/>
845+ <button
846+ class="assignee-remove"
847+ type="submit"
848+ title=format!("Take {name} off this task")
849+ >
850+ "✕"
851+ </button>
852+ </ActionForm>
853+ }
854+ })}
855+ </span>
856+ }
857+}
858+
859+#[component]
860+fn AssigneePicker(
861+ task_id: StoredValue<String>,
862+ people: Vec<Person>,
863+ on_change: impl Fn() + Copy + Send + Sync + 'static,
864+) -> impl IntoView {
865+ let action = ServerAction::<Assign>::new();
866+ let value = action.value();
867+ Effect::new(move |_| {
868+ if matches!(value.get(), Some(Ok(None))) {
869+ on_change();
870+ }
871+ });
872+ let empty = people.is_empty();
873+
874+ view! {
875+ {(!empty)
876+ .then(|| {
877+ view! {
878+ <ActionForm action=action attr:class="assignee-add">
879+ <input type="hidden" name="task_id" value=move || task_id.get_value()/>
880+ <select class="assignee-select" name="user_id">
881+ {people
882+ .iter()
883+ .map(|person| {
884+ view! {
885+ <option value=person.id.clone()>{person.display_name.clone()}</option>
886+ }
887+ })
888+ .collect_view()}
889+ </select>
890+ <button class="assignee-assign" type="submit">
891+ "Assign"
892+ </button>
893+ </ActionForm>
894+ }
895+ })}
896+ }
897+}
898+
899+#[component]
900+fn DepRow(
901+ task_id: StoredValue<String>,
902+ edge: DependencyEdge,
903+ direction: Direction,
904+ may_write: bool,
905+ on_change: impl Fn() + Copy + Send + Sync + 'static,
906+) -> impl IntoView {
907+ let action = ServerAction::<UnlinkTasks>::new();
908+ let value = action.value();
909+ Effect::new(move |_| {
910+ if matches!(value.get(), Some(Ok(None))) {
911+ on_change();
912+ }
913+ });
914+ let cleared = edge.is_cleared();
915+ let note = match direction {
916+ Direction::BlockedBy => edge.blocked_by_label(),
917+ Direction::Blocks => edge.blocks_label(),
918+ };
919+ let waiting = matches!(direction, Direction::Blocks);
920+ let other_id = edge.task_id.clone();
921+ let wire = match direction {
922+ Direction::BlockedBy => "blocked_by",
923+ Direction::Blocks => "blocks",
924+ };
925+
926+ view! {
927+ <div class="dep-row" class:dep-row-waiting=waiting>
928+ {cleared.then(|| view! { <span class="dep-tick">"✓"</span> })}
929+ <span class="dep-key">{edge.task_key.clone()}</span>
930+ <span class="dep-title">{edge.title.clone()}</span>
931+ <div class="spacer"></div>
932+ <span class="dep-note">{note}</span>
933+ {(may_write && !cleared)
934+ .then(|| {
935+ view! {
936+ <ActionForm action=action attr:class="dep-unlink-form">
937+ <input type="hidden" name="task_id" value=move || task_id.get_value()/>
938+ <input type="hidden" name="other_id" value=other_id/>
939+ <input type="hidden" name="direction" value=wire/>
940+ <button class="dep-unlink" type="submit" title="Remove this link">
941+ "✕"
942+ </button>
943+ </ActionForm>
944+ }
945+ })}
946+ </div>
947+ }
948+}
949+
950+#[component]
951+fn CommentRow(comment: Comment) -> impl IntoView {
952+ use dizey_core::detail::moment_label;
953+
954+ view! {
955+ <div class="comment">
956+ <div class="comment-head">
957+ <span class="comment-who">{comment.author.display_name.clone()}</span>
958+ <span class="comment-when">{moment_label(comment.at)}</span>
959+ </div>
960+ <div class="comment-body">{comment.body.clone()}</div>
961+ </div>
962+ }
963+}
crates/dizey-web/src/lib.rsmodified+1 -0
@@ -1,6 +1,7 @@
1 pub mod app;1 pub mod app;
2 pub mod auth;2 pub mod auth;
3 pub mod board;3 pub mod board;
4+pub mod detail;
4 pub mod pages;5 pub mod pages;
5 #[cfg(feature = "ssr")]6 #[cfg(feature = "ssr")]
6 pub mod server;7 pub mod server;
crates/dizey-web/tests/http.rsmodified+232 -14
@@ -28,18 +28,23 @@ use uuid::Uuid;
28 struct App {28 struct App {
29 dir: PathBuf,29 dir: PathBuf,
30 router: Router,30 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>,
31 }34 }
32 35
33 impl App {36 impl App {
34 async fn open() -> Self {37 async fn open() -> Self {
35 let dir = std::env::temp_dir().join(format!("dizey-http-{}", Uuid::new_v4()));38 let dir = std::env::temp_dir().join(format!("dizey-http-{}", Uuid::new_v4()));
36 std::fs::create_dir_all(&dir).unwrap();39 std::fs::create_dir_all(&dir).unwrap();
37- let store = TursoStore::open(dir.join("dizey.db").to_str().unwrap())40+ let store = Arc::new(
38- .await41+ TursoStore::open(dir.join("dizey.db").to_str().unwrap())
39- .unwrap();42+ .await
43+ .unwrap(),
44+ );
40 let options = LeptosOptions::builder().output_name("dizey").build();45 let options = LeptosOptions::builder().output_name("dizey").build();
41- let router = dizey_web::server::router(Accounts::new(Arc::new(store)), options);46+ let router = dizey_web::server::router(Accounts::new(store.clone()), options);
42- Self { dir, router }47+ Self { dir, router, store }
43 }48 }
44 49
45 /// Posts a form to a server function, as the browser does, and returns the50 /// Posts a form to a server function, as the browser does, and returns the
@@ -196,21 +201,17 @@ async fn first_column(app: &App, cookie: &str) -> String {
196 async fn a_viewer_who_posts_to_create_task_anyway_is_refused() {201 async fn a_viewer_who_posts_to_create_task_anyway_is_refused() {
197 let app = App::open().await;202 let app = App::open().await;
198 let admin = admin(&app).await;203 let admin = admin(&app).await;
199- let viewer = invited(204+ let viewer = invited(&app, &admin, "quiet@dizey.sh", "Quiet Reader", Role::Viewer).await;
200- &app,
201- &admin,
202- "quiet@dizey.sh",
203- "Quiet Reader",
204- Role::Viewer,
205- )
206- .await;
207 let column = first_column(&app, &admin).await;205 let column = first_column(&app, &admin).await;
208 206
209 let answer = app207 let answer = app
210 .post(208 .post(
211 path::<dizey_web::board::CreateTask>(),209 path::<dizey_web::board::CreateTask>(),
212 Some(&viewer),210 Some(&viewer),
213- &[("title", "Viewer should not get this"), ("column_id", &column)],211+ &[
212+ ("title", "Viewer should not get this"),
213+ ("column_id", &column),
214+ ],
214 )215 )
215 .await;216 .await;
216 217
@@ -295,3 +296,220 @@ async fn the_board_is_not_readable_without_a_session() {
295 .await;296 .await;
296 assert_eq!(answer.body, "{\"Err\":\"SignInFirst\"}");297 assert_eq!(answer.body, "{\"Err\":\"SignInFirst\"}");
297 }298 }
299+
300+/// Makes a task and hands back its id, read off the board the way the browser
301+/// would.
302+async fn a_task(app: &App, cookie: &str, column: &str, title: &str) -> String {
303+ let answer = app
304+ .post(
305+ path::<dizey_web::board::CreateTask>(),
306+ Some(cookie),
307+ &[("title", title), ("column_id", column)],
308+ )
309+ .await;
310+ assert_eq!(answer.body, "null", "the task was refused: {}", answer.body);
311+
312+ let answer = app
313+ .post(path::<dizey_web::board::CurrentBoard>(), Some(cookie), &[])
314+ .await;
315+ let needle = format!("\"title\":\"{title}\"");
316+ let before = answer
317+ .body
318+ .split_once(&needle)
319+ .map(|(head, _)| head)
320+ .expect("the new task is not on the board");
321+ before
322+ .rsplit_once("{\"id\":\"")
323+ .and_then(|(_, rest)| rest.split('"').next())
324+ .expect("no id on the new task")
325+ .to_string()
326+}
327+
328+#[tokio::test]
329+async fn a_viewer_who_posts_a_comment_anyway_is_refused() {
330+ let app = App::open().await;
331+ let admin = admin(&app).await;
332+ let viewer = invited(&app, &admin, "eyes@dizey.sh", "Ida Eyes", Role::Viewer).await;
333+ let column = first_column(&app, &admin).await;
334+ let task = a_task(&app, &admin, &column, "Ship the detail modal").await;
335+
336+ let answer = app
337+ .post(
338+ path::<dizey_web::detail::PostComment>(),
339+ Some(&viewer),
340+ &[("task_id", &task), ("body", "Viewers cannot say this")],
341+ )
342+ .await;
343+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
344+ assert_eq!(answer.body, "\"Forbidden\"");
345+
346+ // The refusal is not cosmetic: nothing was written.
347+ let answer = app
348+ .post(
349+ path::<dizey_web::detail::FetchTask>(),
350+ Some(&admin),
351+ &[("task_id", &task)],
352+ )
353+ .await;
354+ assert!(
355+ !answer.body.contains("Viewers cannot say this"),
356+ "the refused comment was written anyway: {}",
357+ answer.body
358+ );
359+}
360+
361+#[tokio::test]
362+async fn a_member_may_comment_and_the_author_is_the_session() {
363+ let app = App::open().await;
364+ let admin = admin(&app).await;
365+ let member = invited(&app, &admin, "kai@dizey.sh", "Kai Renner", Role::Member).await;
366+ let column = first_column(&app, &admin).await;
367+ let task = a_task(&app, &admin, &column, "Wire the picker").await;
368+
369+ let answer = app
370+ .post(
371+ path::<dizey_web::detail::PostComment>(),
372+ Some(&member),
373+ &[("task_id", &task), ("body", "Picker is narrow on purpose")],
374+ )
375+ .await;
376+ assert_eq!(answer.body, "null", "a member was refused: {}", answer.body);
377+
378+ let answer = app
379+ .post(
380+ path::<dizey_web::detail::FetchTask>(),
381+ Some(&admin),
382+ &[("task_id", &task)],
383+ )
384+ .await;
385+ assert!(answer.body.contains("Picker is narrow on purpose"));
386+ assert!(
387+ answer.body.contains("Kai Renner"),
388+ "the comment is not attributed to the session's user: {}",
389+ answer.body
390+ );
391+}
392+
393+#[tokio::test]
394+async fn a_link_that_would_close_a_circle_is_refused_at_the_endpoint() {
395+ let app = App::open().await;
396+ let admin = admin(&app).await;
397+ let column = first_column(&app, &admin).await;
398+ let first = a_task(&app, &admin, &column, "Lay the cable").await;
399+ let second = a_task(&app, &admin, &column, "Light the cable").await;
400+
401+ let answer = app
402+ .post(
403+ path::<dizey_web::detail::LinkTasks>(),
404+ Some(&admin),
405+ &[
406+ ("task_id", &second),
407+ ("other_id", &first),
408+ ("direction", "blocked_by"),
409+ ],
410+ )
411+ .await;
412+ assert_eq!(
413+ answer.body, "null",
414+ "the first link was refused: {}",
415+ answer.body
416+ );
417+
418+ let answer = app
419+ .post(
420+ path::<dizey_web::detail::LinkTasks>(),
421+ Some(&admin),
422+ &[
423+ ("task_id", &first),
424+ ("other_id", &second),
425+ ("direction", "blocked_by"),
426+ ],
427+ )
428+ .await;
429+ assert_eq!(answer.body, "\"Cycle\"");
430+}
431+
432+#[tokio::test]
433+async fn a_task_id_from_nowhere_is_not_found() {
434+ let app = App::open().await;
435+ let admin = admin(&app).await;
436+
437+ let answer = app
438+ .post(
439+ path::<dizey_web::detail::FetchTask>(),
440+ Some(&admin),
441+ &[("task_id", "00000000-0000-0000-0000-000000000000")],
442+ )
443+ .await;
444+ assert_eq!(answer.body, "{\"Err\":\"NotFound\"}");
445+}
446+
447+#[tokio::test]
448+async fn a_viewer_who_posts_a_delete_anyway_is_refused() {
449+ let app = App::open().await;
450+ let admin = admin(&app).await;
451+ let viewer = invited(&app, &admin, "wren@dizey.sh", "Wren Ash", Role::Viewer).await;
452+ let column = first_column(&app, &admin).await;
453+ let task = a_task(&app, &admin, &column, "Viewers cannot remove this").await;
454+
455+ let answer = app
456+ .post(
457+ path::<dizey_web::detail::DeleteTask>(),
458+ Some(&viewer),
459+ &[("task_id", &task)],
460+ )
461+ .await;
462+ assert_eq!(answer.body, "\"Forbidden\"");
463+
464+ let answer = app
465+ .post(path::<dizey_web::board::CurrentBoard>(), Some(&admin), &[])
466+ .await;
467+ assert!(
468+ answer.body.contains("Viewers cannot remove this"),
469+ "the refused delete happened anyway: {}",
470+ answer.body
471+ );
472+}
473+
474+#[tokio::test]
475+async fn a_member_cannot_delete_when_the_workspace_says_admins_only() {
476+ use dizey_core::store::{DeletePolicy, Store};
477+
478+ let app = App::open().await;
479+ let admin = admin(&app).await;
480+ let member = invited(&app, &admin, "rae@dizey.sh", "Rae Okonkwo", Role::Member).await;
481+ 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,
494+ )
495+ .await
496+ .unwrap();
497+
498+ let answer = app
499+ .post(
500+ path::<dizey_web::detail::DeleteTask>(),
501+ Some(&member),
502+ &[("task_id", &task)],
503+ )
504+ .await;
505+ assert_eq!(answer.body, "\"Forbidden\"");
506+
507+ let answer = app
508+ .post(path::<dizey_web::board::CurrentBoard>(), Some(&admin), &[])
509+ .await;
510+ assert!(
511+ answer.body.contains("Not yours to remove"),
512+ "the refused delete happened anyway: {}",
513+ answer.body
514+ );
515+}
style/main.scssmodified+386 -3
@@ -445,6 +445,12 @@ a {
445 border-radius: 8px;445 border-radius: 8px;
446 padding: 12px;446 padding: 12px;
447 box-shadow: 0 1px 2px rgba(28, 27, 24, 0.05);447 box-shadow: 0 1px 2px rgba(28, 27, 24, 0.05);
448+ cursor: pointer;
449+
450+ &:focus-visible {
451+ outline: 2px solid var(--accent);
452+ outline-offset: 1px;
453+ }
448 }454 }
449 455
450 .card-done {456 .card-done {
@@ -530,10 +536,8 @@ a {
530 & + & { margin-left: -7px; }536 & + & { margin-left: -7px; }
531 537
532 &-none {538 &-none {
533- border: 1px dashed #c9c5ba;539+ border: 1px dashed var(--border-strong);
534- color: var(--muted-soft);
535 background: transparent;540 background: transparent;
536- font-size: 12px;
537 }541 }
538 542
539 &-tone-0 { background: #46557b; }543 &-tone-0 { background: #46557b; }
@@ -623,3 +627,382 @@ a {
623 color: var(--muted);627 color: var(--muted);
624 cursor: pointer;628 cursor: pointer;
625 }629 }
630+
631+// -- the task detail modal --------------------------------------------------
632+
633+.modal-scrim {
634+ position: fixed;
635+ inset: 0;
636+ background: rgba(28, 27, 24, 0.28);
637+ display: flex;
638+ align-items: flex-start;
639+ justify-content: center;
640+ padding: 48px 24px;
641+ overflow-y: auto;
642+ z-index: 20;
643+}
644+
645+.modal {
646+ width: 780px;
647+ max-width: 100%;
648+ background: var(--surface);
649+ border: 1px solid var(--border);
650+ border-radius: 12px;
651+ box-shadow: 0 12px 40px rgba(28, 27, 24, 0.18);
652+ padding: 20px 24px 16px;
653+ outline: none;
654+}
655+
656+.modal-loading { height: 220px; }
657+
658+.modal-note,
659+.modal-problem {
660+ margin: 8px 0 0;
661+ font-size: 13px;
662+ color: #a04a24;
663+}
664+
665+.detail-head {
666+ display: flex;
667+ align-items: center;
668+ gap: 10px;
669+}
670+
671+.detail-key {
672+ font-family: var(--font-mono);
673+ font-size: 11px;
674+ color: var(--muted-soft);
675+}
676+
677+.detail-title {
678+ margin: 0;
679+ font-size: 20px;
680+ font-weight: 600;
681+}
682+
683+.detail-esc {
684+ font-family: var(--font-mono);
685+ font-size: 10px;
686+ color: var(--muted-soft);
687+ border: 1px solid var(--border-strong);
688+ border-radius: 4px;
689+ padding: 1px 5px;
690+}
691+
692+.detail-close {
693+ border: none;
694+ background: none;
695+ color: var(--muted);
696+ font-size: 14px;
697+ cursor: pointer;
698+ padding: 2px 4px;
699+}
700+
701+.detail-fields {
702+ display: grid;
703+ grid-template-columns: 1fr 1.5fr 1fr;
704+ gap: 12px;
705+ margin-top: 18px;
706+}
707+
708+.detail-field {
709+ display: flex;
710+ flex-direction: column;
711+ gap: 6px;
712+}
713+
714+.detail-label {
715+ font-size: 10px;
716+ font-weight: 600;
717+ letter-spacing: 0.08em;
718+ color: var(--muted-soft);
719+}
720+
721+.detail-value {
722+ min-height: 36px;
723+ display: flex;
724+ align-items: center;
725+ padding: 0 10px;
726+ background: #faf9f6;
727+ border: 1px solid var(--border-strong);
728+ border-radius: var(--radius);
729+ font-size: 13px;
730+}
731+
732+.detail-overdue {
733+ border-color: #e8c9b8;
734+ color: #a04a24;
735+}
736+
737+.detail-assignees {
738+ min-height: 36px;
739+ display: flex;
740+ align-items: center;
741+ flex-wrap: wrap;
742+ gap: 6px;
743+ padding: 4px 6px;
744+ background: #faf9f6;
745+ border: 1px solid var(--border-strong);
746+ border-radius: var(--radius);
747+}
748+
749+.assignee-chip {
750+ display: inline-flex;
751+ align-items: center;
752+ gap: 4px;
753+ font-size: 12px;
754+ background: var(--surface);
755+ border: 1px solid var(--border-strong);
756+ border-radius: 11px;
757+ padding: 2px 4px 2px 8px;
758+}
759+
760+.assignee-drop { display: inline-flex; }
761+
762+.assignee-remove {
763+ border: none;
764+ background: none;
765+ color: var(--muted-soft);
766+ font-size: 10px;
767+ cursor: pointer;
768+ padding: 0 2px;
769+}
770+
771+.assignee-add {
772+ display: inline-flex;
773+ gap: 4px;
774+}
775+
776+.assignee-select,
777+.dep-select {
778+ font-family: inherit;
779+ font-size: 12px;
780+ background: var(--surface);
781+ border: 1px solid var(--border-strong);
782+ border-radius: 4px;
783+ padding: 2px 4px;
784+ max-width: 220px;
785+}
786+
787+.assignee-assign,
788+.dep-add {
789+ font-family: inherit;
790+ font-size: 12px;
791+ background: var(--surface);
792+ border: 1px solid var(--border-strong);
793+ border-radius: 4px;
794+ padding: 2px 8px;
795+ cursor: pointer;
796+}
797+
798+.detail-form {
799+ display: flex;
800+ flex-direction: column;
801+ gap: 6px;
802+ margin-top: 20px;
803+}
804+
805+.detail-input,
806+.detail-textarea,
807+.comment-input {
808+ font-family: inherit;
809+ font-size: 14px;
810+ color: #3d3a34;
811+ background: var(--surface);
812+ border: 1px solid var(--border-strong);
813+ border-radius: var(--radius);
814+ padding: 8px 10px;
815+ resize: vertical;
816+}
817+
818+.detail-textarea { line-height: 1.6; }
819+
820+.detail-date { width: 160px; }
821+
822+.detail-form-row {
823+ display: flex;
824+ justify-content: flex-end;
825+}
826+
827+.detail-save,
828+.comment-post {
829+ font-family: inherit;
830+ font-size: 13px;
831+ color: #fffefb;
832+ background: var(--accent);
833+ border: 1px solid var(--accent);
834+ border-radius: var(--radius);
835+ padding: 6px 14px;
836+ cursor: pointer;
837+
838+ &:disabled { opacity: 0.6; cursor: default; }
839+}
840+
841+.detail-section {
842+ display: flex;
843+ flex-direction: column;
844+ gap: 8px;
845+ margin-top: 22px;
846+}
847+
848+.dep-group {
849+ display: flex;
850+ flex-direction: column;
851+ gap: 6px;
852+}
853+
854+.dep-heading {
855+ font-size: 10px;
856+ font-weight: 600;
857+ letter-spacing: 0.08em;
858+ color: var(--muted-soft);
859+}
860+
861+.dep-row {
862+ display: flex;
863+ align-items: center;
864+ gap: 8px;
865+ min-height: 34px;
866+ padding: 0 10px;
867+ background: #faf9f6;
868+ border: 1px solid var(--border-strong);
869+ border-radius: var(--radius);
870+ font-size: 13px;
871+}
872+
873+.dep-row-waiting {
874+ background: #fdfaf1;
875+ border-color: #e6d7ae;
876+
877+ .dep-note { color: #7a5c1e; }
878+}
879+
880+.dep-tick { color: #5c7b46; }
881+
882+.dep-key {
883+ font-family: var(--font-mono);
884+ font-size: 11px;
885+ color: var(--muted-soft);
886+}
887+
888+.dep-note {
889+ font-size: 12px;
890+ color: var(--muted);
891+}
892+
893+.dep-unlink-form { display: inline-flex; }
894+
895+.dep-unlink {
896+ border: none;
897+ background: none;
898+ color: var(--muted-soft);
899+ font-size: 11px;
900+ cursor: pointer;
901+}
902+
903+.dep-link {
904+ display: flex;
905+ align-items: center;
906+ gap: 6px;
907+}
908+
909+.comment {
910+ display: flex;
911+ flex-direction: column;
912+ gap: 3px;
913+}
914+
915+.comment-head {
916+ display: flex;
917+ align-items: baseline;
918+ gap: 8px;
919+}
920+
921+.comment-who {
922+ font-size: 13px;
923+ font-weight: 600;
924+}
925+
926+.comment-when {
927+ font-family: var(--font-mono);
928+ font-size: 11px;
929+ color: var(--muted-soft);
930+}
931+
932+.comment-body {
933+ font-size: 13px;
934+ line-height: 1.55;
935+ color: #3d3a34;
936+ white-space: pre-wrap;
937+}
938+
939+.comment-composer {
940+ display: flex;
941+ flex-direction: column;
942+ gap: 6px;
943+ margin-top: 4px;
944+}
945+
946+.comment-row {
947+ display: flex;
948+ align-items: center;
949+ gap: 8px;
950+}
951+
952+.comment-hint {
953+ font-family: var(--font-mono);
954+ font-size: 10px;
955+ color: var(--muted-soft);
956+ border: 1px solid var(--border-strong);
957+ border-radius: 4px;
958+ padding: 1px 5px;
959+}
960+
961+.activity-line {
962+ display: flex;
963+ align-items: baseline;
964+ gap: 8px;
965+ font-size: 12px;
966+ color: var(--muted);
967+}
968+
969+.activity-stamp {
970+ font-family: var(--font-mono);
971+ font-size: 11px;
972+ color: var(--muted-soft);
973+}
974+
975+.activity-who { color: var(--ink); }
976+
977+.detail-foot {
978+ display: flex;
979+ align-items: center;
980+ gap: 8px;
981+ margin-top: 22px;
982+ padding-top: 14px;
983+ border-top: 1px solid var(--border);
984+}
985+
986+.detail-delete-form { display: inline-flex; }
987+
988+.detail-delete {
989+ font-family: inherit;
990+ font-size: 13px;
991+ color: #a04a24;
992+ background: none;
993+ border: 1px solid #e8c9b8;
994+ border-radius: var(--radius);
995+ padding: 6px 12px;
996+ cursor: pointer;
997+}
998+
999+.detail-cancel {
1000+ font-family: inherit;
1001+ font-size: 13px;
1002+ color: var(--muted);
1003+ background: var(--surface);
1004+ border: 1px solid var(--border-strong);
1005+ border-radius: var(--radius);
1006+ padding: 6px 12px;
1007+ cursor: pointer;
1008+}