From 40165b43d7878ddf419f1f1220906aca2a15df0a 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:13:07 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(web):=20the=20board=20screen,?= =?UTF-8?q?=20and=20the=20guards=20that=20stand=20behind=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The board a signed-in person lands on: four columns, cards with keys, deadlines, comment counts, dependency chips and stacked assignee avatars, an All tasks / Mine / Blocked filter, and an inline composer on every column that degrades to a plain form without JS. The mutation endpoint is the part that matters. `create_task` sits behind `require_writer`, and the column it is handed is checked against this workspace's own board, so a client cannot post a task into a column it was never shown. The router moved out of `main` into `server::router` so the tests can drive the real handlers: a Viewer who posts to `create_task` anyway gets `Forbidden` and the board stays empty — the absent button is not offered as evidence. --- Cargo.lock | 1 + crates/dizey-web/Cargo.toml | 7 + crates/dizey-web/src/auth.rs | 7 + crates/dizey-web/src/board.rs | 442 +++++++++++++++++++++++++++++++++ crates/dizey-web/src/lib.rs | 1 + crates/dizey-web/src/main.rs | 23 +- crates/dizey-web/src/pages.rs | 22 +- crates/dizey-web/src/server.rs | 31 +++ crates/dizey-web/tests/http.rs | 297 ++++++++++++++++++++++ style/main.scss | 363 +++++++++++++++++++++++++++ 10 files changed, 1160 insertions(+), 34 deletions(-) create mode 100644 crates/dizey-web/src/board.rs create mode 100644 crates/dizey-web/tests/http.rs diff --git a/Cargo.lock b/Cargo.lock index a23511b..a6bc0c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -969,6 +969,7 @@ dependencies = [ "tower", "tower-http 0.7.0", "turso", + "uuid", "wasm-bindgen", ] diff --git a/crates/dizey-web/Cargo.toml b/crates/dizey-web/Cargo.toml index f8392d2..faebe0d 100644 --- a/crates/dizey-web/Cargo.toml +++ b/crates/dizey-web/Cargo.toml @@ -47,3 +47,10 @@ ssr = [ "dizey-core/server", "dep:turso", ] + +# The HTTP test drives the real router, so it needs the server side of the app. +# Run it with `cargo test -p dizey-web --features ssr`. +[dev-dependencies] +tokio = { workspace = true } +tower = { version = "0.5.2", features = ["util"] } +uuid = { workspace = true } diff --git a/crates/dizey-web/src/auth.rs b/crates/dizey-web/src/auth.rs index 729fe95..5f7aa82 100644 --- a/crates/dizey-web/src/auth.rs +++ b/crates/dizey-web/src/auth.rs @@ -24,6 +24,8 @@ pub enum Refusal { AddressTaken, /// The link is spent, expired, or was never real. LinkNotUsable, + /// A card with no title is not a card. + EmptyTitle, Unavailable, } @@ -43,6 +45,7 @@ impl Refusal { "This link no longer works. Ask the admin to send another." .to_string() } + Refusal::EmptyTitle => "Give the task a title.".to_string(), Refusal::Unavailable => "Something went wrong. Try again.".to_string(), } } @@ -51,6 +54,9 @@ impl Refusal { /// The person the current browser is signed in as. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Me { + /// The account id, so the board can tell "Mine" from everyone else's + /// without a second call. + pub id: String, pub display_name: String, pub email: String, pub role: dizey_core::Role, @@ -85,6 +91,7 @@ pub async fn current_gate() -> Result { if let Some(user) = current_user().await { return Ok(Gate::SignedIn(Me { + id: user.id, display_name: user.display_name, email: user.email, role: user.role, diff --git a/crates/dizey-web/src/board.rs b/crates/dizey-web/src/board.rs new file mode 100644 index 0000000..8bf9b05 --- /dev/null +++ b/crates/dizey-web/src/board.rs @@ -0,0 +1,442 @@ +//! The board, from the Main and EmptyBoard artboards. +//! +//! The whole screen is one server call: the columns, the cards and everything +//! hanging off them arrive together, already joined. What a Viewer may not do +//! is refused in the server functions below — the missing button is a courtesy, +//! not the guard. + +use dizey_core::board::{BoardView, Person, TaskCard}; +use leptos::prelude::*; +use serde::{Deserialize, Serialize}; +use time::Date; + +use crate::auth::{Me, Refusal}; + +/// One board screen's worth of state. +/// +/// `today` comes from the server: whether a deadline has passed is not left to +/// whatever the browser's clock says. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct BoardSnapshot { + pub view: BoardView, + pub me: Me, + pub today: Date, +} + +/// The board this browser may see. (The `#[server]` macro names a struct after +/// the function, so the call is `current_board` and the answer is a +/// `BoardSnapshot`.) +#[server] +pub async fn current_board() -> Result, ServerFnError> { + use crate::server::{accounts, require_user}; + use dizey_core::board::load; + use time::OffsetDateTime; + + let user = match require_user().await { + Ok(user) => user, + Err(refusal) => return Ok(Err(refusal)), + }; + let store = accounts().store().clone(); + let Some(view) = load(store.as_ref(), &user.workspace_id) + .await + .map_err(|e| ServerFnError::new(e.to_string()))? + else { + return Ok(Err(Refusal::Unavailable)); + }; + Ok(Ok(BoardSnapshot { + view, + me: Me { + id: user.id, + display_name: user.display_name, + email: user.email, + role: user.role, + }, + today: OffsetDateTime::now_utc().date(), + })) +} + +/// Adds a card to a column. A Viewer is refused here, in the handler. +#[server] +pub async fn create_task( + title: String, + column_id: String, +) -> Result, ServerFnError> { + use crate::server::{accounts, require_writer}; + use dizey_core::store::NewTask; + + let user = match require_writer().await { + Ok(user) => user, + Err(refusal) => return Ok(Some(refusal)), + }; + let title = title.trim().to_string(); + if title.is_empty() { + return Ok(Some(Refusal::EmptyTitle)); + } + + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + let Some(board) = store.board(&user.workspace_id).await.map_err(fail)? else { + return Ok(Some(Refusal::Unavailable)); + }; + // The column id arrives from the browser, so it is checked against this + // workspace's board rather than trusted. + let columns = store.columns(&board.id).await.map_err(fail)?; + if !columns.iter().any(|column| column.id == column_id) { + return Ok(Some(Refusal::Forbidden)); + } + + store + .create_task(NewTask { + board_id: &board.id, + column_id: &column_id, + title: &title, + description: "", + deadline: None, + created_by: &user.id, + }) + .await + .map_err(fail)?; + Ok(None) +} + +/// Which cards the filter row is showing. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Filter { + All, + Mine, + Blocked, +} + +impl Filter { + fn keeps(self, card: &TaskCard, me: &str) -> bool { + match self { + Filter::All => true, + Filter::Mine => card.is_assigned_to(me), + Filter::Blocked => card.is_blocked(), + } + } +} + +#[component] +pub fn Board() -> impl IntoView { + let board = Resource::new(|| (), |_| async move { current_board().await }); + + view! { + } + }> + {move || Suspend::new(async move { + match board.await { + Ok(Ok(snapshot)) => { + view! { } + .into_any() + } + Ok(Err(refusal)) => { + view! { +
+

