The board screen, and the guards that stand behind it
Browse files at this commit40165b43d7878ddf419f1f1220906aca2a15df0aParent: 65b6f65- feat
- the board screen, and the guards that stand behind it
10 changed files +1160 -34
- Cargo.lock +1 -0
- crates/dizey-web/Cargo.toml +7 -0
- crates/dizey-web/src/auth.rs +7 -0
- crates/dizey-web/src/board.rs +442 -0
- crates/dizey-web/src/lib.rs +1 -0
- crates/dizey-web/src/main.rs +1 -22
- crates/dizey-web/src/pages.rs +10 -12
- crates/dizey-web/src/server.rs +31 -0
- crates/dizey-web/tests/http.rs +297 -0
- style/main.scss +363 -0
Cargo.lockmodified+1 -0
| @@ -969,6 +969,7 @@ dependencies = [ | |||
| 969 | "tower", | 969 | "tower", |
| 970 | "tower-http 0.7.0", | 970 | "tower-http 0.7.0", |
| 971 | "turso", | 971 | "turso", |
| 972 | + "uuid", | ||
| 972 | "wasm-bindgen", | 973 | "wasm-bindgen", |
| 973 | ] | 974 | ] |
| 974 | 975 | ||
crates/dizey-web/Cargo.tomlmodified+7 -0
| @@ -47,3 +47,10 @@ ssr = [ | |||
| 47 | "dizey-core/server", | 47 | "dizey-core/server", |
| 48 | "dep:turso", | 48 | "dep:turso", |
| 49 | ] | 49 | ] |
| 50 | + | ||
| 51 | +# The HTTP test drives the real router, so it needs the server side of the app. | ||
| 52 | +# Run it with `cargo test -p dizey-web --features ssr`. | ||
| 53 | +[dev-dependencies] | ||
| 54 | +tokio = { workspace = true } | ||
| 55 | +tower = { version = "0.5.2", features = ["util"] } | ||
| 56 | +uuid = { workspace = true } | ||
crates/dizey-web/src/auth.rsmodified+7 -0
| @@ -24,6 +24,8 @@ pub enum Refusal { | |||
| 24 | AddressTaken, | 24 | AddressTaken, |
| 25 | /// The link is spent, expired, or was never real. | 25 | /// The link is spent, expired, or was never real. |
| 26 | LinkNotUsable, | 26 | LinkNotUsable, |
| 27 | + /// A card with no title is not a card. | ||
| 28 | + EmptyTitle, | ||
| 27 | Unavailable, | 29 | Unavailable, |
| 28 | } | 30 | } |
| 29 | 31 | ||
| @@ -43,6 +45,7 @@ impl Refusal { | |||
| 43 | "This link no longer works. Ask the admin to send another." | 45 | "This link no longer works. Ask the admin to send another." |
| 44 | .to_string() | 46 | .to_string() |
| 45 | } | 47 | } |
| 48 | + Refusal::EmptyTitle => "Give the task a title.".to_string(), | ||
| 46 | Refusal::Unavailable => "Something went wrong. Try again.".to_string(), | 49 | Refusal::Unavailable => "Something went wrong. Try again.".to_string(), |
| 47 | } | 50 | } |
| 48 | } | 51 | } |
| @@ -51,6 +54,9 @@ impl Refusal { | |||
| 51 | /// The person the current browser is signed in as. | 54 | /// The person the current browser is signed in as. |
| 52 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | 55 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| 53 | pub struct Me { | 56 | pub struct Me { |
| 57 | + /// The account id, so the board can tell "Mine" from everyone else's | ||
| 58 | + /// without a second call. | ||
| 59 | + pub id: String, | ||
| 54 | pub display_name: String, | 60 | pub display_name: String, |
| 55 | pub email: String, | 61 | pub email: String, |
| 56 | pub role: dizey_core::Role, | 62 | pub role: dizey_core::Role, |
| @@ -85,6 +91,7 @@ pub async fn current_gate() -> Result<Gate, ServerFnError> { | |||
| 85 | 91 | ||
| 86 | if let Some(user) = current_user().await { | 92 | if let Some(user) = current_user().await { |
| 87 | return Ok(Gate::SignedIn(Me { | 93 | return Ok(Gate::SignedIn(Me { |
| 94 | + id: user.id, | ||
| 88 | display_name: user.display_name, | 95 | display_name: user.display_name, |
| 89 | email: user.email, | 96 | email: user.email, |
| 90 | role: user.role, | 97 | role: user.role, |
crates/dizey-web/src/board.rsadded+442 -0
| @@ -0,0 +1,442 @@ | |||
| 1 | +//! The board, from the Main and EmptyBoard artboards. | ||
| 2 | +//! | ||
| 3 | +//! The whole screen is one server call: the columns, the cards and everything | ||
| 4 | +//! hanging off them arrive together, already joined. What a Viewer may not do | ||
| 5 | +//! is refused in the server functions below — the missing button is a courtesy, | ||
| 6 | +//! not the guard. | ||
| 7 | + | ||
| 8 | +use dizey_core::board::{BoardView, Person, TaskCard}; | ||
| 9 | +use leptos::prelude::*; | ||
| 10 | +use serde::{Deserialize, Serialize}; | ||
| 11 | +use time::Date; | ||
| 12 | + | ||
| 13 | +use crate::auth::{Me, Refusal}; | ||
| 14 | + | ||
| 15 | +/// One board screen's worth of state. | ||
| 16 | +/// | ||
| 17 | +/// `today` comes from the server: whether a deadline has passed is not left to | ||
| 18 | +/// whatever the browser's clock says. | ||
| 19 | +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
| 20 | +pub struct BoardSnapshot { | ||
| 21 | + pub view: BoardView, | ||
| 22 | + pub me: Me, | ||
| 23 | + pub today: Date, | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +/// The board this browser may see. (The `#[server]` macro names a struct after | ||
| 27 | +/// the function, so the call is `current_board` and the answer is a | ||
| 28 | +/// `BoardSnapshot`.) | ||
| 29 | +#[server] | ||
| 30 | +pub async fn current_board() -> Result<Result<BoardSnapshot, Refusal>, ServerFnError> { | ||
| 31 | + use crate::server::{accounts, require_user}; | ||
| 32 | + use dizey_core::board::load; | ||
| 33 | + use time::OffsetDateTime; | ||
| 34 | + | ||
| 35 | + let user = match require_user().await { | ||
| 36 | + Ok(user) => user, | ||
| 37 | + Err(refusal) => return Ok(Err(refusal)), | ||
| 38 | + }; | ||
| 39 | + let store = accounts().store().clone(); | ||
| 40 | + let Some(view) = load(store.as_ref(), &user.workspace_id) | ||
| 41 | + .await | ||
| 42 | + .map_err(|e| ServerFnError::new(e.to_string()))? | ||
| 43 | + else { | ||
| 44 | + return Ok(Err(Refusal::Unavailable)); | ||
| 45 | + }; | ||
| 46 | + Ok(Ok(BoardSnapshot { | ||
| 47 | + view, | ||
| 48 | + me: Me { | ||
| 49 | + id: user.id, | ||
| 50 | + display_name: user.display_name, | ||
| 51 | + email: user.email, | ||
| 52 | + role: user.role, | ||
| 53 | + }, | ||
| 54 | + today: OffsetDateTime::now_utc().date(), | ||
| 55 | + })) | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +/// Adds a card to a column. A Viewer is refused here, in the handler. | ||
| 59 | +#[server] | ||
| 60 | +pub async fn create_task( | ||
| 61 | + title: String, | ||
| 62 | + column_id: String, | ||
| 63 | +) -> Result<Option<Refusal>, ServerFnError> { | ||
| 64 | + use crate::server::{accounts, require_writer}; | ||
| 65 | + use dizey_core::store::NewTask; | ||
| 66 | + | ||
| 67 | + let user = match require_writer().await { | ||
| 68 | + Ok(user) => user, | ||
| 69 | + Err(refusal) => return Ok(Some(refusal)), | ||
| 70 | + }; | ||
| 71 | + let title = title.trim().to_string(); | ||
| 72 | + if title.is_empty() { | ||
| 73 | + return Ok(Some(Refusal::EmptyTitle)); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + let store = accounts().store().clone(); | ||
| 77 | + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); | ||
| 78 | + let Some(board) = store.board(&user.workspace_id).await.map_err(fail)? else { | ||
| 79 | + return Ok(Some(Refusal::Unavailable)); | ||
| 80 | + }; | ||
| 81 | + // The column id arrives from the browser, so it is checked against this | ||
| 82 | + // workspace's board rather than trusted. | ||
| 83 | + let columns = store.columns(&board.id).await.map_err(fail)?; | ||
| 84 | + if !columns.iter().any(|column| column.id == column_id) { | ||
| 85 | + return Ok(Some(Refusal::Forbidden)); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + store | ||
| 89 | + .create_task(NewTask { | ||
| 90 | + board_id: &board.id, | ||
| 91 | + column_id: &column_id, | ||
| 92 | + title: &title, | ||
| 93 | + description: "", | ||
| 94 | + deadline: None, | ||
| 95 | + created_by: &user.id, | ||
| 96 | + }) | ||
| 97 | + .await | ||
| 98 | + .map_err(fail)?; | ||
| 99 | + Ok(None) | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +/// Which cards the filter row is showing. | ||
| 103 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| 104 | +enum Filter { | ||
| 105 | + All, | ||
| 106 | + Mine, | ||
| 107 | + Blocked, | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +impl Filter { | ||
| 111 | + fn keeps(self, card: &TaskCard, me: &str) -> bool { | ||
| 112 | + match self { | ||
| 113 | + Filter::All => true, | ||
| 114 | + Filter::Mine => card.is_assigned_to(me), | ||
| 115 | + Filter::Blocked => card.is_blocked(), | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +#[component] | ||
| 121 | +pub fn Board() -> impl IntoView { | ||
| 122 | + let board = Resource::new(|| (), |_| async move { current_board().await }); | ||
| 123 | + | ||
| 124 | + view! { | ||
| 125 | + <Suspense fallback=|| { | ||
| 126 | + view! { <main class="board-stage"></main> } | ||
| 127 | + }> | ||
| 128 | + {move || Suspend::new(async move { | ||
| 129 | + match board.await { | ||
| 130 | + Ok(Ok(snapshot)) => { | ||
| 131 | + view! { <BoardScreen snapshot=snapshot on_change=move || board.refetch()/> } | ||
| 132 | + .into_any() | ||
| 133 | + } | ||
| 134 | + Ok(Err(refusal)) => { | ||
| 135 | + view! { | ||
| 136 | + <main class="scaffold-note"> | ||
| 137 | + <p>{refusal.message()}</p> | ||
| 138 | + </main> | ||
| 139 | + } | ||
| 140 | + .into_any() | ||
| 141 | + } | ||
| 142 | + Err(_) => { | ||
| 143 | + view! { | ||
| 144 | + <main class="scaffold-note"> | ||
| 145 | + <p>"Something went wrong. Reload the page."</p> | ||
| 146 | + </main> | ||
| 147 | + } | ||
| 148 | + .into_any() | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + })} | ||
| 152 | + </Suspense> | ||
| 153 | + } | ||
| 154 | +} | ||
| 155 | + | ||
| 156 | +#[component] | ||
| 157 | +fn BoardScreen( | ||
| 158 | + snapshot: BoardSnapshot, | ||
| 159 | + on_change: impl Fn() + Copy + Send + Sync + 'static, | ||
| 160 | +) -> impl IntoView { | ||
| 161 | + let BoardSnapshot { view, me, today } = snapshot; | ||
| 162 | + let filter = RwSignal::new(Filter::All); | ||
| 163 | + // Which column has its composer open, if any. | ||
| 164 | + let composing = RwSignal::new(None::<String>); | ||
| 165 | + let may_write = me.role.can_write_tasks(); | ||
| 166 | + let my_id = StoredValue::new(me.id.clone()); | ||
| 167 | + | ||
| 168 | + // The New task button opens the composer in the first column, which is | ||
| 169 | + // where a new card belongs when nobody has said otherwise. | ||
| 170 | + let first_column_id = StoredValue::new( | ||
| 171 | + view.columns | ||
| 172 | + .first() | ||
| 173 | + .map(|column| column.column.id.clone()), | ||
| 174 | + ); | ||
| 175 | + | ||
| 176 | + let overdue = view.overdue_count(today); | ||
| 177 | + let blocked = view.blocked_count(); | ||
| 178 | + let empty = view.is_empty(); | ||
| 179 | + let board_name = view.board.name.clone(); | ||
| 180 | + | ||
| 181 | + let columns = view | ||
| 182 | + .columns | ||
| 183 | + .into_iter() | ||
| 184 | + .map(|column| { | ||
| 185 | + // Both live in stored values so the closures below stay `Copy`: | ||
| 186 | + // a column's cards and its id are read by the count, the list, the | ||
| 187 | + // composer and the empty-column button. | ||
| 188 | + let cards = StoredValue::new(column.cards); | ||
| 189 | + let column_id = StoredValue::new(column.column.id.clone()); | ||
| 190 | + let name = column.column.name.clone(); | ||
| 191 | + let is_done_column = column.column.is_done; | ||
| 192 | + let shown = Memo::new(move |_| { | ||
| 193 | + let filter = filter.get(); | ||
| 194 | + let me = my_id.read_value().clone(); | ||
| 195 | + cards | ||
| 196 | + .read_value() | ||
| 197 | + .iter() | ||
| 198 | + .filter(|card| filter.keeps(card, &me)) | ||
| 199 | + .cloned() | ||
| 200 | + .collect::<Vec<TaskCard>>() | ||
| 201 | + }); | ||
| 202 | + let open_composer = move |_| composing.set(Some(column_id.read_value().clone())); | ||
| 203 | + let is_composing = | ||
| 204 | + move || composing.get().as_deref() == Some(column_id.read_value().as_str()); | ||
| 205 | + | ||
| 206 | + view! { | ||
| 207 | + <section class="column"> | ||
| 208 | + <header class="column-head"> | ||
| 209 | + <span class="column-name">{name}</span> | ||
| 210 | + <span class="column-count">{move || shown.get().len()}</span> | ||
| 211 | + <div class="spacer"></div> | ||
| 212 | + {may_write | ||
| 213 | + .then(|| { | ||
| 214 | + view! { | ||
| 215 | + <button | ||
| 216 | + class="column-add" | ||
| 217 | + title="Add a task" | ||
| 218 | + on:click=open_composer | ||
| 219 | + > | ||
| 220 | + "+" | ||
| 221 | + </button> | ||
| 222 | + } | ||
| 223 | + })} | ||
| 224 | + </header> | ||
| 225 | + <div class="column-cards"> | ||
| 226 | + <For each=move || shown.get() key=|card: &TaskCard| card.id.clone() let:card> | ||
| 227 | + <Card card=card today=today done_column=is_done_column/> | ||
| 228 | + </For> | ||
| 229 | + <Show when=move || may_write && is_composing()> | ||
| 230 | + <Composer | ||
| 231 | + column_id=column_id | ||
| 232 | + on_done=move || { | ||
| 233 | + composing.set(None); | ||
| 234 | + on_change(); | ||
| 235 | + } | ||
| 236 | + on_cancel=move || composing.set(None) | ||
| 237 | + /> | ||
| 238 | + </Show> | ||
| 239 | + <Show when=move || { | ||
| 240 | + may_write && !is_composing() && shown.get().is_empty() | ||
| 241 | + }> | ||
| 242 | + <button class="column-empty-add" on:click=open_composer> | ||
| 243 | + "+ Add a task" | ||
| 244 | + </button> | ||
| 245 | + </Show> | ||
| 246 | + </div> | ||
| 247 | + </section> | ||
| 248 | + } | ||
| 249 | + }) | ||
| 250 | + .collect_view(); | ||
| 251 | + | ||
| 252 | + view! { | ||
| 253 | + <header class="topbar"> | ||
| 254 | + <div class="wordmark"> | ||
| 255 | + <span class="wordmark-text">"dizey"</span> | ||
| 256 | + <span class="wordmark-dot"></span> | ||
| 257 | + </div> | ||
| 258 | + <div class="topbar-divider"></div> | ||
| 259 | + <span class="board-name">{board_name}</span> | ||
| 260 | + <div class="spacer"></div> | ||
| 261 | + <span class="topbar-who" title=me.email.clone()> | ||
| 262 | + {me.display_name.clone()} | ||
| 263 | + </span> | ||
| 264 | + {may_write | ||
| 265 | + .then(|| { | ||
| 266 | + view! { | ||
| 267 | + <button | ||
| 268 | + class="new-task" | ||
| 269 | + on:click=move |_| composing.set(first_column_id.get_value()) | ||
| 270 | + > | ||
| 271 | + "New task" | ||
| 272 | + </button> | ||
| 273 | + } | ||
| 274 | + })} | ||
| 275 | + </header> | ||
| 276 | + | ||
| 277 | + <div class="filterbar"> | ||
| 278 | + <div class="segmented"> | ||
| 279 | + <FilterTab filter=filter this=Filter::All label="All tasks"/> | ||
| 280 | + <FilterTab filter=filter this=Filter::Mine label="Mine"/> | ||
| 281 | + <FilterTab filter=filter this=Filter::Blocked label="Blocked"/> | ||
| 282 | + </div> | ||
| 283 | + <div class="topbar-divider"></div> | ||
| 284 | + <span class="sort-note">"Sort: deadline"</span> | ||
| 285 | + <div class="spacer"></div> | ||
| 286 | + {(overdue > 0) | ||
| 287 | + .then(|| view! { <span class="chip chip-overdue">{format!("{overdue} overdue")}</span> })} | ||
| 288 | + {(blocked > 0) | ||
| 289 | + .then(|| view! { <span class="chip chip-blocked">{format!("{blocked} blocked")}</span> })} | ||
| 290 | + </div> | ||
| 291 | + | ||
| 292 | + <main class="board-stage"> | ||
| 293 | + <div class="board-columns">{columns}</div> | ||
| 294 | + {empty | ||
| 295 | + .then(|| { | ||
| 296 | + view! { | ||
| 297 | + <div class="board-empty"> | ||
| 298 | + <div class="board-empty-title">"This board is empty"</div> | ||
| 299 | + <div class="board-empty-sub"> | ||
| 300 | + "Create the first task with the New task button." | ||
| 301 | + </div> | ||
| 302 | + </div> | ||
| 303 | + } | ||
| 304 | + })} | ||
| 305 | + </main> | ||
| 306 | + } | ||
| 307 | +} | ||
| 308 | + | ||
| 309 | +#[component] | ||
| 310 | +fn FilterTab(filter: RwSignal<Filter>, this: Filter, label: &'static str) -> impl IntoView { | ||
| 311 | + view! { | ||
| 312 | + <button | ||
| 313 | + class="segment" | ||
| 314 | + class:segment-on=move || filter.get() == this | ||
| 315 | + on:click=move |_| filter.set(this) | ||
| 316 | + > | ||
| 317 | + {label} | ||
| 318 | + </button> | ||
| 319 | + } | ||
| 320 | +} | ||
| 321 | + | ||
| 322 | +#[component] | ||
| 323 | +fn Card(card: TaskCard, today: Date, done_column: bool) -> impl IntoView { | ||
| 324 | + let blocks = card.blocks.len(); | ||
| 325 | + let blocked_by = card.blocked_by.join(", "); | ||
| 326 | + let deadline = card.deadline_label(today); | ||
| 327 | + let overdue = card.is_overdue(today); | ||
| 328 | + let dated = card.deadline.is_some() || card.is_done(); | ||
| 329 | + let comments = card.comment_count; | ||
| 330 | + let assignees = card.assignees.clone(); | ||
| 331 | + | ||
| 332 | + view! { | ||
| 333 | + <article class="card" class:card-done=done_column> | ||
| 334 | + <div class="card-keys"> | ||
| 335 | + <span class="card-key">{card.task_key.clone()}</span> | ||
| 336 | + {(blocks > 0) | ||
| 337 | + .then(|| view! { <span class="card-blocks">{format!("blocks {blocks}")}</span> })} | ||
| 338 | + {(!blocked_by.is_empty()) | ||
| 339 | + .then(|| { | ||
| 340 | + view! { | ||
| 341 | + <span class="card-blocked-by">{format!("blocked by {blocked_by}")}</span> | ||
| 342 | + } | ||
| 343 | + })} | ||
| 344 | + </div> | ||
| 345 | + <div class="card-title">{card.title.clone()}</div> | ||
| 346 | + <div class="card-foot"> | ||
| 347 | + <span | ||
| 348 | + class="card-deadline" | ||
| 349 | + class:card-deadline-overdue=overdue | ||
| 350 | + class:card-deadline-none=!dated | ||
| 351 | + > | ||
| 352 | + {deadline} | ||
| 353 | + </span> | ||
| 354 | + {(comments > 0) | ||
| 355 | + .then(|| view! { <span class="card-comments">{format!("{comments} ✎")}</span> })} | ||
| 356 | + <div class="spacer"></div> | ||
| 357 | + <div class="avatars"> | ||
| 358 | + {assignees | ||
| 359 | + .iter() | ||
| 360 | + .map(|person| view! { <Avatar person=person.clone()/> }) | ||
| 361 | + .collect_view()} | ||
| 362 | + {assignees | ||
| 363 | + .is_empty() | ||
| 364 | + .then(|| { | ||
| 365 | + view! { | ||
| 366 | + <span class="avatar avatar-none" title="Nobody is on this yet"> | ||
| 367 | + "?" | ||
| 368 | + </span> | ||
| 369 | + } | ||
| 370 | + })} | ||
| 371 | + </div> | ||
| 372 | + </div> | ||
| 373 | + </article> | ||
| 374 | + } | ||
| 375 | +} | ||
| 376 | + | ||
| 377 | +#[component] | ||
| 378 | +fn Avatar(person: Person) -> impl IntoView { | ||
| 379 | + let initials = person.initials(); | ||
| 380 | + // Five tones from the mockups' palette, picked from the id so a person | ||
| 381 | + // keeps the same one wherever they appear. | ||
| 382 | + let tone = person | ||
| 383 | + .id | ||
| 384 | + .bytes() | ||
| 385 | + .fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32)) | ||
| 386 | + % 5; | ||
| 387 | + view! { | ||
| 388 | + <span class=format!("avatar avatar-tone-{tone}") title=person.display_name.clone()> | ||
| 389 | + {initials} | ||
| 390 | + </span> | ||
| 391 | + } | ||
| 392 | +} | ||
| 393 | + | ||
| 394 | +/// The inline "Add a task" input. It is a real form, so it still works with the | ||
| 395 | +/// wasm bundle blocked. | ||
| 396 | +#[component] | ||
| 397 | +fn Composer( | ||
| 398 | + column_id: StoredValue<String>, | ||
| 399 | + on_done: impl Fn() + Copy + Send + Sync + 'static, | ||
| 400 | + on_cancel: impl Fn() + Copy + Send + Sync + 'static, | ||
| 401 | +) -> impl IntoView { | ||
| 402 | + let action = ServerAction::<CreateTask>::new(); | ||
| 403 | + let value = action.value(); | ||
| 404 | + Effect::new(move |_| { | ||
| 405 | + if matches!(value.get(), Some(Ok(None))) { | ||
| 406 | + on_done(); | ||
| 407 | + } | ||
| 408 | + }); | ||
| 409 | + | ||
| 410 | + view! { | ||
| 411 | + <ActionForm action=action attr:class="composer"> | ||
| 412 | + <input type="hidden" name="column_id" value=move || column_id.get_value()/> | ||
| 413 | + <input | ||
| 414 | + class="composer-input" | ||
| 415 | + type="text" | ||
| 416 | + name="title" | ||
| 417 | + placeholder="What needs doing?" | ||
| 418 | + autofocus | ||
| 419 | + required | ||
| 420 | + on:keydown=move |event| { | ||
| 421 | + if event.key() == "Escape" { | ||
| 422 | + on_cancel(); | ||
| 423 | + } | ||
| 424 | + } | ||
| 425 | + /> | ||
| 426 | + <div class="composer-row"> | ||
| 427 | + <button class="composer-add" type="submit" disabled=move || action.pending().get()> | ||
| 428 | + "Add" | ||
| 429 | + </button> | ||
| 430 | + <button class="composer-cancel" type="button" on:click=move |_| on_cancel()> | ||
| 431 | + "Cancel" | ||
| 432 | + </button> | ||
| 433 | + </div> | ||
| 434 | + {move || { | ||
| 435 | + value | ||
| 436 | + .get() | ||
| 437 | + .and_then(|answer| answer.ok().flatten()) | ||
| 438 | + .map(|refusal| view! { <p class="auth-problem">{refusal.message()}</p> }) | ||
| 439 | + }} | ||
| 440 | + </ActionForm> | ||
| 441 | + } | ||
| 442 | +} | ||
crates/dizey-web/src/lib.rsmodified+1 -0
| @@ -1,5 +1,6 @@ | |||
| 1 | pub mod app; | 1 | pub mod app; |
| 2 | pub mod auth; | 2 | pub mod auth; |
| 3 | +pub mod board; | ||
| 3 | pub mod pages; | 4 | pub mod pages; |
| 4 | #[cfg(feature = "ssr")] | 5 | #[cfg(feature = "ssr")] |
| 5 | pub mod server; | 6 | pub mod server; |
crates/dizey-web/src/main.rsmodified+1 -22
| @@ -1,12 +1,9 @@ | |||
| 1 | #[cfg(feature = "ssr")] | 1 | #[cfg(feature = "ssr")] |
| 2 | #[tokio::main] | 2 | #[tokio::main] |
| 3 | async fn main() { | 3 | async fn main() { |
| 4 | - use axum::Router; | ||
| 5 | use dizey_core::accounts::Accounts; | 4 | use dizey_core::accounts::Accounts; |
| 6 | use dizey_core::store::TursoStore; | 5 | use dizey_core::store::TursoStore; |
| 7 | - use dizey_web::app::{App, shell}; | ||
| 8 | use leptos::prelude::*; | 6 | use leptos::prelude::*; |
| 9 | - use leptos_axum::{LeptosRoutes, generate_route_list}; | ||
| 10 | use std::sync::Arc; | 7 | use std::sync::Arc; |
| 11 | 8 | ||
| 12 | // One process per database file: Turso is a single-writer engine and a | 9 | // One process per database file: Turso is a single-writer engine and a |
| @@ -21,26 +18,8 @@ async fn main() { | |||
| 21 | let conf = get_configuration(None).expect("failed to read leptos configuration"); | 18 | let conf = get_configuration(None).expect("failed to read leptos configuration"); |
| 22 | let leptos_options = conf.leptos_options; | 19 | let leptos_options = conf.leptos_options; |
| 23 | let addr = leptos_options.site_addr; | 20 | let addr = leptos_options.site_addr; |
| 24 | - let routes = generate_route_list(App); | ||
| 25 | 21 | ||
| 26 | - let app = Router::new() | 22 | + let app = dizey_web::server::router(accounts, leptos_options); |
| 27 | - .route("/healthz", axum::routing::get(|| async { "ok" })) | ||
| 28 | - .leptos_routes_with_context( | ||
| 29 | - &leptos_options, | ||
| 30 | - routes, | ||
| 31 | - { | ||
| 32 | - // Provided here *and* to the server-function handler, which | ||
| 33 | - // `leptos_routes_with_context` registers with the same closure. | ||
| 34 | - let accounts = accounts.clone(); | ||
| 35 | - move || provide_context(accounts.clone()) | ||
| 36 | - }, | ||
| 37 | - { | ||
| 38 | - let leptos_options = leptos_options.clone(); | ||
| 39 | - move || shell(leptos_options.clone()) | ||
| 40 | - }, | ||
| 41 | - ) | ||
| 42 | - .fallback(leptos_axum::file_and_error_handler(shell)) | ||
| 43 | - .with_state(leptos_options); | ||
| 44 | 23 | ||
| 45 | let listener = tokio::net::TcpListener::bind(&addr) | 24 | let listener = tokio::net::TcpListener::bind(&addr) |
| 46 | .await | 25 | .await |
crates/dizey-web/src/pages.rsmodified+10 -12
| @@ -7,6 +7,7 @@ use leptos_router::hooks::use_params_map; | |||
| 7 | use crate::auth::{ | 7 | use crate::auth::{ |
| 8 | ClaimWorkspace, Gate, Invited, RedeemLink, Refusal, SignIn, current_gate, invitation, | 8 | ClaimWorkspace, Gate, Invited, RedeemLink, Refusal, SignIn, current_gate, invitation, |
| 9 | }; | 9 | }; |
| 10 | +use crate::board::Board; | ||
| 10 | 11 | ||
| 11 | /// The front door. Which screen this is depends on the workspace, and the | 12 | /// The front door. Which screen this is depends on the workspace, and the |
| 12 | /// server decides — an empty workspace offers setup, a claimed one offers a | 13 | /// server decides — an empty workspace offers setup, a claimed one offers a |
| @@ -16,29 +17,27 @@ pub fn Landing() -> impl IntoView { | |||
| 16 | let gate = Resource::new(|| (), |_| async move { current_gate().await }); | 17 | let gate = Resource::new(|| (), |_| async move { current_gate().await }); |
| 17 | 18 | ||
| 18 | view! { | 19 | view! { |
| 19 | - <Topbar/> | ||
| 20 | <Suspense fallback=|| view! { <main class="auth-stage"></main> }> | 20 | <Suspense fallback=|| view! { <main class="auth-stage"></main> }> |
| 21 | {move || Suspend::new(async move { | 21 | {move || Suspend::new(async move { |
| 22 | match gate.await { | 22 | match gate.await { |
| 23 | Ok(Gate::NeedsSetup) => { | 23 | Ok(Gate::NeedsSetup) => { |
| 24 | - view! { <SetupCard on_done=move || gate.refetch()/> }.into_any() | 24 | + view! { |
| 25 | + <Topbar/> | ||
| 26 | + <SetupCard on_done=move || gate.refetch()/> | ||
| 27 | + } | ||
| 28 | + .into_any() | ||
| 25 | } | 29 | } |
| 26 | Ok(Gate::NeedsSignIn) => { | 30 | Ok(Gate::NeedsSignIn) => { |
| 27 | - view! { <SignInCard on_done=move || gate.refetch()/> }.into_any() | ||
| 28 | - } | ||
| 29 | - Ok(Gate::SignedIn(me)) => { | ||
| 30 | view! { | 31 | view! { |
| 31 | - <main class="scaffold-note"> | 32 | + <Topbar/> |
| 32 | - <p> | 33 | + <SignInCard on_done=move || gate.refetch()/> |
| 33 | - "Signed in as " {me.display_name} " (" {me.email} ")." | ||
| 34 | - </p> | ||
| 35 | - <p>"The board is not wired up yet."</p> | ||
| 36 | - </main> | ||
| 37 | } | 34 | } |
| 38 | .into_any() | 35 | .into_any() |
| 39 | } | 36 | } |
| 37 | + Ok(Gate::SignedIn(_)) => view! { <Board/> }.into_any(), | ||
| 40 | Err(_) => { | 38 | Err(_) => { |
| 41 | view! { | 39 | view! { |
| 40 | + <Topbar/> | ||
| 42 | <main class="scaffold-note"> | 41 | <main class="scaffold-note"> |
| 43 | <p>"Something went wrong. Reload the page."</p> | 42 | <p>"Something went wrong. Reload the page."</p> |
| 44 | </main> | 43 | </main> |
| @@ -141,7 +140,6 @@ pub fn Join() -> impl IntoView { | |||
| 141 | let who = Resource::new(token, |token| async move { invitation(token).await }); | 140 | let who = Resource::new(token, |token| async move { invitation(token).await }); |
| 142 | 141 | ||
| 143 | view! { | 142 | view! { |
| 144 | - <Topbar/> | ||
| 145 | <Suspense fallback=|| view! { <main class="auth-stage"></main> }> | 143 | <Suspense fallback=|| view! { <main class="auth-stage"></main> }> |
| 146 | {move || Suspend::new(async move { | 144 | {move || Suspend::new(async move { |
| 147 | match who.await { | 145 | match who.await { |
crates/dizey-web/src/server.rsmodified+31 -0
| @@ -146,3 +146,34 @@ impl From<AccountError> for Refusal { | |||
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| 149 | + | ||
| 150 | +/// The whole application as an axum `Router`: the server functions, the | ||
| 151 | +/// rendered routes and the static files. | ||
| 152 | +/// | ||
| 153 | +/// It lives here rather than in `main` so a test can drive the real handlers — | ||
| 154 | +/// the guards above are only worth anything if something calls them the way a | ||
| 155 | +/// browser does. | ||
| 156 | +pub fn router(accounts: Accounts, leptos_options: LeptosOptions) -> axum::Router { | ||
| 157 | + use axum::Router; | ||
| 158 | + use leptos_axum::{LeptosRoutes, generate_route_list}; | ||
| 159 | + | ||
| 160 | + let routes = generate_route_list(crate::app::App); | ||
| 161 | + Router::new() | ||
| 162 | + .route("/healthz", axum::routing::get(|| async { "ok" })) | ||
| 163 | + .leptos_routes_with_context( | ||
| 164 | + &leptos_options, | ||
| 165 | + routes, | ||
| 166 | + { | ||
| 167 | + // Provided here *and* to the server-function handler, which | ||
| 168 | + // `leptos_routes_with_context` registers with the same closure. | ||
| 169 | + let accounts = accounts.clone(); | ||
| 170 | + move || provide_context(accounts.clone()) | ||
| 171 | + }, | ||
| 172 | + { | ||
| 173 | + let leptos_options = leptos_options.clone(); | ||
| 174 | + move || crate::app::shell(leptos_options.clone()) | ||
| 175 | + }, | ||
| 176 | + ) | ||
| 177 | + .fallback(leptos_axum::file_and_error_handler(crate::app::shell)) | ||
| 178 | + .with_state(leptos_options) | ||
| 179 | +} | ||
crates/dizey-web/tests/http.rsadded+297 -0
| @@ -0,0 +1,297 @@ | |||
| 1 | +//! The app driven the way a browser drives it: real router, real handlers, real | ||
| 2 | +//! session cookie. | ||
| 3 | +//! | ||
| 4 | +//! The point of this binary is the guards. A button the UI does not draw proves | ||
| 5 | +//! nothing — a Viewer who posts to the mutation endpoint anyway must be refused | ||
| 6 | +//! by the handler, and that is what these tests call. | ||
| 7 | +//! | ||
| 8 | +//! New HTTP tests belong in this file rather than a new `tests/*.rs`: one test | ||
| 9 | +//! binary links and runs once. | ||
| 10 | +#![cfg(feature = "ssr")] | ||
| 11 | + | ||
| 12 | +use std::path::PathBuf; | ||
| 13 | +use std::sync::Arc; | ||
| 14 | + | ||
| 15 | +use axum::Router; | ||
| 16 | +use axum::body::Body; | ||
| 17 | +use axum::http::{HeaderValue, Request, StatusCode, header}; | ||
| 18 | +use dizey_core::Role; | ||
| 19 | +use dizey_core::accounts::Accounts; | ||
| 20 | +use dizey_core::store::TursoStore; | ||
| 21 | +use dizey_web::server::SESSION_COOKIE; | ||
| 22 | +use leptos::prelude::LeptosOptions; | ||
| 23 | +use leptos::server_fn::ServerFn; | ||
| 24 | +use tower::ServiceExt; | ||
| 25 | +use uuid::Uuid; | ||
| 26 | + | ||
| 27 | +/// A throwaway workspace: its own database file and its own router. | ||
| 28 | +struct App { | ||
| 29 | + dir: PathBuf, | ||
| 30 | + router: Router, | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +impl App { | ||
| 34 | + async fn open() -> Self { | ||
| 35 | + let dir = std::env::temp_dir().join(format!("dizey-http-{}", Uuid::new_v4())); | ||
| 36 | + std::fs::create_dir_all(&dir).unwrap(); | ||
| 37 | + let store = TursoStore::open(dir.join("dizey.db").to_str().unwrap()) | ||
| 38 | + .await | ||
| 39 | + .unwrap(); | ||
| 40 | + let options = LeptosOptions::builder().output_name("dizey").build(); | ||
| 41 | + let router = dizey_web::server::router(Accounts::new(Arc::new(store)), options); | ||
| 42 | + Self { dir, router } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /// Posts a form to a server function, as the browser does, and returns the | ||
| 46 | + /// status, the JSON body and any session cookie the answer set. | ||
| 47 | + async fn post(&self, path: &str, cookie: Option<&str>, form: &[(&str, &str)]) -> Answer { | ||
| 48 | + let body = form | ||
| 49 | + .iter() | ||
| 50 | + .map(|(key, value)| format!("{}={}", encode(key), encode(value))) | ||
| 51 | + .collect::<Vec<_>>() | ||
| 52 | + .join("&"); | ||
| 53 | + let mut request = Request::builder() | ||
| 54 | + .method("POST") | ||
| 55 | + .uri(path) | ||
| 56 | + .header(header::ACCEPT, "application/json") | ||
| 57 | + .header(header::CONTENT_TYPE, "application/x-www-form-urlencoded"); | ||
| 58 | + if let Some(cookie) = cookie { | ||
| 59 | + request = request.header( | ||
| 60 | + header::COOKIE, | ||
| 61 | + HeaderValue::from_str(&format!("{SESSION_COOKIE}={cookie}")).unwrap(), | ||
| 62 | + ); | ||
| 63 | + } | ||
| 64 | + let response = self | ||
| 65 | + .router | ||
| 66 | + .clone() | ||
| 67 | + .oneshot(request.body(Body::from(body)).unwrap()) | ||
| 68 | + .await | ||
| 69 | + .unwrap(); | ||
| 70 | + let status = response.status(); | ||
| 71 | + let session = response | ||
| 72 | + .headers() | ||
| 73 | + .get_all(header::SET_COOKIE) | ||
| 74 | + .iter() | ||
| 75 | + .filter_map(|value| value.to_str().ok()) | ||
| 76 | + .find_map(session_from); | ||
| 77 | + let bytes = axum::body::to_bytes(response.into_body(), usize::MAX) | ||
| 78 | + .await | ||
| 79 | + .unwrap(); | ||
| 80 | + Answer { | ||
| 81 | + status, | ||
| 82 | + session, | ||
| 83 | + body: String::from_utf8(bytes.to_vec()).unwrap(), | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +impl Drop for App { | ||
| 89 | + fn drop(&mut self) { | ||
| 90 | + let _ = std::fs::remove_dir_all(&self.dir); | ||
| 91 | + } | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +struct Answer { | ||
| 95 | + status: StatusCode, | ||
| 96 | + session: Option<String>, | ||
| 97 | + body: String, | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +/// The `Set-Cookie` value's session token, if that header carries a live one. | ||
| 101 | +fn session_from(raw: &str) -> Option<String> { | ||
| 102 | + let value = raw.strip_prefix(SESSION_COOKIE)?.strip_prefix('=')?; | ||
| 103 | + let value = value.split(';').next()?.trim(); | ||
| 104 | + (!value.is_empty()).then(|| value.to_string()) | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +/// Form encoding, enough for the addresses and passphrases these tests send. | ||
| 108 | +fn encode(raw: &str) -> String { | ||
| 109 | + let mut out = String::with_capacity(raw.len()); | ||
| 110 | + for byte in raw.bytes() { | ||
| 111 | + match byte { | ||
| 112 | + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { | ||
| 113 | + out.push(byte as char) | ||
| 114 | + } | ||
| 115 | + b' ' => out.push('+'), | ||
| 116 | + other => out.push_str(&format!("%{other:02X}")), | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + out | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +fn path<F: ServerFn>() -> &'static str { | ||
| 123 | + F::PATH | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +/// Claims the workspace and returns the admin's session cookie. | ||
| 127 | +async fn admin(app: &App) -> String { | ||
| 128 | + let answer = app | ||
| 129 | + .post( | ||
| 130 | + path::<dizey_web::auth::ClaimWorkspace>(), | ||
| 131 | + None, | ||
| 132 | + &[ | ||
| 133 | + ("display_name", "Ada Lovelace"), | ||
| 134 | + ("email", "ada@dizey.sh"), | ||
| 135 | + ("password", "correct horse battery staple"), | ||
| 136 | + ], | ||
| 137 | + ) | ||
| 138 | + .await; | ||
| 139 | + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); | ||
| 140 | + assert_eq!(answer.body, "null", "claiming was refused"); | ||
| 141 | + answer.session.expect("claiming set no session cookie") | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +/// Invites someone in the given role and signs them in, returning their cookie. | ||
| 145 | +async fn invited(app: &App, admin: &str, email: &str, name: &str, role: Role) -> String { | ||
| 146 | + let role = match role { | ||
| 147 | + Role::Admin => "admin", | ||
| 148 | + Role::Member => "member", | ||
| 149 | + Role::Viewer => "viewer", | ||
| 150 | + }; | ||
| 151 | + let answer = app | ||
| 152 | + .post( | ||
| 153 | + path::<dizey_web::auth::InviteMember>(), | ||
| 154 | + Some(admin), | ||
| 155 | + &[("email", email), ("display_name", name), ("role", role)], | ||
| 156 | + ) | ||
| 157 | + .await; | ||
| 158 | + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); | ||
| 159 | + let token = answer | ||
| 160 | + .body | ||
| 161 | + .rsplit_once("/join/") | ||
| 162 | + .and_then(|(_, rest)| rest.split('"').next()) | ||
| 163 | + .expect("no invitation link in {answer.body}") | ||
| 164 | + .to_string(); | ||
| 165 | + | ||
| 166 | + let answer = app | ||
| 167 | + .post( | ||
| 168 | + path::<dizey_web::auth::RedeemLink>(), | ||
| 169 | + None, | ||
| 170 | + &[ | ||
| 171 | + ("token", &token), | ||
| 172 | + ("password", "lantern gravel spoon meadow"), | ||
| 173 | + ], | ||
| 174 | + ) | ||
| 175 | + .await; | ||
| 176 | + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); | ||
| 177 | + assert_eq!(answer.body, "null", "first sign-in was refused"); | ||
| 178 | + answer.session.expect("first sign-in set no session cookie") | ||
| 179 | +} | ||
| 180 | + | ||
| 181 | +/// The id of the board's first column, read the way the board page reads it. | ||
| 182 | +async fn first_column(app: &App, cookie: &str) -> String { | ||
| 183 | + let answer = app | ||
| 184 | + .post(path::<dizey_web::board::CurrentBoard>(), Some(cookie), &[]) | ||
| 185 | + .await; | ||
| 186 | + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); | ||
| 187 | + answer | ||
| 188 | + .body | ||
| 189 | + .split_once("\"columns\":[{\"column\":{\"id\":\"") | ||
| 190 | + .and_then(|(_, rest)| rest.split('"').next()) | ||
| 191 | + .expect("no column in the board") | ||
| 192 | + .to_string() | ||
| 193 | +} | ||
| 194 | + | ||
| 195 | +#[tokio::test] | ||
| 196 | +async fn a_viewer_who_posts_to_create_task_anyway_is_refused() { | ||
| 197 | + let app = App::open().await; | ||
| 198 | + let admin = admin(&app).await; | ||
| 199 | + let viewer = invited( | ||
| 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; | ||
| 208 | + | ||
| 209 | + let answer = app | ||
| 210 | + .post( | ||
| 211 | + path::<dizey_web::board::CreateTask>(), | ||
| 212 | + Some(&viewer), | ||
| 213 | + &[("title", "Viewer should not get this"), ("column_id", &column)], | ||
| 214 | + ) | ||
| 215 | + .await; | ||
| 216 | + | ||
| 217 | + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); | ||
| 218 | + assert_eq!(answer.body, "\"Forbidden\""); | ||
| 219 | + | ||
| 220 | + // And the refusal is not cosmetic: the board is still empty. | ||
| 221 | + let answer = app | ||
| 222 | + .post(path::<dizey_web::board::CurrentBoard>(), Some(&admin), &[]) | ||
| 223 | + .await; | ||
| 224 | + assert!( | ||
| 225 | + !answer.body.contains("Viewer should not get this"), | ||
| 226 | + "the refused task was written anyway: {}", | ||
| 227 | + answer.body | ||
| 228 | + ); | ||
| 229 | +} | ||
| 230 | + | ||
| 231 | +#[tokio::test] | ||
| 232 | +async fn a_member_may_create_a_task() { | ||
| 233 | + let app = App::open().await; | ||
| 234 | + let admin = admin(&app).await; | ||
| 235 | + let member = invited(&app, &admin, "mo@dizey.sh", "Mo Dubois", Role::Member).await; | ||
| 236 | + let column = first_column(&app, &admin).await; | ||
| 237 | + | ||
| 238 | + let answer = app | ||
| 239 | + .post( | ||
| 240 | + path::<dizey_web::board::CreateTask>(), | ||
| 241 | + Some(&member), | ||
| 242 | + &[("title", "Wire the deadline chip"), ("column_id", &column)], | ||
| 243 | + ) | ||
| 244 | + .await; | ||
| 245 | + assert_eq!(answer.body, "null", "a member was refused: {}", answer.body); | ||
| 246 | + | ||
| 247 | + let answer = app | ||
| 248 | + .post(path::<dizey_web::board::CurrentBoard>(), Some(&admin), &[]) | ||
| 249 | + .await; | ||
| 250 | + assert!(answer.body.contains("Wire the deadline chip")); | ||
| 251 | + assert!(answer.body.contains("DZ-01"), "no key on the new task"); | ||
| 252 | +} | ||
| 253 | + | ||
| 254 | +#[tokio::test] | ||
| 255 | +async fn a_task_cannot_be_dropped_into_another_workspaces_column() { | ||
| 256 | + let app = App::open().await; | ||
| 257 | + let admin = admin(&app).await; | ||
| 258 | + | ||
| 259 | + let answer = app | ||
| 260 | + .post( | ||
| 261 | + path::<dizey_web::board::CreateTask>(), | ||
| 262 | + Some(&admin), | ||
| 263 | + &[ | ||
| 264 | + ("title", "Wrong column"), | ||
| 265 | + ("column_id", "00000000-0000-0000-0000-000000000000"), | ||
| 266 | + ], | ||
| 267 | + ) | ||
| 268 | + .await; | ||
| 269 | + assert_eq!(answer.body, "\"Forbidden\""); | ||
| 270 | +} | ||
| 271 | + | ||
| 272 | +#[tokio::test] | ||
| 273 | +async fn a_card_needs_a_title() { | ||
| 274 | + let app = App::open().await; | ||
| 275 | + let admin = admin(&app).await; | ||
| 276 | + let column = first_column(&app, &admin).await; | ||
| 277 | + | ||
| 278 | + let answer = app | ||
| 279 | + .post( | ||
| 280 | + path::<dizey_web::board::CreateTask>(), | ||
| 281 | + Some(&admin), | ||
| 282 | + &[("title", " "), ("column_id", &column)], | ||
| 283 | + ) | ||
| 284 | + .await; | ||
| 285 | + assert_eq!(answer.body, "\"EmptyTitle\""); | ||
| 286 | +} | ||
| 287 | + | ||
| 288 | +#[tokio::test] | ||
| 289 | +async fn the_board_is_not_readable_without_a_session() { | ||
| 290 | + let app = App::open().await; | ||
| 291 | + let _admin = admin(&app).await; | ||
| 292 | + | ||
| 293 | + let answer = app | ||
| 294 | + .post(path::<dizey_web::board::CurrentBoard>(), None, &[]) | ||
| 295 | + .await; | ||
| 296 | + assert_eq!(answer.body, "{\"Err\":\"SignInFirst\"}"); | ||
| 297 | +} | ||
style/main.scssmodified+363 -0
| @@ -260,3 +260,366 @@ a { | |||
| 260 | border-top: 1px solid #f0eee7; | 260 | border-top: 1px solid #f0eee7; |
| 261 | padding-top: 12px; | 261 | padding-top: 12px; |
| 262 | } | 262 | } |
| 263 | + | ||
| 264 | +// -- the board (Main and EmptyBoard artboards) ------------------------------- | ||
| 265 | + | ||
| 266 | +.spacer { flex-grow: 1; } | ||
| 267 | + | ||
| 268 | +.board-name { | ||
| 269 | + font-size: 14px; | ||
| 270 | + font-weight: 600; | ||
| 271 | +} | ||
| 272 | + | ||
| 273 | +.topbar-who { | ||
| 274 | + font-size: 13px; | ||
| 275 | + color: var(--muted); | ||
| 276 | +} | ||
| 277 | + | ||
| 278 | +.new-task { | ||
| 279 | + display: flex; | ||
| 280 | + align-items: center; | ||
| 281 | + gap: 8px; | ||
| 282 | + height: 36px; | ||
| 283 | + padding: 0 14px; | ||
| 284 | + background: var(--accent); | ||
| 285 | + color: var(--surface); | ||
| 286 | + border: none; | ||
| 287 | + border-radius: var(--radius); | ||
| 288 | + font-family: inherit; | ||
| 289 | + font-size: 13px; | ||
| 290 | + font-weight: 600; | ||
| 291 | + cursor: pointer; | ||
| 292 | + | ||
| 293 | + &:hover { background: var(--accent-ink); } | ||
| 294 | +} | ||
| 295 | + | ||
| 296 | +.filterbar { | ||
| 297 | + height: 52px; | ||
| 298 | + background: var(--surface); | ||
| 299 | + border-bottom: 1px solid var(--border); | ||
| 300 | + display: flex; | ||
| 301 | + align-items: center; | ||
| 302 | + gap: 14px; | ||
| 303 | + padding: 0 24px; | ||
| 304 | +} | ||
| 305 | + | ||
| 306 | +.segmented { | ||
| 307 | + display: flex; | ||
| 308 | + align-items: center; | ||
| 309 | + background: #f2f0ea; | ||
| 310 | + border: 1px solid var(--border-strong); | ||
| 311 | + border-radius: var(--radius); | ||
| 312 | + padding: 2px; | ||
| 313 | + gap: 2px; | ||
| 314 | +} | ||
| 315 | + | ||
| 316 | +.segment { | ||
| 317 | + font-family: inherit; | ||
| 318 | + font-size: 13px; | ||
| 319 | + font-weight: 500; | ||
| 320 | + color: var(--muted); | ||
| 321 | + background: transparent; | ||
| 322 | + border: none; | ||
| 323 | + padding: 5px 12px; | ||
| 324 | + border-radius: 4px; | ||
| 325 | + cursor: pointer; | ||
| 326 | +} | ||
| 327 | + | ||
| 328 | +.segment-on { | ||
| 329 | + font-weight: 600; | ||
| 330 | + color: var(--ink); | ||
| 331 | + background: var(--surface); | ||
| 332 | + box-shadow: 0 1px 2px rgba(28, 27, 24, 0.06); | ||
| 333 | +} | ||
| 334 | + | ||
| 335 | +.sort-note { | ||
| 336 | + display: flex; | ||
| 337 | + align-items: center; | ||
| 338 | + height: 32px; | ||
| 339 | + padding: 0 10px; | ||
| 340 | + border: 1px solid var(--border-strong); | ||
| 341 | + border-radius: var(--radius); | ||
| 342 | + font-size: 13px; | ||
| 343 | + font-weight: 500; | ||
| 344 | +} | ||
| 345 | + | ||
| 346 | +.chip { | ||
| 347 | + display: flex; | ||
| 348 | + align-items: center; | ||
| 349 | + height: 32px; | ||
| 350 | + padding: 0 12px; | ||
| 351 | + border-radius: var(--radius); | ||
| 352 | + font-size: 13px; | ||
| 353 | + font-weight: 600; | ||
| 354 | + | ||
| 355 | + &-overdue { | ||
| 356 | + background: #f9ece4; | ||
| 357 | + border: 1px solid #ecd0bf; | ||
| 358 | + color: #a04a24; | ||
| 359 | + } | ||
| 360 | + | ||
| 361 | + &-blocked { | ||
| 362 | + background: #f7f0dd; | ||
| 363 | + border: 1px solid #e6d7ae; | ||
| 364 | + color: #7a5c1e; | ||
| 365 | + } | ||
| 366 | +} | ||
| 367 | + | ||
| 368 | +.board-stage { | ||
| 369 | + position: relative; | ||
| 370 | + min-height: calc(100vh - var(--topbar-height) - 52px); | ||
| 371 | + padding: 20px 24px 24px 24px; | ||
| 372 | +} | ||
| 373 | + | ||
| 374 | +.board-columns { | ||
| 375 | + display: grid; | ||
| 376 | + grid-template-columns: repeat(4, minmax(0, 1fr)); | ||
| 377 | + gap: 16px; | ||
| 378 | + align-items: start; | ||
| 379 | +} | ||
| 380 | + | ||
| 381 | +.column { | ||
| 382 | + background: #f1efe8; | ||
| 383 | + border-radius: 10px; | ||
| 384 | + padding: 12px; | ||
| 385 | + display: flex; | ||
| 386 | + flex-direction: column; | ||
| 387 | + gap: 10px; | ||
| 388 | + min-height: 120px; | ||
| 389 | +} | ||
| 390 | + | ||
| 391 | +.column-head { | ||
| 392 | + display: flex; | ||
| 393 | + align-items: center; | ||
| 394 | + gap: 8px; | ||
| 395 | + padding: 2px 4px; | ||
| 396 | +} | ||
| 397 | + | ||
| 398 | +.column-name { | ||
| 399 | + font-size: 13px; | ||
| 400 | + font-weight: 600; | ||
| 401 | +} | ||
| 402 | + | ||
| 403 | +.column-count { | ||
| 404 | + font-family: var(--font-mono); | ||
| 405 | + font-size: 11px; | ||
| 406 | + color: var(--muted-soft); | ||
| 407 | +} | ||
| 408 | + | ||
| 409 | +.column-add { | ||
| 410 | + width: 28px; | ||
| 411 | + height: 28px; | ||
| 412 | + border: none; | ||
| 413 | + border-radius: var(--radius); | ||
| 414 | + background: transparent; | ||
| 415 | + color: var(--muted); | ||
| 416 | + font-size: 16px; | ||
| 417 | + line-height: 1; | ||
| 418 | + cursor: pointer; | ||
| 419 | + | ||
| 420 | + &:hover { background: #e7e4dc; } | ||
| 421 | +} | ||
| 422 | + | ||
| 423 | +.column-cards { | ||
| 424 | + display: flex; | ||
| 425 | + flex-direction: column; | ||
| 426 | + gap: 10px; | ||
| 427 | +} | ||
| 428 | + | ||
| 429 | +.column-empty-add { | ||
| 430 | + border: 1px dashed #d5d1c7; | ||
| 431 | + border-radius: 8px; | ||
| 432 | + padding: 14px; | ||
| 433 | + background: transparent; | ||
| 434 | + color: var(--muted-soft); | ||
| 435 | + font-family: inherit; | ||
| 436 | + font-size: 13px; | ||
| 437 | + cursor: pointer; | ||
| 438 | + | ||
| 439 | + &:hover { color: var(--ink); } | ||
| 440 | +} | ||
| 441 | + | ||
| 442 | +.card { | ||
| 443 | + background: var(--surface); | ||
| 444 | + border: 1px solid var(--border); | ||
| 445 | + border-radius: 8px; | ||
| 446 | + padding: 12px; | ||
| 447 | + box-shadow: 0 1px 2px rgba(28, 27, 24, 0.05); | ||
| 448 | +} | ||
| 449 | + | ||
| 450 | +.card-done { | ||
| 451 | + background: #faf9f4; | ||
| 452 | + box-shadow: none; | ||
| 453 | + | ||
| 454 | + .card-title { color: var(--muted); } | ||
| 455 | +} | ||
| 456 | + | ||
| 457 | +.card-keys { | ||
| 458 | + display: flex; | ||
| 459 | + align-items: baseline; | ||
| 460 | + gap: 6px; | ||
| 461 | + font-family: var(--font-mono); | ||
| 462 | + font-size: 10px; | ||
| 463 | +} | ||
| 464 | + | ||
| 465 | +.card-key { color: var(--muted-soft); } | ||
| 466 | + | ||
| 467 | +.card-blocks, | ||
| 468 | +.card-blocked-by { color: #7a5c1e; } | ||
| 469 | + | ||
| 470 | +.card-title { | ||
| 471 | + font-size: 14px; | ||
| 472 | + font-weight: 500; | ||
| 473 | + line-height: 1.4; | ||
| 474 | + margin-top: 4px; | ||
| 475 | +} | ||
| 476 | + | ||
| 477 | +.card-foot { | ||
| 478 | + display: flex; | ||
| 479 | + align-items: center; | ||
| 480 | + gap: 6px; | ||
| 481 | + margin-top: 10px; | ||
| 482 | + flex-wrap: wrap; | ||
| 483 | +} | ||
| 484 | + | ||
| 485 | +.card-deadline { | ||
| 486 | + display: flex; | ||
| 487 | + align-items: center; | ||
| 488 | + font-family: var(--font-mono); | ||
| 489 | + font-size: 11px; | ||
| 490 | + color: var(--muted); | ||
| 491 | + background: #f1efe8; | ||
| 492 | + border-radius: 4px; | ||
| 493 | + padding: 2px 6px; | ||
| 494 | + | ||
| 495 | + &-overdue { | ||
| 496 | + color: #a04a24; | ||
| 497 | + background: #f9ece4; | ||
| 498 | + } | ||
| 499 | + | ||
| 500 | + &-none { | ||
| 501 | + color: var(--muted-soft); | ||
| 502 | + background: transparent; | ||
| 503 | + padding-left: 0; | ||
| 504 | + } | ||
| 505 | +} | ||
| 506 | + | ||
| 507 | +.card-comments { | ||
| 508 | + font-family: var(--font-mono); | ||
| 509 | + font-size: 11px; | ||
| 510 | + color: var(--muted); | ||
| 511 | +} | ||
| 512 | + | ||
| 513 | +.avatars { | ||
| 514 | + display: flex; | ||
| 515 | + align-items: center; | ||
| 516 | +} | ||
| 517 | + | ||
| 518 | +.avatar { | ||
| 519 | + width: 22px; | ||
| 520 | + height: 22px; | ||
| 521 | + border-radius: 50%; | ||
| 522 | + border: 2px solid var(--surface); | ||
| 523 | + color: var(--surface); | ||
| 524 | + font-family: var(--font-mono); | ||
| 525 | + font-size: 9px; | ||
| 526 | + display: flex; | ||
| 527 | + align-items: center; | ||
| 528 | + justify-content: center; | ||
| 529 | + | ||
| 530 | + & + & { margin-left: -7px; } | ||
| 531 | + | ||
| 532 | + &-none { | ||
| 533 | + border: 1px dashed #c9c5ba; | ||
| 534 | + color: var(--muted-soft); | ||
| 535 | + background: transparent; | ||
| 536 | + font-size: 12px; | ||
| 537 | + } | ||
| 538 | + | ||
| 539 | + &-tone-0 { background: #46557b; } | ||
| 540 | + &-tone-1 { background: #7b6846; } | ||
| 541 | + &-tone-2 { background: #5c7b46; } | ||
| 542 | + &-tone-3 { background: #7b4655; } | ||
| 543 | + &-tone-4 { background: #46707b; } | ||
| 544 | +} | ||
| 545 | + | ||
| 546 | +.board-empty { | ||
| 547 | + position: absolute; | ||
| 548 | + left: 50%; | ||
| 549 | + top: 50%; | ||
| 550 | + transform: translate(-50%, -50%); | ||
| 551 | + display: flex; | ||
| 552 | + flex-direction: column; | ||
| 553 | + align-items: center; | ||
| 554 | + gap: 12px; | ||
| 555 | + background: var(--surface); | ||
| 556 | + border: 1px solid var(--border); | ||
| 557 | + border-radius: 12px; | ||
| 558 | + padding: 28px 40px; | ||
| 559 | + box-shadow: 0 4px 16px rgba(28, 27, 24, 0.08); | ||
| 560 | + | ||
| 561 | + &-title { | ||
| 562 | + font-size: 16px; | ||
| 563 | + font-weight: 600; | ||
| 564 | + } | ||
| 565 | + | ||
| 566 | + &-sub { | ||
| 567 | + font-size: 13px; | ||
| 568 | + color: var(--muted); | ||
| 569 | + text-align: center; | ||
| 570 | + line-height: 1.5; | ||
| 571 | + } | ||
| 572 | +} | ||
| 573 | + | ||
| 574 | +.composer { | ||
| 575 | + background: var(--surface); | ||
| 576 | + border: 1px solid var(--border-strong); | ||
| 577 | + border-radius: 8px; | ||
| 578 | + padding: 10px; | ||
| 579 | + display: flex; | ||
| 580 | + flex-direction: column; | ||
| 581 | + gap: 8px; | ||
| 582 | +} | ||
| 583 | + | ||
| 584 | +.composer-input { | ||
| 585 | + width: 100%; | ||
| 586 | + height: 34px; | ||
| 587 | + padding: 0 10px; | ||
| 588 | + background: #faf9f6; | ||
| 589 | + border: 1px solid var(--border-strong); | ||
| 590 | + border-radius: var(--radius); | ||
| 591 | + font-family: inherit; | ||
| 592 | + font-size: 14px; | ||
| 593 | + color: var(--ink); | ||
| 594 | +} | ||
| 595 | + | ||
| 596 | +.composer-row { | ||
| 597 | + display: flex; | ||
| 598 | + align-items: center; | ||
| 599 | + gap: 8px; | ||
| 600 | +} | ||
| 601 | + | ||
| 602 | +.composer-add { | ||
| 603 | + height: 30px; | ||
| 604 | + padding: 0 12px; | ||
| 605 | + background: var(--accent); | ||
| 606 | + color: var(--surface); | ||
| 607 | + border: none; | ||
| 608 | + border-radius: var(--radius); | ||
| 609 | + font-family: inherit; | ||
| 610 | + font-size: 13px; | ||
| 611 | + font-weight: 600; | ||
| 612 | + cursor: pointer; | ||
| 613 | +} | ||
| 614 | + | ||
| 615 | +.composer-cancel { | ||
| 616 | + height: 30px; | ||
| 617 | + padding: 0 10px; | ||
| 618 | + background: transparent; | ||
| 619 | + border: 1px solid var(--border-strong); | ||
| 620 | + border-radius: var(--radius); | ||
| 621 | + font-family: inherit; | ||
| 622 | + font-size: 13px; | ||
| 623 | + color: var(--muted); | ||
| 624 | + cursor: pointer; | ||
| 625 | +} | ||