From b0f8661c6ef561a574a8372f4dff13692ee689e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 26 Aug 2026 09:35:14 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(web):=20the=20task=20detail,?= =?UTF-8?q?=20and=20the=20refusals=20behind=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 26 +- crates/dizey-web/src/board.rs | 66 ++- crates/dizey-web/src/detail.rs | 963 +++++++++++++++++++++++++++++++++ crates/dizey-web/src/lib.rs | 1 + crates/dizey-web/tests/http.rs | 246 ++++++++- style/main.scss | 389 ++++++++++++- 6 files changed, 1653 insertions(+), 38 deletions(-) create mode 100644 crates/dizey-web/src/detail.rs diff --git a/crates/dizey-web/src/auth.rs b/crates/dizey-web/src/auth.rs index 5f7aa82..2758dee 100644 --- a/crates/dizey-web/src/auth.rs +++ b/crates/dizey-web/src/auth.rs @@ -26,6 +26,15 @@ pub enum Refusal { LinkNotUsable, /// A card with no title is not a card. EmptyTitle, + /// A comment with nothing in it. + EmptyComment, + /// The date field did not hold a date. + BadDeadline, + /// The link asked for would put a task behind itself. + Cycle, + /// No such task — or none this account may see. Deliberately one answer for + /// both. + NotFound, Unavailable, } @@ -42,10 +51,13 @@ impl Refusal { Refusal::AlreadyClaimed => "This workspace already has an owner.".to_string(), Refusal::AddressTaken => "That address already has an account.".to_string(), Refusal::LinkNotUsable => { - "This link no longer works. Ask the admin to send another." - .to_string() + "This link no longer works. Ask the admin to send another.".to_string() } Refusal::EmptyTitle => "Give the task a title.".to_string(), + Refusal::EmptyComment => "Write something first.".to_string(), + Refusal::BadDeadline => "That is not a date.".to_string(), + Refusal::Cycle => "That link would put this task behind itself.".to_string(), + Refusal::NotFound => "No such task.".to_string(), Refusal::Unavailable => "Something went wrong. Try again.".to_string(), } } @@ -189,17 +201,11 @@ pub async fn redeem_link( /// Signing in. Answers the same whether the address is unknown, has no password /// yet, or the password is wrong. #[server] -pub async fn sign_in( - email: String, - password: String, -) -> Result, ServerFnError> { +pub async fn sign_in(email: String, password: String) -> Result, ServerFnError> { use crate::server::{accounts, client_label, set_session_cookie}; use dizey_core::accounts::SESSION_LIFETIME; - match accounts() - .sign_in(&email, &password, &client_label()) - .await - { + match accounts().sign_in(&email, &password, &client_label()).await { Ok(signed_in) => { set_session_cookie(signed_in.session_token.expose(), SESSION_LIFETIME); Ok(None) diff --git a/crates/dizey-web/src/board.rs b/crates/dizey-web/src/board.rs index 8bf9b05..8e1b932 100644 --- a/crates/dizey-web/src/board.rs +++ b/crates/dizey-web/src/board.rs @@ -162,16 +162,15 @@ fn BoardScreen( let filter = RwSignal::new(Filter::All); // Which column has its composer open, if any. let composing = RwSignal::new(None::); + // Which card is open in the detail modal, if any. + let opened = RwSignal::new(None::); let may_write = me.role.can_write_tasks(); let my_id = StoredValue::new(me.id.clone()); // The New task button opens the composer in the first column, which is // where a new card belongs when nobody has said otherwise. - let first_column_id = StoredValue::new( - view.columns - .first() - .map(|column| column.column.id.clone()), - ); + let first_column_id = + StoredValue::new(view.columns.first().map(|column| column.column.id.clone())); let overdue = view.overdue_count(today); let blocked = view.blocked_count(); @@ -224,7 +223,12 @@ fn BoardScreen(
- + } })} + {move || { + opened + .get() + .map(|task_id| { + view! { + + } + }) + }} } } @@ -320,7 +337,12 @@ fn FilterTab(filter: RwSignal, this: Filter, label: &'static str) -> imp } #[component] -fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView { +fn Card( + card: TaskCard, + today: Date, + done_column: bool, + on_open: impl Fn(String) + Copy + Send + Sync + 'static, +) -> impl IntoView { let blocks = card.blocks.len(); let blocked_by = card.blocked_by.join(", "); let deadline = card.deadline_label(today); @@ -328,9 +350,25 @@ fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView { let dated = card.deadline.is_some() || card.is_done(); let comments = card.comment_count; let assignees = card.assignees.clone(); + let id = StoredValue::new(card.id.clone()); + let open = move || on_open(id.get_value()); view! { -
+ // The whole card is the way in: the artboard has no separate control, + // so the card itself carries the role and answers the keyboard. +
{card.task_key.clone()} {(blocks > 0) @@ -363,9 +401,15 @@ fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView { .is_empty() .then(|| { view! { - - "?" - + // An empty circle, the avatar's size, in the + // avatar's place: the card's bottom row does + // not reflow when someone is assigned. + } })}
diff --git a/crates/dizey-web/src/detail.rs b/crates/dizey-web/src/detail.rs new file mode 100644 index 0000000..4775b3a --- /dev/null +++ b/crates/dizey-web/src/detail.rs @@ -0,0 +1,963 @@ +//! The task detail modal, from the TaskDetail artboard. +//! +//! One server call brings the whole screen: the task, its assignees, both +//! directions of its dependencies, its comments and its activity. Every change +//! is its own call, and every one of them checks the task belongs to the +//! asker's workspace before it does anything — a task id in a form is an +//! authorization question, not a validation one. + +use dizey_core::board::Person; +use dizey_core::detail::{Comment, DependencyEdge, TaskDetail}; +use leptos::prelude::*; +use serde::{Deserialize, Serialize}; +use time::Date; + +use crate::auth::{Me, Refusal}; + +/// A task this board could be linked to: enough to name it in the picker and +/// nothing more. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct LinkTarget { + pub id: String, + pub task_key: String, + pub title: String, +} + +/// One task detail's worth of state. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct DetailSnapshot { + pub detail: TaskDetail, + pub me: Me, + pub today: Date, + /// What the "Link a task" picker may offer — never this task, never one it + /// is already linked to. + pub linkable: Vec, + pub may_write: bool, + pub may_comment: bool, + /// The workspace's delete policy, already applied to this person. + pub may_delete: bool, +} + +/// Which way round a dependency runs, as it travels in a form. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum Direction { + /// The other task must finish before this one can start. + BlockedBy, + /// The other task is waiting on this one. + Blocks, +} + +#[cfg(feature = "ssr")] +mod guard { + use crate::auth::Refusal; + use dizey_core::detail::TaskFacts; + use dizey_core::store::User; + + /// The task, if this person's workspace is the one holding it. A task in + /// another workspace is not found rather than forbidden: the answer says + /// nothing about whether the id is real. + pub async fn task_of(user: &User, task_id: &str) -> Result { + let store = crate::server::accounts().store().clone(); + match store.task(task_id).await { + Ok(Some(facts)) if facts.workspace_id == user.workspace_id => Ok(facts), + Ok(_) => Err(Refusal::NotFound), + Err(error) => { + eprintln!("store error: {error}"); + Err(Refusal::Unavailable) + } + } + } + + /// The writer behind this request and the task they named. + pub async fn writer_and_task(task_id: &str) -> Result<(User, TaskFacts), Refusal> { + let user = crate::server::require_writer().await?; + let facts = task_of(&user, task_id).await?; + Ok((user, facts)) + } +} + +/// Everything one task detail shows. A Viewer may read it; what they may not do +/// is refused in the calls below, not merely hidden from them here. +#[server] +pub async fn fetch_task(task_id: String) -> Result, ServerFnError> { + use crate::server::{accounts, require_user}; + use dizey_core::detail::load; + use dizey_core::store::DeletePolicy; + use time::OffsetDateTime; + + let user = match require_user().await { + Ok(user) => user, + Err(refusal) => return Ok(Err(refusal)), + }; + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + + let Some(detail) = load(store.as_ref(), &user.workspace_id, &task_id) + .await + .map_err(fail)? + else { + return Ok(Err(Refusal::NotFound)); + }; + + // What the picker may offer: this board's other tasks, minus the ones + // already on either end of a link with this one. + let mut linkable = Vec::new(); + if let Some(board) = store.board(&user.workspace_id).await.map_err(fail)? { + let taken: Vec<&str> = detail + .blocked_by + .iter() + .chain(detail.blocks.iter()) + .map(|edge| edge.task_id.as_str()) + .collect(); + for task in store.tasks_for_board(&board.id).await.map_err(fail)? { + if task.id == detail.id || taken.contains(&task.id.as_str()) { + continue; + } + linkable.push(LinkTarget { + id: task.id, + task_key: task.task_key, + title: task.title, + }); + } + linkable.sort_by(|a, b| a.task_key.cmp(&b.task_key)); + } + + let may_write = user.role.can_write_tasks(); + let policy = store + .workspace() + .await + .map_err(fail)? + .map(|workspace| workspace.who_can_delete_tasks) + .unwrap_or(DeletePolicy::Admin); + let may_delete = may_write + && match policy { + DeletePolicy::Anyone => true, + DeletePolicy::Admin => user.role.can_administer(), + }; + + Ok(Ok(DetailSnapshot { + detail, + linkable, + may_write, + may_comment: user.role.can_comment(), + may_delete, + me: Me { + id: user.id, + display_name: user.display_name, + email: user.email, + role: user.role, + }, + today: OffsetDateTime::now_utc().date(), + })) +} + +/// Saves the title, the description and the deadline. Status is not here: the +/// column a task sits in is changed by moving it, which is the next slice. +#[server] +pub async fn save_task( + task_id: String, + title: String, + description: String, + deadline: String, +) -> Result, ServerFnError> { + use crate::server::accounts; + use time::OffsetDateTime; + use time::macros::format_description; + + let (user, _) = match guard::writer_and_task(&task_id).await { + Ok(pair) => pair, + Err(refusal) => return Ok(Some(refusal)), + }; + let title = title.trim().to_string(); + if title.is_empty() { + return Ok(Some(Refusal::EmptyTitle)); + } + let deadline = match deadline.trim() { + "" => None, + raw => match Date::parse(raw, format_description!("[year]-[month]-[day]")) { + Ok(day) => Some(day), + Err(_) => return Ok(Some(Refusal::BadDeadline)), + }, + }; + + accounts() + .store() + .save_task( + &task_id, + &title, + description.trim(), + deadline, + &user.id, + OffsetDateTime::now_utc(), + ) + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + Ok(None) +} + +/// Puts someone on a task. A Viewer can neither do this nor be the target: a +/// viewer cannot be given work. +#[server] +pub async fn assign(task_id: String, user_id: String) -> Result, ServerFnError> { + use crate::server::accounts; + use dizey_core::detail::ActivityKind; + use time::OffsetDateTime; + + let (actor, _) = match guard::writer_and_task(&task_id).await { + Ok(pair) => pair, + Err(refusal) => return Ok(Some(refusal)), + }; + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + + // The person named in the form is checked against this workspace, not + // trusted, and a viewer is refused here rather than left out of the picker. + let Some(person) = store.user(&user_id).await.map_err(fail)? else { + return Ok(Some(Refusal::NotFound)); + }; + if person.workspace_id != actor.workspace_id { + return Ok(Some(Refusal::NotFound)); + } + if !person.role.can_be_assigned() { + return Ok(Some(Refusal::Forbidden)); + } + + store + .assign_task(&task_id, &person.id) + .await + .map_err(fail)?; + store + .record_activity( + &task_id, + Some(&actor.id), + &ActivityKind::Assigned, + &person.display_name, + OffsetDateTime::now_utc(), + ) + .await + .map_err(fail)?; + Ok(None) +} + +#[server] +pub async fn unassign(task_id: String, user_id: String) -> Result, ServerFnError> { + use crate::server::accounts; + use dizey_core::detail::ActivityKind; + use time::OffsetDateTime; + + let (actor, _) = match guard::writer_and_task(&task_id).await { + Ok(pair) => pair, + Err(refusal) => return Ok(Some(refusal)), + }; + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + + let Some(person) = store.user(&user_id).await.map_err(fail)? else { + return Ok(Some(Refusal::NotFound)); + }; + if person.workspace_id != actor.workspace_id { + return Ok(Some(Refusal::NotFound)); + } + store + .unassign_task(&task_id, &person.id) + .await + .map_err(fail)?; + store + .record_activity( + &task_id, + Some(&actor.id), + &ActivityKind::Unassigned, + &person.display_name, + OffsetDateTime::now_utc(), + ) + .await + .map_err(fail)?; + Ok(None) +} + +/// Links two tasks. Both ends are checked against the asker's workspace, and a +/// link that would close a circle is refused by the store, inside the +/// transaction that would have written it. +#[server] +pub async fn link_tasks( + task_id: String, + other_id: String, + direction: Direction, +) -> Result, ServerFnError> { + use crate::server::accounts; + use dizey_core::detail::ActivityKind; + use dizey_core::store::StoreError; + use time::OffsetDateTime; + + let (actor, _) = match guard::writer_and_task(&task_id).await { + Ok(pair) => pair, + Err(refusal) => return Ok(Some(refusal)), + }; + let other = match guard::task_of(&actor, &other_id).await { + Ok(facts) => facts, + Err(refusal) => return Ok(Some(refusal)), + }; + + let (blocked, blocking) = match direction { + Direction::BlockedBy => (task_id.clone(), other_id.clone()), + Direction::Blocks => (other_id.clone(), task_id.clone()), + }; + let store = accounts().store().clone(); + let now = OffsetDateTime::now_utc(); + match store.add_dependency(&blocked, &blocking, now).await { + Ok(()) => {} + Err(StoreError::Cycle) => return Ok(Some(Refusal::Cycle)), + Err(error) => return Err(ServerFnError::new(error.to_string())), + } + store + .record_activity( + &task_id, + Some(&actor.id), + &ActivityKind::Linked, + &other.row.task_key, + now, + ) + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + Ok(None) +} + +/// Clears a link. The row stays, marked cleared, so the history — and the +/// rules engine — still has something to read. +#[server] +pub async fn unlink_tasks( + task_id: String, + other_id: String, + direction: Direction, +) -> Result, ServerFnError> { + use crate::server::accounts; + use dizey_core::detail::ActivityKind; + use time::OffsetDateTime; + + let (actor, _) = match guard::writer_and_task(&task_id).await { + Ok(pair) => pair, + Err(refusal) => return Ok(Some(refusal)), + }; + let other = match guard::task_of(&actor, &other_id).await { + Ok(facts) => facts, + Err(refusal) => return Ok(Some(refusal)), + }; + + let (blocked, blocking) = match direction { + Direction::BlockedBy => (task_id.clone(), other_id.clone()), + Direction::Blocks => (other_id.clone(), task_id.clone()), + }; + let store = accounts().store().clone(); + let now = OffsetDateTime::now_utc(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + store + .clear_dependency(&blocked, &blocking, now) + .await + .map_err(fail)?; + store + .record_activity( + &task_id, + Some(&actor.id), + &ActivityKind::Unlinked, + &other.row.task_key, + now, + ) + .await + .map_err(fail)?; + Ok(None) +} + +/// Writes a comment. The author is the session's user; there is no author field +/// on the form. A Viewer is refused here, not merely shown no textarea. +#[server] +pub async fn post_comment(task_id: String, body: String) -> Result, ServerFnError> { + use crate::server::{accounts, require_user}; + use time::OffsetDateTime; + + let user = match require_user().await { + Ok(user) => user, + Err(refusal) => return Ok(Some(refusal)), + }; + if !user.role.can_comment() { + return Ok(Some(Refusal::Forbidden)); + } + if let Err(refusal) = guard::task_of(&user, &task_id).await { + return Ok(Some(refusal)); + } + let body = body.trim(); + if body.is_empty() { + return Ok(Some(Refusal::EmptyComment)); + } + + accounts() + .store() + .add_comment(&task_id, &user.id, body, OffsetDateTime::now_utc()) + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + Ok(None) +} + +/// Deletes a task, subject to the workspace's policy. Whatever was waiting only +/// on it becomes unblocked, and the store records that. +#[server] +pub async fn delete_task(task_id: String) -> Result, ServerFnError> { + use crate::server::accounts; + use dizey_core::store::DeletePolicy; + use time::OffsetDateTime; + + let (user, _) = match guard::writer_and_task(&task_id).await { + Ok(pair) => pair, + Err(refusal) => return Ok(Some(refusal)), + }; + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + let policy = store + .workspace() + .await + .map_err(fail)? + .map(|workspace| workspace.who_can_delete_tasks) + .unwrap_or(DeletePolicy::Admin); + if matches!(policy, DeletePolicy::Admin) && !user.role.can_administer() { + return Ok(Some(Refusal::Forbidden)); + } + + store + .delete_task(&task_id, &user.id, OffsetDateTime::now_utc()) + .await + .map_err(fail)?; + Ok(None) +} + +// -- the screen ------------------------------------------------------------- + +/// The modal. `esc` closes it, as the artboard's chip says. +#[component] +pub fn TaskDetailModal( + task_id: String, + on_close: impl Fn() + Copy + Send + Sync + 'static, + on_change: impl Fn() + Copy + Send + Sync + 'static, +) -> impl IntoView { + let task_id = StoredValue::new(task_id); + let detail = Resource::new( + move || task_id.get_value(), + |id| async move { fetch_task(id).await }, + ); + // Every change writes and then re-reads: the modal shows what the store + // says, not what the browser hoped. + let changed = move || { + detail.refetch(); + on_change(); + }; + + view! { + +
+ } +} + +#[component] +fn DetailScreen( + snapshot: DetailSnapshot, + on_close: impl Fn() + Copy + Send + Sync + 'static, + on_change: impl Fn() + Copy + Send + Sync + 'static, +) -> impl IntoView { + let DetailSnapshot { + detail, + me: _, + today, + linkable, + may_write, + may_comment, + may_delete, + } = snapshot; + + let id = StoredValue::new(detail.id.clone()); + let task_key = detail.task_key.clone(); + let title = detail.title.clone(); + let title_field = detail.title.clone(); + let description = detail.description.clone(); + let description_field = detail.description.clone(); + let status = detail.column.name.clone(); + let deadline_input = detail.deadline_input(); + let overdue = detail.is_overdue(today); + let deadline_label = detail.deadline_label(today); + let assignee_count = detail.assignees.len(); + let unassigned: Vec = detail.unassigned().cloned().collect(); + + let save = ServerAction::::new(); + let comment = ServerAction::::new(); + let link = ServerAction::::new(); + let remove = ServerAction::::new(); + // Every action that lands re-reads the task and the board behind it. + for value in [save.value(), comment.value(), link.value()] { + Effect::new(move |_| { + if matches!(value.get(), Some(Ok(None))) { + on_change(); + } + }); + } + let removed = remove.value(); + Effect::new(move |_| { + if matches!(removed.get(), Some(Ok(None))) { + on_change(); + on_close(); + } + }); + + let problem = move || { + [save.value(), comment.value(), link.value(), remove.value()] + .into_iter() + .find_map(|value| value.get().and_then(|answer| answer.ok().flatten())) + .map(|refusal| view! { }) + }; + + view! { +
+ {task_key} +

{title}

+
+ "esc" + +
+ +
+
+ "STATUS" + // Read-only this slice: moving a card is the transition the + // mail rules watch, and it lands with the drag. + {status} +
+
+ + {format!("ASSIGNEES — {assignee_count}")} + +
+ {detail + .assignees + .iter() + .map(|person| { + view! { + + } + }) + .collect_view()} + {may_write + .then(|| { + view! { } + })} +
+
+
+ "DEADLINE" + + {deadline_label} + +
+
+ + + + "TITLE" + + "DESCRIPTION" + + "DEADLINE" + + {may_write + .then(|| { + view! { +
+ +
+ } + })} +
+ +
+
+ "DEPENDENCIES" +
+ {(!detail.blocked_by.is_empty()) + .then(|| { + view! { +
+ "BLOCKED BY" + {detail + .blocked_by + .iter() + .map(|edge| { + view! { + + } + }) + .collect_view()} +
+ } + })} + {(!detail.blocks.is_empty()) + .then(|| { + view! { +
+ "BLOCKS" + {detail + .blocks + .iter() + .map(|edge| { + view! { + + } + }) + .collect_view()} +
+ } + })} + {(may_write && !linkable.is_empty()) + .then(|| { + view! { + + + + + + + } + })} +
+ +
+ "COMMENTS" + {detail + .comments + .iter() + .map(|entry| view! { }) + .collect_view()} + {may_comment + .then(|| { + view! { + + + +
+ "⌘↵ to post" +
+ +
+
+ } + })} +
+ +
+ "ACTIVITY" + {detail + .activity + .iter() + .map(|entry| { + let who = entry + .actor + .as_ref() + .map(|person| person.display_name.clone()) + .unwrap_or_else(|| "Dizey".to_string()); + view! { +
+ {entry.moment()} + {who} + {entry.sentence()} +
+ } + }) + .collect_view()} +
+ + {problem} + +
+ {may_delete + .then(|| { + view! { + + + + + } + })} +
+ +
+ } +} + +#[component] +fn AssigneeChip( + task_id: StoredValue, + person: Person, + may_write: bool, + on_change: impl Fn() + Copy + Send + Sync + 'static, +) -> impl IntoView { + let action = ServerAction::::new(); + let value = action.value(); + Effect::new(move |_| { + if matches!(value.get(), Some(Ok(None))) { + on_change(); + } + }); + let name = person.display_name.clone(); + + view! { + + {name.clone()} + {may_write + .then(|| { + view! { + + + + + + } + })} + + } +} + +#[component] +fn AssigneePicker( + task_id: StoredValue, + people: Vec, + on_change: impl Fn() + Copy + Send + Sync + 'static, +) -> impl IntoView { + let action = ServerAction::::new(); + let value = action.value(); + Effect::new(move |_| { + if matches!(value.get(), Some(Ok(None))) { + on_change(); + } + }); + let empty = people.is_empty(); + + view! { + {(!empty) + .then(|| { + view! { + + + + + + } + })} + } +} + +#[component] +fn DepRow( + task_id: StoredValue, + edge: DependencyEdge, + direction: Direction, + may_write: bool, + on_change: impl Fn() + Copy + Send + Sync + 'static, +) -> impl IntoView { + let action = ServerAction::::new(); + let value = action.value(); + Effect::new(move |_| { + if matches!(value.get(), Some(Ok(None))) { + on_change(); + } + }); + let cleared = edge.is_cleared(); + let note = match direction { + Direction::BlockedBy => edge.blocked_by_label(), + Direction::Blocks => edge.blocks_label(), + }; + let waiting = matches!(direction, Direction::Blocks); + let other_id = edge.task_id.clone(); + let wire = match direction { + Direction::BlockedBy => "blocked_by", + Direction::Blocks => "blocks", + }; + + view! { +
+ {cleared.then(|| view! { "✓" })} + {edge.task_key.clone()} + {edge.title.clone()} +
+ {note} + {(may_write && !cleared) + .then(|| { + view! { + + + + + + + } + })} +
+ } +} + +#[component] +fn CommentRow(comment: Comment) -> impl IntoView { + use dizey_core::detail::moment_label; + + view! { +
+
+ {comment.author.display_name.clone()} + {moment_label(comment.at)} +
+
{comment.body.clone()}
+
+ } +} diff --git a/crates/dizey-web/src/lib.rs b/crates/dizey-web/src/lib.rs index 297e502..d40d906 100644 --- a/crates/dizey-web/src/lib.rs +++ b/crates/dizey-web/src/lib.rs @@ -1,6 +1,7 @@ pub mod app; pub mod auth; pub mod board; +pub mod detail; pub mod pages; #[cfg(feature = "ssr")] pub mod server; diff --git a/crates/dizey-web/tests/http.rs b/crates/dizey-web/tests/http.rs index 944264d..be76978 100644 --- a/crates/dizey-web/tests/http.rs +++ b/crates/dizey-web/tests/http.rs @@ -28,18 +28,23 @@ use uuid::Uuid; struct App { dir: PathBuf, router: Router, + /// The same store the router talks to, so a test can set a workspace + /// setting that has no screen yet. + store: Arc, } impl App { async fn open() -> Self { let dir = std::env::temp_dir().join(format!("dizey-http-{}", Uuid::new_v4())); std::fs::create_dir_all(&dir).unwrap(); - let store = TursoStore::open(dir.join("dizey.db").to_str().unwrap()) - .await - .unwrap(); + let store = Arc::new( + TursoStore::open(dir.join("dizey.db").to_str().unwrap()) + .await + .unwrap(), + ); let options = LeptosOptions::builder().output_name("dizey").build(); - let router = dizey_web::server::router(Accounts::new(Arc::new(store)), options); - Self { dir, router } + let router = dizey_web::server::router(Accounts::new(store.clone()), options); + Self { dir, router, store } } /// 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 { async fn a_viewer_who_posts_to_create_task_anyway_is_refused() { let app = App::open().await; let admin = admin(&app).await; - let viewer = invited( - &app, - &admin, - "quiet@dizey.sh", - "Quiet Reader", - Role::Viewer, - ) - .await; + let viewer = invited(&app, &admin, "quiet@dizey.sh", "Quiet Reader", Role::Viewer).await; let column = first_column(&app, &admin).await; let answer = app .post( path::(), Some(&viewer), - &[("title", "Viewer should not get this"), ("column_id", &column)], + &[ + ("title", "Viewer should not get this"), + ("column_id", &column), + ], ) .await; @@ -295,3 +296,220 @@ async fn the_board_is_not_readable_without_a_session() { .await; assert_eq!(answer.body, "{\"Err\":\"SignInFirst\"}"); } + +/// Makes a task and hands back its id, read off the board the way the browser +/// would. +async fn a_task(app: &App, cookie: &str, column: &str, title: &str) -> String { + let answer = app + .post( + path::(), + Some(cookie), + &[("title", title), ("column_id", column)], + ) + .await; + assert_eq!(answer.body, "null", "the task was refused: {}", answer.body); + + let answer = app + .post(path::(), Some(cookie), &[]) + .await; + let needle = format!("\"title\":\"{title}\""); + let before = answer + .body + .split_once(&needle) + .map(|(head, _)| head) + .expect("the new task is not on the board"); + before + .rsplit_once("{\"id\":\"") + .and_then(|(_, rest)| rest.split('"').next()) + .expect("no id on the new task") + .to_string() +} + +#[tokio::test] +async fn a_viewer_who_posts_a_comment_anyway_is_refused() { + let app = App::open().await; + let admin = admin(&app).await; + let viewer = invited(&app, &admin, "eyes@dizey.sh", "Ida Eyes", Role::Viewer).await; + let column = first_column(&app, &admin).await; + let task = a_task(&app, &admin, &column, "Ship the detail modal").await; + + let answer = app + .post( + path::(), + Some(&viewer), + &[("task_id", &task), ("body", "Viewers cannot say this")], + ) + .await; + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + assert_eq!(answer.body, "\"Forbidden\""); + + // The refusal is not cosmetic: nothing was written. + let answer = app + .post( + path::(), + Some(&admin), + &[("task_id", &task)], + ) + .await; + assert!( + !answer.body.contains("Viewers cannot say this"), + "the refused comment was written anyway: {}", + answer.body + ); +} + +#[tokio::test] +async fn a_member_may_comment_and_the_author_is_the_session() { + let app = App::open().await; + let admin = admin(&app).await; + let member = invited(&app, &admin, "kai@dizey.sh", "Kai Renner", Role::Member).await; + let column = first_column(&app, &admin).await; + let task = a_task(&app, &admin, &column, "Wire the picker").await; + + let answer = app + .post( + path::(), + Some(&member), + &[("task_id", &task), ("body", "Picker is narrow on purpose")], + ) + .await; + assert_eq!(answer.body, "null", "a member was refused: {}", answer.body); + + let answer = app + .post( + path::(), + Some(&admin), + &[("task_id", &task)], + ) + .await; + assert!(answer.body.contains("Picker is narrow on purpose")); + assert!( + answer.body.contains("Kai Renner"), + "the comment is not attributed to the session's user: {}", + answer.body + ); +} + +#[tokio::test] +async fn a_link_that_would_close_a_circle_is_refused_at_the_endpoint() { + let app = App::open().await; + let admin = admin(&app).await; + let column = first_column(&app, &admin).await; + let first = a_task(&app, &admin, &column, "Lay the cable").await; + let second = a_task(&app, &admin, &column, "Light the cable").await; + + let answer = app + .post( + path::(), + Some(&admin), + &[ + ("task_id", &second), + ("other_id", &first), + ("direction", "blocked_by"), + ], + ) + .await; + assert_eq!( + answer.body, "null", + "the first link was refused: {}", + answer.body + ); + + let answer = app + .post( + path::(), + Some(&admin), + &[ + ("task_id", &first), + ("other_id", &second), + ("direction", "blocked_by"), + ], + ) + .await; + assert_eq!(answer.body, "\"Cycle\""); +} + +#[tokio::test] +async fn a_task_id_from_nowhere_is_not_found() { + let app = App::open().await; + let admin = admin(&app).await; + + let answer = app + .post( + path::(), + Some(&admin), + &[("task_id", "00000000-0000-0000-0000-000000000000")], + ) + .await; + assert_eq!(answer.body, "{\"Err\":\"NotFound\"}"); +} + +#[tokio::test] +async fn a_viewer_who_posts_a_delete_anyway_is_refused() { + let app = App::open().await; + let admin = admin(&app).await; + let viewer = invited(&app, &admin, "wren@dizey.sh", "Wren Ash", Role::Viewer).await; + let column = first_column(&app, &admin).await; + let task = a_task(&app, &admin, &column, "Viewers cannot remove this").await; + + let answer = app + .post( + path::(), + Some(&viewer), + &[("task_id", &task)], + ) + .await; + assert_eq!(answer.body, "\"Forbidden\""); + + let answer = app + .post(path::(), Some(&admin), &[]) + .await; + assert!( + answer.body.contains("Viewers cannot remove this"), + "the refused delete happened anyway: {}", + answer.body + ); +} + +#[tokio::test] +async fn a_member_cannot_delete_when_the_workspace_says_admins_only() { + use dizey_core::store::{DeletePolicy, Store}; + + let app = App::open().await; + let admin = admin(&app).await; + let member = invited(&app, &admin, "rae@dizey.sh", "Rae Okonkwo", Role::Member).await; + let column = first_column(&app, &admin).await; + let task = a_task(&app, &admin, &column, "Not yours to remove").await; + + // The workspace ships as 'anyone'; the settings screen that flips this is a + // later slice, so the test sets it the way that screen will. + let workspace = app.store.workspace().await.unwrap().unwrap(); + app.store + .set_limits( + &workspace.id, + workspace.attachment_limit_bytes, + workspace.photo_limit_bytes, + &workspace.allowed_file_types, + DeletePolicy::Admin, + ) + .await + .unwrap(); + + let answer = app + .post( + path::(), + Some(&member), + &[("task_id", &task)], + ) + .await; + assert_eq!(answer.body, "\"Forbidden\""); + + let answer = app + .post(path::(), Some(&admin), &[]) + .await; + assert!( + answer.body.contains("Not yours to remove"), + "the refused delete happened anyway: {}", + answer.body + ); +} diff --git a/style/main.scss b/style/main.scss index fd2457d..0775e6d 100644 --- a/style/main.scss +++ b/style/main.scss @@ -445,6 +445,12 @@ a { border-radius: 8px; padding: 12px; box-shadow: 0 1px 2px rgba(28, 27, 24, 0.05); + cursor: pointer; + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 1px; + } } .card-done { @@ -530,10 +536,8 @@ a { & + & { margin-left: -7px; } &-none { - border: 1px dashed #c9c5ba; - color: var(--muted-soft); + border: 1px dashed var(--border-strong); background: transparent; - font-size: 12px; } &-tone-0 { background: #46557b; } @@ -623,3 +627,382 @@ a { color: var(--muted); cursor: pointer; } + +// -- the task detail modal -------------------------------------------------- + +.modal-scrim { + position: fixed; + inset: 0; + background: rgba(28, 27, 24, 0.28); + display: flex; + align-items: flex-start; + justify-content: center; + padding: 48px 24px; + overflow-y: auto; + z-index: 20; +} + +.modal { + width: 780px; + max-width: 100%; + background: var(--surface); + border: 1px solid var(--border); + border-radius: 12px; + box-shadow: 0 12px 40px rgba(28, 27, 24, 0.18); + padding: 20px 24px 16px; + outline: none; +} + +.modal-loading { height: 220px; } + +.modal-note, +.modal-problem { + margin: 8px 0 0; + font-size: 13px; + color: #a04a24; +} + +.detail-head { + display: flex; + align-items: center; + gap: 10px; +} + +.detail-key { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); +} + +.detail-title { + margin: 0; + font-size: 20px; + font-weight: 600; +} + +.detail-esc { + font-family: var(--font-mono); + font-size: 10px; + color: var(--muted-soft); + border: 1px solid var(--border-strong); + border-radius: 4px; + padding: 1px 5px; +} + +.detail-close { + border: none; + background: none; + color: var(--muted); + font-size: 14px; + cursor: pointer; + padding: 2px 4px; +} + +.detail-fields { + display: grid; + grid-template-columns: 1fr 1.5fr 1fr; + gap: 12px; + margin-top: 18px; +} + +.detail-field { + display: flex; + flex-direction: column; + gap: 6px; +} + +.detail-label { + font-size: 10px; + font-weight: 600; + letter-spacing: 0.08em; + color: var(--muted-soft); +} + +.detail-value { + min-height: 36px; + display: flex; + align-items: center; + padding: 0 10px; + background: #faf9f6; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + font-size: 13px; +} + +.detail-overdue { + border-color: #e8c9b8; + color: #a04a24; +} + +.detail-assignees { + min-height: 36px; + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 6px; + padding: 4px 6px; + background: #faf9f6; + border: 1px solid var(--border-strong); + border-radius: var(--radius); +} + +.assignee-chip { + display: inline-flex; + align-items: center; + gap: 4px; + font-size: 12px; + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: 11px; + padding: 2px 4px 2px 8px; +} + +.assignee-drop { display: inline-flex; } + +.assignee-remove { + border: none; + background: none; + color: var(--muted-soft); + font-size: 10px; + cursor: pointer; + padding: 0 2px; +} + +.assignee-add { + display: inline-flex; + gap: 4px; +} + +.assignee-select, +.dep-select { + font-family: inherit; + font-size: 12px; + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: 4px; + padding: 2px 4px; + max-width: 220px; +} + +.assignee-assign, +.dep-add { + font-family: inherit; + font-size: 12px; + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: 4px; + padding: 2px 8px; + cursor: pointer; +} + +.detail-form { + display: flex; + flex-direction: column; + gap: 6px; + margin-top: 20px; +} + +.detail-input, +.detail-textarea, +.comment-input { + font-family: inherit; + font-size: 14px; + color: #3d3a34; + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: var(--radius); + padding: 8px 10px; + resize: vertical; +} + +.detail-textarea { line-height: 1.6; } + +.detail-date { width: 160px; } + +.detail-form-row { + display: flex; + justify-content: flex-end; +} + +.detail-save, +.comment-post { + font-family: inherit; + font-size: 13px; + color: #fffefb; + background: var(--accent); + border: 1px solid var(--accent); + border-radius: var(--radius); + padding: 6px 14px; + cursor: pointer; + + &:disabled { opacity: 0.6; cursor: default; } +} + +.detail-section { + display: flex; + flex-direction: column; + gap: 8px; + margin-top: 22px; +} + +.dep-group { + display: flex; + flex-direction: column; + gap: 6px; +} + +.dep-heading { + font-size: 10px; + font-weight: 600; + letter-spacing: 0.08em; + color: var(--muted-soft); +} + +.dep-row { + display: flex; + align-items: center; + gap: 8px; + min-height: 34px; + padding: 0 10px; + background: #faf9f6; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + font-size: 13px; +} + +.dep-row-waiting { + background: #fdfaf1; + border-color: #e6d7ae; + + .dep-note { color: #7a5c1e; } +} + +.dep-tick { color: #5c7b46; } + +.dep-key { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); +} + +.dep-note { + font-size: 12px; + color: var(--muted); +} + +.dep-unlink-form { display: inline-flex; } + +.dep-unlink { + border: none; + background: none; + color: var(--muted-soft); + font-size: 11px; + cursor: pointer; +} + +.dep-link { + display: flex; + align-items: center; + gap: 6px; +} + +.comment { + display: flex; + flex-direction: column; + gap: 3px; +} + +.comment-head { + display: flex; + align-items: baseline; + gap: 8px; +} + +.comment-who { + font-size: 13px; + font-weight: 600; +} + +.comment-when { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); +} + +.comment-body { + font-size: 13px; + line-height: 1.55; + color: #3d3a34; + white-space: pre-wrap; +} + +.comment-composer { + display: flex; + flex-direction: column; + gap: 6px; + margin-top: 4px; +} + +.comment-row { + display: flex; + align-items: center; + gap: 8px; +} + +.comment-hint { + font-family: var(--font-mono); + font-size: 10px; + color: var(--muted-soft); + border: 1px solid var(--border-strong); + border-radius: 4px; + padding: 1px 5px; +} + +.activity-line { + display: flex; + align-items: baseline; + gap: 8px; + font-size: 12px; + color: var(--muted); +} + +.activity-stamp { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); +} + +.activity-who { color: var(--ink); } + +.detail-foot { + display: flex; + align-items: center; + gap: 8px; + margin-top: 22px; + padding-top: 14px; + border-top: 1px solid var(--border); +} + +.detail-delete-form { display: inline-flex; } + +.detail-delete { + font-family: inherit; + font-size: 13px; + color: #a04a24; + background: none; + border: 1px solid #e8c9b8; + border-radius: var(--radius); + padding: 6px 12px; + cursor: pointer; +} + +.detail-cancel { + font-family: inherit; + font-size: 13px; + color: var(--muted); + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: var(--radius); + padding: 6px 12px; + cursor: pointer; +}