{refusal.message()}

+
+ } + .into_any() + } + Err(_) => { + view! { +
+

"Something went wrong. Reload the page."

+
+ } + .into_any() + } + } + })} +
+ } +} + +#[component] +fn BoardScreen( + snapshot: BoardSnapshot, + on_change: impl Fn() + Copy + Send + Sync + 'static, +) -> impl IntoView { + let BoardSnapshot { view, me, today } = snapshot; + let filter = RwSignal::new(Filter::All); + // Which column has its composer open, if any. + let composing = 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 overdue = view.overdue_count(today); + let blocked = view.blocked_count(); + let empty = view.is_empty(); + let board_name = view.board.name.clone(); + + let columns = view + .columns + .into_iter() + .map(|column| { + // Both live in stored values so the closures below stay `Copy`: + // a column's cards and its id are read by the count, the list, the + // composer and the empty-column button. + let cards = StoredValue::new(column.cards); + let column_id = StoredValue::new(column.column.id.clone()); + let name = column.column.name.clone(); + let is_done_column = column.column.is_done; + let shown = Memo::new(move |_| { + let filter = filter.get(); + let me = my_id.read_value().clone(); + cards + .read_value() + .iter() + .filter(|card| filter.keeps(card, &me)) + .cloned() + .collect::>() + }); + let open_composer = move |_| composing.set(Some(column_id.read_value().clone())); + let is_composing = + move || composing.get().as_deref() == Some(column_id.read_value().as_str()); + + view! { +
+
+ {name} + {move || shown.get().len()} +
+ {may_write + .then(|| { + view! { + + } + })} +
+
+ + + + + + + + + +
+
+ } + }) + .collect_view(); + + view! { +
+
+ "dizey" + +
+
+ {board_name} +
+ + {me.display_name.clone()} + + {may_write + .then(|| { + view! { + + } + })} +
+ +
+
+ + + +
+
+ "Sort: deadline" +
+ {(overdue > 0) + .then(|| view! { {format!("{overdue} overdue")} })} + {(blocked > 0) + .then(|| view! { {format!("{blocked} blocked")} })} +
+ +
+
{columns}
+ {empty + .then(|| { + view! { +
+
"This board is empty"
+
+ "Create the first task with the New task button." +
+
+ } + })} +
+ } +} + +#[component] +fn FilterTab(filter: RwSignal, this: Filter, label: &'static str) -> impl IntoView { + view! { + + } +} + +#[component] +fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView { + let blocks = card.blocks.len(); + let blocked_by = card.blocked_by.join(", "); + let deadline = card.deadline_label(today); + let overdue = card.is_overdue(today); + let dated = card.deadline.is_some() || card.is_done(); + let comments = card.comment_count; + let assignees = card.assignees.clone(); + + view! { +
+
+ {card.task_key.clone()} + {(blocks > 0) + .then(|| view! { {format!("blocks {blocks}")} })} + {(!blocked_by.is_empty()) + .then(|| { + view! { + {format!("blocked by {blocked_by}")} + } + })} +
+
{card.title.clone()}
+
+ + {deadline} + + {(comments > 0) + .then(|| view! { {format!("{comments} ✎")} })} +
+
+ {assignees + .iter() + .map(|person| view! { }) + .collect_view()} + {assignees + .is_empty() + .then(|| { + view! { + + "?" + + } + })} +
+
+
+ } +} + +#[component] +fn Avatar(person: Person) -> impl IntoView { + let initials = person.initials(); + // Five tones from the mockups' palette, picked from the id so a person + // keeps the same one wherever they appear. + let tone = person + .id + .bytes() + .fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32)) + % 5; + view! { + + {initials} + + } +} + +/// The inline "Add a task" input. It is a real form, so it still works with the +/// wasm bundle blocked. +#[component] +fn Composer( + column_id: StoredValue, + on_done: impl Fn() + Copy + Send + Sync + 'static, + on_cancel: 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_done(); + } + }); + + view! { + + + +
+ + +
+ {move || { + value + .get() + .and_then(|answer| answer.ok().flatten()) + .map(|refusal| view! {

{refusal.message()}

}) + }} +
+ } +} diff --git a/crates/dizey-web/src/lib.rs b/crates/dizey-web/src/lib.rs index da368eb..297e502 100644 --- a/crates/dizey-web/src/lib.rs +++ b/crates/dizey-web/src/lib.rs @@ -1,5 +1,6 @@ pub mod app; pub mod auth; +pub mod board; pub mod pages; #[cfg(feature = "ssr")] pub mod server; diff --git a/crates/dizey-web/src/main.rs b/crates/dizey-web/src/main.rs index 13160d9..6dbb15e 100644 --- a/crates/dizey-web/src/main.rs +++ b/crates/dizey-web/src/main.rs @@ -1,12 +1,9 @@ #[cfg(feature = "ssr")] #[tokio::main] async fn main() { - use axum::Router; use dizey_core::accounts::Accounts; use dizey_core::store::TursoStore; - use dizey_web::app::{App, shell}; use leptos::prelude::*; - use leptos_axum::{LeptosRoutes, generate_route_list}; use std::sync::Arc; // One process per database file: Turso is a single-writer engine and a @@ -21,26 +18,8 @@ async fn main() { let conf = get_configuration(None).expect("failed to read leptos configuration"); let leptos_options = conf.leptos_options; let addr = leptos_options.site_addr; - let routes = generate_route_list(App); - let app = Router::new() - .route("/healthz", axum::routing::get(|| async { "ok" })) - .leptos_routes_with_context( - &leptos_options, - routes, - { - // Provided here *and* to the server-function handler, which - // `leptos_routes_with_context` registers with the same closure. - let accounts = accounts.clone(); - move || provide_context(accounts.clone()) - }, - { - let leptos_options = leptos_options.clone(); - move || shell(leptos_options.clone()) - }, - ) - .fallback(leptos_axum::file_and_error_handler(shell)) - .with_state(leptos_options); + let app = dizey_web::server::router(accounts, leptos_options); let listener = tokio::net::TcpListener::bind(&addr) .await diff --git a/crates/dizey-web/src/pages.rs b/crates/dizey-web/src/pages.rs index ad084f0..74dcb60 100644 --- a/crates/dizey-web/src/pages.rs +++ b/crates/dizey-web/src/pages.rs @@ -7,6 +7,7 @@ use leptos_router::hooks::use_params_map; use crate::auth::{ ClaimWorkspace, Gate, Invited, RedeemLink, Refusal, SignIn, current_gate, invitation, }; +use crate::board::Board; /// The front door. Which screen this is depends on the workspace, and the /// server decides — an empty workspace offers setup, a claimed one offers a @@ -16,29 +17,27 @@ pub fn Landing() -> impl IntoView { let gate = Resource::new(|| (), |_| async move { current_gate().await }); view! { - }> {move || Suspend::new(async move { match gate.await { Ok(Gate::NeedsSetup) => { - view! { }.into_any() + view! { + + + } + .into_any() } Ok(Gate::NeedsSignIn) => { - view! { }.into_any() - } - Ok(Gate::SignedIn(me)) => { view! { -
-

- "Signed in as " {me.display_name} " (" {me.email} ")." -

-

"The board is not wired up yet."

-
+ + } .into_any() } + Ok(Gate::SignedIn(_)) => view! { }.into_any(), Err(_) => { view! { +

"Something went wrong. Reload the page."

@@ -141,7 +140,6 @@ pub fn Join() -> impl IntoView { let who = Resource::new(token, |token| async move { invitation(token).await }); view! { - }> {move || Suspend::new(async move { match who.await { diff --git a/crates/dizey-web/src/server.rs b/crates/dizey-web/src/server.rs index 7120f8c..54c69f4 100644 --- a/crates/dizey-web/src/server.rs +++ b/crates/dizey-web/src/server.rs @@ -146,3 +146,34 @@ impl From for Refusal { } } } + +/// The whole application as an axum `Router`: the server functions, the +/// rendered routes and the static files. +/// +/// It lives here rather than in `main` so a test can drive the real handlers — +/// the guards above are only worth anything if something calls them the way a +/// browser does. +pub fn router(accounts: Accounts, leptos_options: LeptosOptions) -> axum::Router { + use axum::Router; + use leptos_axum::{LeptosRoutes, generate_route_list}; + + let routes = generate_route_list(crate::app::App); + Router::new() + .route("/healthz", axum::routing::get(|| async { "ok" })) + .leptos_routes_with_context( + &leptos_options, + routes, + { + // Provided here *and* to the server-function handler, which + // `leptos_routes_with_context` registers with the same closure. + let accounts = accounts.clone(); + move || provide_context(accounts.clone()) + }, + { + let leptos_options = leptos_options.clone(); + move || crate::app::shell(leptos_options.clone()) + }, + ) + .fallback(leptos_axum::file_and_error_handler(crate::app::shell)) + .with_state(leptos_options) +} diff --git a/crates/dizey-web/tests/http.rs b/crates/dizey-web/tests/http.rs new file mode 100644 index 0000000..944264d --- /dev/null +++ b/crates/dizey-web/tests/http.rs @@ -0,0 +1,297 @@ +//! The app driven the way a browser drives it: real router, real handlers, real +//! session cookie. +//! +//! The point of this binary is the guards. A button the UI does not draw proves +//! nothing — a Viewer who posts to the mutation endpoint anyway must be refused +//! by the handler, and that is what these tests call. +//! +//! New HTTP tests belong in this file rather than a new `tests/*.rs`: one test +//! binary links and runs once. +#![cfg(feature = "ssr")] + +use std::path::PathBuf; +use std::sync::Arc; + +use axum::Router; +use axum::body::Body; +use axum::http::{HeaderValue, Request, StatusCode, header}; +use dizey_core::Role; +use dizey_core::accounts::Accounts; +use dizey_core::store::TursoStore; +use dizey_web::server::SESSION_COOKIE; +use leptos::prelude::LeptosOptions; +use leptos::server_fn::ServerFn; +use tower::ServiceExt; +use uuid::Uuid; + +/// A throwaway workspace: its own database file and its own router. +struct App { + dir: PathBuf, + router: Router, +} + +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 options = LeptosOptions::builder().output_name("dizey").build(); + let router = dizey_web::server::router(Accounts::new(Arc::new(store)), options); + Self { dir, router } + } + + /// Posts a form to a server function, as the browser does, and returns the + /// status, the JSON body and any session cookie the answer set. + async fn post(&self, path: &str, cookie: Option<&str>, form: &[(&str, &str)]) -> Answer { + let body = form + .iter() + .map(|(key, value)| format!("{}={}", encode(key), encode(value))) + .collect::>() + .join("&"); + let mut request = Request::builder() + .method("POST") + .uri(path) + .header(header::ACCEPT, "application/json") + .header(header::CONTENT_TYPE, "application/x-www-form-urlencoded"); + if let Some(cookie) = cookie { + request = request.header( + header::COOKIE, + HeaderValue::from_str(&format!("{SESSION_COOKIE}={cookie}")).unwrap(), + ); + } + let response = self + .router + .clone() + .oneshot(request.body(Body::from(body)).unwrap()) + .await + .unwrap(); + let status = response.status(); + let session = response + .headers() + .get_all(header::SET_COOKIE) + .iter() + .filter_map(|value| value.to_str().ok()) + .find_map(session_from); + let bytes = axum::body::to_bytes(response.into_body(), usize::MAX) + .await + .unwrap(); + Answer { + status, + session, + body: String::from_utf8(bytes.to_vec()).unwrap(), + } + } +} + +impl Drop for App { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.dir); + } +} + +struct Answer { + status: StatusCode, + session: Option, + body: String, +} + +/// The `Set-Cookie` value's session token, if that header carries a live one. +fn session_from(raw: &str) -> Option { + let value = raw.strip_prefix(SESSION_COOKIE)?.strip_prefix('=')?; + let value = value.split(';').next()?.trim(); + (!value.is_empty()).then(|| value.to_string()) +} + +/// Form encoding, enough for the addresses and passphrases these tests send. +fn encode(raw: &str) -> String { + let mut out = String::with_capacity(raw.len()); + for byte in raw.bytes() { + match byte { + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { + out.push(byte as char) + } + b' ' => out.push('+'), + other => out.push_str(&format!("%{other:02X}")), + } + } + out +} + +fn path() -> &'static str { + F::PATH +} + +/// Claims the workspace and returns the admin's session cookie. +async fn admin(app: &App) -> String { + let answer = app + .post( + path::(), + None, + &[ + ("display_name", "Ada Lovelace"), + ("email", "ada@dizey.sh"), + ("password", "correct horse battery staple"), + ], + ) + .await; + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + assert_eq!(answer.body, "null", "claiming was refused"); + answer.session.expect("claiming set no session cookie") +} + +/// Invites someone in the given role and signs them in, returning their cookie. +async fn invited(app: &App, admin: &str, email: &str, name: &str, role: Role) -> String { + let role = match role { + Role::Admin => "admin", + Role::Member => "member", + Role::Viewer => "viewer", + }; + let answer = app + .post( + path::(), + Some(admin), + &[("email", email), ("display_name", name), ("role", role)], + ) + .await; + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + let token = answer + .body + .rsplit_once("/join/") + .and_then(|(_, rest)| rest.split('"').next()) + .expect("no invitation link in {answer.body}") + .to_string(); + + let answer = app + .post( + path::(), + None, + &[ + ("token", &token), + ("password", "lantern gravel spoon meadow"), + ], + ) + .await; + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + assert_eq!(answer.body, "null", "first sign-in was refused"); + answer.session.expect("first sign-in set no session cookie") +} + +/// The id of the board's first column, read the way the board page reads it. +async fn first_column(app: &App, cookie: &str) -> String { + let answer = app + .post(path::(), Some(cookie), &[]) + .await; + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + answer + .body + .split_once("\"columns\":[{\"column\":{\"id\":\"") + .and_then(|(_, rest)| rest.split('"').next()) + .expect("no column in the board") + .to_string() +} + +#[tokio::test] +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 column = first_column(&app, &admin).await; + + let answer = app + .post( + path::(), + Some(&viewer), + &[("title", "Viewer should not get this"), ("column_id", &column)], + ) + .await; + + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + assert_eq!(answer.body, "\"Forbidden\""); + + // And the refusal is not cosmetic: the board is still empty. + let answer = app + .post(path::(), Some(&admin), &[]) + .await; + assert!( + !answer.body.contains("Viewer should not get this"), + "the refused task was written anyway: {}", + answer.body + ); +} + +#[tokio::test] +async fn a_member_may_create_a_task() { + let app = App::open().await; + let admin = admin(&app).await; + let member = invited(&app, &admin, "mo@dizey.sh", "Mo Dubois", Role::Member).await; + let column = first_column(&app, &admin).await; + + let answer = app + .post( + path::(), + Some(&member), + &[("title", "Wire the deadline chip"), ("column_id", &column)], + ) + .await; + assert_eq!(answer.body, "null", "a member was refused: {}", answer.body); + + let answer = app + .post(path::(), Some(&admin), &[]) + .await; + assert!(answer.body.contains("Wire the deadline chip")); + assert!(answer.body.contains("DZ-01"), "no key on the new task"); +} + +#[tokio::test] +async fn a_task_cannot_be_dropped_into_another_workspaces_column() { + let app = App::open().await; + let admin = admin(&app).await; + + let answer = app + .post( + path::(), + Some(&admin), + &[ + ("title", "Wrong column"), + ("column_id", "00000000-0000-0000-0000-000000000000"), + ], + ) + .await; + assert_eq!(answer.body, "\"Forbidden\""); +} + +#[tokio::test] +async fn a_card_needs_a_title() { + let app = App::open().await; + let admin = admin(&app).await; + let column = first_column(&app, &admin).await; + + let answer = app + .post( + path::(), + Some(&admin), + &[("title", " "), ("column_id", &column)], + ) + .await; + assert_eq!(answer.body, "\"EmptyTitle\""); +} + +#[tokio::test] +async fn the_board_is_not_readable_without_a_session() { + let app = App::open().await; + let _admin = admin(&app).await; + + let answer = app + .post(path::(), None, &[]) + .await; + assert_eq!(answer.body, "{\"Err\":\"SignInFirst\"}"); +} diff --git a/style/main.scss b/style/main.scss index f5f4b5a..fd2457d 100644 --- a/style/main.scss +++ b/style/main.scss @@ -260,3 +260,366 @@ a { border-top: 1px solid #f0eee7; padding-top: 12px; } + +// -- the board (Main and EmptyBoard artboards) ------------------------------- + +.spacer { flex-grow: 1; } + +.board-name { + font-size: 14px; + font-weight: 600; +} + +.topbar-who { + font-size: 13px; + color: var(--muted); +} + +.new-task { + display: flex; + align-items: center; + gap: 8px; + height: 36px; + padding: 0 14px; + background: var(--accent); + color: var(--surface); + border: none; + border-radius: var(--radius); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; + + &:hover { background: var(--accent-ink); } +} + +.filterbar { + height: 52px; + background: var(--surface); + border-bottom: 1px solid var(--border); + display: flex; + align-items: center; + gap: 14px; + padding: 0 24px; +} + +.segmented { + display: flex; + align-items: center; + background: #f2f0ea; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + padding: 2px; + gap: 2px; +} + +.segment { + font-family: inherit; + font-size: 13px; + font-weight: 500; + color: var(--muted); + background: transparent; + border: none; + padding: 5px 12px; + border-radius: 4px; + cursor: pointer; +} + +.segment-on { + font-weight: 600; + color: var(--ink); + background: var(--surface); + box-shadow: 0 1px 2px rgba(28, 27, 24, 0.06); +} + +.sort-note { + display: flex; + align-items: center; + height: 32px; + padding: 0 10px; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + font-size: 13px; + font-weight: 500; +} + +.chip { + display: flex; + align-items: center; + height: 32px; + padding: 0 12px; + border-radius: var(--radius); + font-size: 13px; + font-weight: 600; + + &-overdue { + background: #f9ece4; + border: 1px solid #ecd0bf; + color: #a04a24; + } + + &-blocked { + background: #f7f0dd; + border: 1px solid #e6d7ae; + color: #7a5c1e; + } +} + +.board-stage { + position: relative; + min-height: calc(100vh - var(--topbar-height) - 52px); + padding: 20px 24px 24px 24px; +} + +.board-columns { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 16px; + align-items: start; +} + +.column { + background: #f1efe8; + border-radius: 10px; + padding: 12px; + display: flex; + flex-direction: column; + gap: 10px; + min-height: 120px; +} + +.column-head { + display: flex; + align-items: center; + gap: 8px; + padding: 2px 4px; +} + +.column-name { + font-size: 13px; + font-weight: 600; +} + +.column-count { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); +} + +.column-add { + width: 28px; + height: 28px; + border: none; + border-radius: var(--radius); + background: transparent; + color: var(--muted); + font-size: 16px; + line-height: 1; + cursor: pointer; + + &:hover { background: #e7e4dc; } +} + +.column-cards { + display: flex; + flex-direction: column; + gap: 10px; +} + +.column-empty-add { + border: 1px dashed #d5d1c7; + border-radius: 8px; + padding: 14px; + background: transparent; + color: var(--muted-soft); + font-family: inherit; + font-size: 13px; + cursor: pointer; + + &:hover { color: var(--ink); } +} + +.card { + background: var(--surface); + border: 1px solid var(--border); + border-radius: 8px; + padding: 12px; + box-shadow: 0 1px 2px rgba(28, 27, 24, 0.05); +} + +.card-done { + background: #faf9f4; + box-shadow: none; + + .card-title { color: var(--muted); } +} + +.card-keys { + display: flex; + align-items: baseline; + gap: 6px; + font-family: var(--font-mono); + font-size: 10px; +} + +.card-key { color: var(--muted-soft); } + +.card-blocks, +.card-blocked-by { color: #7a5c1e; } + +.card-title { + font-size: 14px; + font-weight: 500; + line-height: 1.4; + margin-top: 4px; +} + +.card-foot { + display: flex; + align-items: center; + gap: 6px; + margin-top: 10px; + flex-wrap: wrap; +} + +.card-deadline { + display: flex; + align-items: center; + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted); + background: #f1efe8; + border-radius: 4px; + padding: 2px 6px; + + &-overdue { + color: #a04a24; + background: #f9ece4; + } + + &-none { + color: var(--muted-soft); + background: transparent; + padding-left: 0; + } +} + +.card-comments { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted); +} + +.avatars { + display: flex; + align-items: center; +} + +.avatar { + width: 22px; + height: 22px; + border-radius: 50%; + border: 2px solid var(--surface); + color: var(--surface); + font-family: var(--font-mono); + font-size: 9px; + display: flex; + align-items: center; + justify-content: center; + + & + & { margin-left: -7px; } + + &-none { + border: 1px dashed #c9c5ba; + color: var(--muted-soft); + background: transparent; + font-size: 12px; + } + + &-tone-0 { background: #46557b; } + &-tone-1 { background: #7b6846; } + &-tone-2 { background: #5c7b46; } + &-tone-3 { background: #7b4655; } + &-tone-4 { background: #46707b; } +} + +.board-empty { + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); + display: flex; + flex-direction: column; + align-items: center; + gap: 12px; + background: var(--surface); + border: 1px solid var(--border); + border-radius: 12px; + padding: 28px 40px; + box-shadow: 0 4px 16px rgba(28, 27, 24, 0.08); + + &-title { + font-size: 16px; + font-weight: 600; + } + + &-sub { + font-size: 13px; + color: var(--muted); + text-align: center; + line-height: 1.5; + } +} + +.composer { + background: var(--surface); + border: 1px solid var(--border-strong); + border-radius: 8px; + padding: 10px; + display: flex; + flex-direction: column; + gap: 8px; +} + +.composer-input { + width: 100%; + height: 34px; + padding: 0 10px; + background: #faf9f6; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + font-family: inherit; + font-size: 14px; + color: var(--ink); +} + +.composer-row { + display: flex; + align-items: center; + gap: 8px; +} + +.composer-add { + height: 30px; + padding: 0 12px; + background: var(--accent); + color: var(--surface); + border: none; + border-radius: var(--radius); + font-family: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; +} + +.composer-cancel { + height: 30px; + padding: 0 10px; + background: transparent; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + font-family: inherit; + font-size: 13px; + color: var(--muted); + cursor: pointer; +}