diff --git a/crates/izlek-core/migrations/0018_photo_in_the_user.sql b/crates/izlek-core/migrations/0018_photo_in_the_user.sql new file mode 100644 index 0000000..bef9f75 --- /dev/null +++ b/crates/izlek-core/migrations/0018_photo_in_the_user.sql @@ -0,0 +1,5 @@ +-- A profile picture lives in the database as bytes, the way an attachment +-- lives in its file (0010): no filesystem path survives a backup or a move. +-- `photo_path` (0001) never carried a value and is left behind, dead. +ALTER TABLE user ADD COLUMN photo BLOB; +ALTER TABLE user ADD COLUMN photo_mime TEXT; diff --git a/crates/izlek-core/src/board.rs b/crates/izlek-core/src/board.rs index 6ce3a6d..ae0e03d 100644 --- a/crates/izlek-core/src/board.rs +++ b/crates/izlek-core/src/board.rs @@ -76,7 +76,7 @@ pub enum Moved { pub struct Person { pub id: String, pub display_name: String, - pub photo_path: Option, + pub has_photo: bool, } impl Person { diff --git a/crates/izlek-core/src/store/mod.rs b/crates/izlek-core/src/store/mod.rs index 0c94cb9..857ef66 100644 --- a/crates/izlek-core/src/store/mod.rs +++ b/crates/izlek-core/src/store/mod.rs @@ -137,7 +137,7 @@ pub struct User { pub display_name: String, pub role: Role, pub password_hash: Option, - pub photo_path: Option, + pub has_photo: bool, pub created_at: OffsetDateTime, pub last_signed_in_at: Option, /// Who made this account. Null for the first account, which nobody @@ -578,12 +578,15 @@ pub trait Store: BoardReads + DetailReads + 'static { async fn set_password_hash(&self, user_id: &str, hash: &str) -> Result<()>; - async fn set_profile( - &self, - user_id: &str, - display_name: &str, - photo_path: Option<&str>, - ) -> Result<()>; + async fn set_profile(&self, user_id: &str, display_name: &str) -> Result<()>; + + /// Stores the profile photo's bytes and mime type, replacing any previous one. + async fn set_photo(&self, user_id: &str, bytes: &[u8], mime: &str) -> Result<()>; + + async fn clear_photo(&self, user_id: &str) -> Result<()>; + + /// The photo's bytes and mime type, or `None` when none is set. + async fn photo(&self, user_id: &str) -> Result, String)>>; /// Changes the sign-in address. Refuses with [`StoreError::Conflict`] if /// another account in the same workspace already holds it — the same diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index c50db08..90fb960 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -10,7 +10,7 @@ use rand::Rng; use time::OffsetDateTime; use time::format_description::well_known::Rfc3339; use turso::transaction::TransactionBehavior; -use turso::{Builder, Connection, Row, Value, params}; +use turso::{Builder, Connection, Row, params}; use ulid::Ulid; use super::secret; @@ -70,6 +70,7 @@ const MIGRATIONS: &[(i64, &str)] = &[ include_str!("../../migrations/0016_display_preferences.sql"), ), (17, include_str!("../../migrations/0017_ui_preference.sql")), + (18, include_str!("../../migrations/0018_photo_in_the_user.sql")), ]; /// The board a fresh workspace gets, and its columns. `Done` is the column @@ -577,7 +578,7 @@ fn user_from(row: &Row) -> Result { display_name: text(row, 3)?, role: Role::parse(&text(row, 4)?).ok_or_else(|| StoreError::Corrupt("role".into()))?, password_hash: opt_text(row, 5)?, - photo_path: opt_text(row, 6)?, + has_photo: row.get::(6).map_err(backend)? != 0, created_at: parse_stamp(&text(row, 7)?)?, last_signed_in_at: opt_stamp(row, 8)?, invited_by: opt_text(row, 9)?, @@ -589,7 +590,7 @@ fn user_from(row: &Row) -> Result { } const USER_COLUMNS: &str = "id, workspace_id, email, display_name, role, password_hash, \ - photo_path, created_at, last_signed_in_at, invited_by, timezone, theme, language, ui"; + (photo IS NOT NULL), created_at, last_signed_in_at, invited_by, timezone, theme, language, ui"; fn signin_link_from(row: &Row) -> Result { Ok(SigninLink { @@ -943,21 +944,28 @@ impl Store for TursoStore { } } - async fn set_profile( - &self, - user_id: &str, - display_name: &str, - photo_path: Option<&str>, - ) -> Result<()> { + async fn set_profile(&self, user_id: &str, display_name: &str) -> Result<()> { + let conn = self.conn.lock().await; + let n = conn + .execute( + "UPDATE user SET display_name = ?1 WHERE id = ?2", + params![display_name, user_id], + ) + .await + .map_err(backend)?; + if n == 0 { + Err(StoreError::NotFound) + } else { + Ok(()) + } + } + + async fn set_photo(&self, user_id: &str, bytes: &[u8], mime: &str) -> Result<()> { let conn = self.conn.lock().await; - let photo = match photo_path { - Some(p) => Value::from(p.to_string()), - None => Value::Null, - }; let n = conn .execute( - "UPDATE user SET display_name = ?1, photo_path = ?2 WHERE id = ?3", - params![display_name, photo, user_id], + "UPDATE user SET photo = ?1, photo_mime = ?2 WHERE id = ?3", + params![bytes, mime, user_id], ) .await .map_err(backend)?; @@ -968,6 +976,40 @@ impl Store for TursoStore { } } + async fn clear_photo(&self, user_id: &str) -> Result<()> { + let conn = self.conn.lock().await; + let n = conn + .execute( + "UPDATE user SET photo = NULL, photo_mime = NULL WHERE id = ?1", + params![user_id], + ) + .await + .map_err(backend)?; + if n == 0 { + Err(StoreError::NotFound) + } else { + Ok(()) + } + } + + async fn photo(&self, user_id: &str) -> Result, String)>> { + let conn = self.conn.lock().await; + let mut rows = conn + .query( + "SELECT photo, photo_mime FROM user WHERE id = ?1", + params![user_id], + ) + .await + .map_err(backend)?; + match rows.next().await.map_err(backend)? { + Some(row) => match row.get::>>(0).map_err(backend)? { + Some(bytes) => Ok(Some((bytes, text(&row, 1)?))), + None => Ok(None), + }, + None => Ok(None), + } + } + async fn set_email(&self, user_id: &str, workspace_id: &str, email: &str) -> Result<()> { let email = fold_email(email); if let Some(existing) = self.user_by_email(workspace_id, &email).await? @@ -2800,7 +2842,7 @@ impl DetailReads for TursoStore { let conn = self.conn.lock().await; let mut rows = conn .query( - "SELECT u.id, u.display_name, u.photo_path FROM task_assignee a \ + "SELECT u.id, u.display_name, (u.photo IS NOT NULL) FROM task_assignee a \ JOIN user u ON u.id = a.user_id \ WHERE a.task_id = ?1 ORDER BY u.display_name", params![task_id], @@ -2812,7 +2854,7 @@ impl DetailReads for TursoStore { out.push(Person { id: text(&row, 0)?, display_name: text(&row, 1)?, - photo_path: opt_text(&row, 2)?, + has_photo: row.get::(2).map_err(backend)? != 0, }); } Ok(out) @@ -2824,7 +2866,7 @@ impl DetailReads for TursoStore { // so neither leaves the server for this screen. let mut rows = conn .query( - "SELECT id, display_name, photo_path FROM user \ + "SELECT id, display_name, (photo IS NOT NULL) FROM user \ WHERE workspace_id = ?1 AND role <> ?2 ORDER BY display_name", params![workspace_id, Role::Viewer.as_str()], ) @@ -2835,7 +2877,7 @@ impl DetailReads for TursoStore { out.push(Person { id: text(&row, 0)?, display_name: text(&row, 1)?, - photo_path: opt_text(&row, 2)?, + has_photo: row.get::(2).map_err(backend)? != 0, }); } Ok(out) @@ -2883,7 +2925,7 @@ impl DetailReads for TursoStore { let conn = self.conn.lock().await; let mut rows = conn .query( - "SELECT c.id, c.body, c.created_at, u.id, u.display_name, u.photo_path \ + "SELECT c.id, c.body, c.created_at, u.id, u.display_name, (u.photo IS NOT NULL) \ FROM comment c JOIN user u ON u.id = c.author_id \ WHERE c.task_id = ?1 ORDER BY c.created_at, c.rowid", params![task_id], @@ -2899,7 +2941,7 @@ impl DetailReads for TursoStore { author: Person { id: text(&row, 3)?, display_name: text(&row, 4)?, - photo_path: opt_text(&row, 5)?, + has_photo: row.get::(5).map_err(backend)? != 0, }, }); } @@ -2939,7 +2981,7 @@ impl DetailReads for TursoStore { let mut rows = conn .query( "SELECT a.id, a.kind, a.detail, a.created_at, u.id, u.display_name, \ - u.photo_path \ + (u.photo IS NOT NULL) \ FROM activity a LEFT JOIN user u ON u.id = a.actor_id \ WHERE a.task_id = ?1 ORDER BY a.created_at, a.rowid", params![task_id], @@ -2952,7 +2994,7 @@ impl DetailReads for TursoStore { Some(id) => Some(Person { id, display_name: text(&row, 5)?, - photo_path: opt_text(&row, 6)?, + has_photo: row.get::(6).map_err(backend)? != 0, }), None => None, }; @@ -3039,7 +3081,7 @@ impl BoardReads for TursoStore { let conn = self.conn.lock().await; let mut rows = conn .query( - "SELECT a.task_id, u.id, u.display_name, u.photo_path \ + "SELECT a.task_id, u.id, u.display_name, (u.photo IS NOT NULL) \ FROM task_assignee a \ JOIN task t ON t.id = a.task_id \ JOIN user u ON u.id = a.user_id \ @@ -3056,7 +3098,7 @@ impl BoardReads for TursoStore { Person { id: text(&row, 1)?, display_name: text(&row, 2)?, - photo_path: opt_text(&row, 3)?, + has_photo: row.get::(3).map_err(backend)? != 0, }, )); } diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index 880f62a..273f480 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -236,14 +236,14 @@ async fn migrations_apply_once_and_survive_reopen() { let path = dir.join("izlek.db").to_string_lossy().into_owned(); let first = TursoStore::open(&path).await.unwrap(); - assert_eq!(first.schema_version().await.unwrap(), 17); + assert_eq!(first.schema_version().await.unwrap(), 18); claim(&first).await; drop(first); // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and // must not lose what the first open wrote. let second = TursoStore::open(&path).await.unwrap(); - assert_eq!(second.schema_version().await.unwrap(), 17); + assert_eq!(second.schema_version().await.unwrap(), 18); assert_eq!(second.workspace().await.unwrap().unwrap().name, "Izlek"); drop(second); let _ = std::fs::remove_dir_all(&dir); @@ -260,7 +260,7 @@ async fn migration_0013_rebuilds_mail_rule_without_losing_its_ledger() { a_pre_0013_store_with_a_rule_send_and_decision().await; let store = TursoStore::open(path.to_str().unwrap()).await.unwrap(); - assert_eq!(store.schema_version().await.unwrap(), 17); + assert_eq!(store.schema_version().await.unwrap(), 18); assert_eq!(store.board(&workspace).await.unwrap().unwrap().id, board); let rules = store.mail_rules(&board).await.unwrap(); @@ -780,7 +780,12 @@ async fn profile_and_role_updates_stick() { scratch .store - .set_profile(&user.id, "Grace H.", Some("photos/grace.png")) + .set_profile(&user.id, "Grace H.") + .await + .unwrap(); + scratch + .store + .set_photo(&user.id, b"grace-bytes", "image/png") .await .unwrap(); scratch @@ -791,9 +796,12 @@ async fn profile_and_role_updates_stick() { let at = OffsetDateTime::now_utc(); scratch.store.mark_signed_in(&user.id, at).await.unwrap(); + let photo = scratch.store.photo(&user.id).await.unwrap().unwrap(); + assert_eq!(photo.0, b"grace-bytes".to_vec()); + assert_eq!(photo.1, "image/png"); let user = scratch.store.user(&user.id).await.unwrap().unwrap(); assert_eq!(user.display_name, "Grace H."); - assert_eq!(user.photo_path.as_deref(), Some("photos/grace.png")); + assert!(user.has_photo); assert_eq!(user.role, Role::Viewer); // Stored as RFC 3339 text, so equality holds to the second. assert_eq!( @@ -802,21 +810,10 @@ async fn profile_and_role_updates_stick() { ); // Clearing the photo is a real update, not a no-op. - scratch - .store - .set_profile(&user.id, "Grace H.", None) - .await - .unwrap(); - assert!( - scratch - .store - .user(&user.id) - .await - .unwrap() - .unwrap() - .photo_path - .is_none() - ); + scratch.store.clear_photo(&user.id).await.unwrap(); + let user = scratch.store.user(&user.id).await.unwrap().unwrap(); + assert!(!user.has_photo); + assert!(scratch.store.photo(&user.id).await.unwrap().is_none()); } #[tokio::test] @@ -2292,7 +2289,7 @@ fn initials_fall_back_to_two_letters() { let person = |name: &str| Person { id: "u".into(), display_name: name.into(), - photo_path: None, + has_photo: false, }; assert_eq!(person("Mel Duarte").initials(), "MD"); assert_eq!(person("Ada").initials(), "A"); diff --git a/crates/izlek-web/src/auth.rs b/crates/izlek-web/src/auth.rs index 7b639b9..c6b1ae7 100644 --- a/crates/izlek-web/src/auth.rs +++ b/crates/izlek-web/src/auth.rs @@ -17,8 +17,8 @@ use topcoat::router::response::{IntoResponse, Response}; use topcoat::router::{HeaderName, StatusCode, header, route}; use crate::server::{ - Refusal, accounts, clear_session_cookie, client_label, mail, presented_session, - require_admin, require_user, set_session_cookie, + Refusal, accounts, clear_session_cookie, client_label, mail, presented_session, require_admin, + require_user, set_session_cookie, }; use crate::settings::encode_q; @@ -100,7 +100,12 @@ struct ClaimWorkspaceForm { #[route(POST "/api/claim_workspace")] async fn claim_workspace(cx: &Cx, Form(input): Form) -> Redirect { match accounts(cx) - .claim_workspace(WORKSPACE_NAME, &input.email, &input.display_name, &input.password) + .claim_workspace( + WORKSPACE_NAME, + &input.email, + &input.display_name, + &input.password, + ) .await { Ok((_workspace, signed_in)) => { @@ -121,7 +126,10 @@ struct SignInForm { /// password yet, or the password is wrong. #[route(POST "/api/sign_in")] async fn sign_in(cx: &Cx, Form(input): Form) -> Redirect { - match accounts(cx).sign_in(&input.email, &input.password, &client_label(cx)).await { + match accounts(cx) + .sign_in(&input.email, &input.password, &client_label(cx)) + .await + { Ok(signed_in) => { set_session_cookie(cx, signed_in.session_token.expose(), SESSION_LIFETIME); redirect(cx, None) @@ -161,7 +169,11 @@ async fn redeem_link(cx: &Cx, Form(input): Form) -> Redirect { // Redeemed; the referring `/join/{token}` now names a spent // link, which would show "no longer works" to someone who just // signed in, so land on the board itself instead. - Ok((StatusCode::SEE_OTHER, [(header::LOCATION, "/".to_string())], Json(None))) + Ok(( + StatusCode::SEE_OTHER, + [(header::LOCATION, "/".to_string())], + Json(None), + )) } Err(error) => redirect(cx, Some(error.into())), } @@ -215,7 +227,10 @@ async fn invite_member(cx: &Cx, Form(input): Form) -> Result admin, Err(refusal) => return invite_answer(cx, has_referer, Err(refusal)), }; - match accounts(cx).invite(&admin, &input.email, &input.display_name, input.role).await { + match accounts(cx) + .invite(&admin, &input.email, &input.display_name, input.role) + .await + { Ok(made) => { mail(cx).after_invite(); invite_answer(cx, has_referer, Ok(made.user.email)) @@ -226,7 +241,11 @@ async fn invite_member(cx: &Cx, Form(input): Form) -> Result) -> Result { +fn invite_answer( + cx: &Cx, + has_referer: bool, + outcome: std::result::Result, +) -> Result { if !has_referer { return Json(outcome).into_response(cx); } diff --git a/crates/izlek-web/src/board.rs b/crates/izlek-web/src/board.rs index f5e7deb..de5eab7 100644 --- a/crates/izlek-web/src/board.rs +++ b/crates/izlek-web/src/board.rs @@ -6,7 +6,7 @@ //! the server — a drag's only client-side memory is the browser's own drag //! session (`dataTransfer`), read back by the column that catches the drop. -use izlek_core::board::{DeadlineState, Moved, Person, TaskCard}; +use izlek_core::board::{DeadlineState, Moved, TaskCard}; use izlek_core::store::{NewTask, User}; use time::{Date, OffsetDateTime}; use topcoat::Result; @@ -50,7 +50,13 @@ async fn move_card_shared( return Ok(Some(Refusal::Forbidden)); } match store - .move_task(task_id, from_column_id, to_column_id, &user.id, OffsetDateTime::now_utc()) + .move_task( + task_id, + from_column_id, + to_column_id, + &user.id, + OffsetDateTime::now_utc(), + ) .await { Ok(Moved::Recorded(transition)) => { @@ -154,7 +160,15 @@ struct CreateTaskForm { /// fields the procedure below trades over the wire. #[route(POST "/api/create_task")] async fn create_task(cx: &Cx, Form(input): Form) -> Redirect { - match create_task_shared(cx, &input.title, &input.column_id, &input.description, &input.deadline).await? { + match create_task_shared( + cx, + &input.title, + &input.column_id, + &input.description, + &input.deadline, + ) + .await? + { Some(refusal) => redirect_refused(cx, "create_task", refusal), // Created; the referring `/?new=1` would reopen a blank new-task // modal, so land on the board itself instead. @@ -173,7 +187,14 @@ struct MoveCardForm { /// and the drop handler in `card_menu_script` all post here. #[route(POST "/api/move_card")] async fn move_card(cx: &Cx, Form(input): Form) -> Redirect { - match move_card_shared(cx, &input.task_id, &input.from_column_id, &input.to_column_id).await? { + match move_card_shared( + cx, + &input.task_id, + &input.from_column_id, + &input.to_column_id, + ) + .await? + { Some(refusal) => redirect_refused(cx, "move_card", refusal), None => redirect(cx), } @@ -232,8 +253,11 @@ async fn board_columns(cx: &Cx, sort: String) -> Result { let today = OffsetDateTime::now_utc().date(); let may_write = user.role.can_write_tasks(); - let all_columns: Vec<(String, String)> = - view_data.columns.iter().map(|column| (column.column.id.clone(), column.column.name.clone())).collect(); + let all_columns: Vec<(String, String)> = view_data + .columns + .iter() + .map(|column| (column.column.id.clone(), column.column.name.clone())) + .collect(); let mut columns = Vec::new(); for column in view_data.columns { columns.push(render_column(cx, column, today, may_write, &all_columns, lang).await?); @@ -260,7 +284,19 @@ async fn render_column( let is_empty = column.cards.is_empty(); let mut cards = Vec::new(); for card in column.cards { - cards.push(render_card(cx, card, today, is_done_column, &column_id, may_write, all_columns, lang).await?); + cards.push( + render_card( + cx, + card, + today, + is_done_column, + &column_id, + may_write, + all_columns, + lang, + ) + .await?, + ); } view! { @@ -307,15 +343,18 @@ async fn render_card( let comments = card.comment_count; let mut assignees = Vec::new(); for person in card.assignees.iter() { - assignees.push(avatar(cx, person, "").await?); + assignees.push(crate::layout::avatar(cx, person, "").await?); } let has_assignees = !card.assignees.is_empty(); let task_id = card.id.clone(); let from_column = column_id.to_string(); let href = format!("/?task={}", card.id); let menu_id = format!("card-menu-{}", card.id); - let move_targets: Vec<(String, String)> = - all_columns.iter().filter(|(id, _)| id != column_id).cloned().collect(); + let move_targets: Vec<(String, String)> = all_columns + .iter() + .filter(|(id, _)| id != column_id) + .cloned() + .collect(); view! { cx => Result { view! { cx => } } -pub(crate) async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { - let initials = person.initials(); - let tone = person - .id - .bytes() - .fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32)) - % 5; - let class = format!("avatar avatar-tone-{tone} {extra}"); - let name = person.display_name.clone(); - view! { - cx => - (initials) - } -} - /// Which task, if any, `/` renders the detail modal open on, and the refusal /// (if any) a create or move landed back here with. `file` opens the viewer /// over that task's modal, the same nested query-param convention `confirm` @@ -502,8 +526,11 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result { let overdue = view_data.overdue_count(today); let blocked = view_data.blocked_count(); let may_write = user.role.can_write_tasks(); - let all_columns: Vec<(String, String)> = - view_data.columns.iter().map(|column| (column.column.id.clone(), column.column.name.clone())).collect(); + let all_columns: Vec<(String, String)> = view_data + .columns + .iter() + .map(|column| (column.column.id.clone(), column.column.name.clone())) + .collect(); let query = query_params::(cx)?; let open_task = query.task.clone(); // `?task=X&new=1` together would render both modals at once — two @@ -525,7 +552,7 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result { (crate::layout::topbar_nav(cx, crate::layout::NavPage::Board, lang).await?)
- (crate::layout::user_menu(cx, &user.display_name, &user.email, user.role, lang).await?) + (crate::layout::user_menu(cx, &crate::detail::Me::from(user), lang).await?)
diff --git a/crates/izlek-web/src/detail.rs b/crates/izlek-web/src/detail.rs index f3c1b5f..f58b32f 100644 --- a/crates/izlek-web/src/detail.rs +++ b/crates/izlek-web/src/detail.rs @@ -17,7 +17,9 @@ //! unchanged. use izlek_core::board::{DeadlineState, Person}; -use izlek_core::detail::{Comment, DeletionCost, DependencyEdge, TaskDetail, TaskFacts, moment_label_in, parse_zone}; +use izlek_core::detail::{ + Comment, DeletionCost, DependencyEdge, TaskDetail, TaskFacts, moment_label_in, parse_zone, +}; use izlek_core::store::{Store, StoreError, User}; use serde::{Deserialize, Serialize}; use time::{Date, UtcOffset}; @@ -49,6 +51,7 @@ pub struct Me { pub email: String, pub role: izlek_core::Role, pub language: String, + pub has_photo: bool, } impl From<&User> for Me { @@ -59,6 +62,7 @@ impl From<&User> for Me { email: user.email.clone(), role: user.role, language: user.language.clone(), + has_photo: user.has_photo, } } } @@ -124,7 +128,11 @@ mod resolve_direction_tests { /// 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. -async fn task_of(store: &dyn Store, user: &User, task_id: &str) -> std::result::Result { +async fn task_of( + store: &dyn Store, + user: &User, + task_id: &str, +) -> std::result::Result { match store.task(task_id).await { Ok(Some(facts)) if facts.workspace_id == user.workspace_id => Ok(facts), Ok(_) => Err(Refusal::NotFound), @@ -136,7 +144,10 @@ async fn task_of(store: &dyn Store, user: &User, task_id: &str) -> std::result:: } /// The writer behind this request and the task they named. -async fn writer_and_task(cx: &Cx, task_id: &str) -> std::result::Result<(User, TaskFacts), Refusal> { +async fn writer_and_task( + cx: &Cx, + task_id: &str, +) -> std::result::Result<(User, TaskFacts), Refusal> { let user = require_writer(cx).await?; let store = accounts(cx).store().clone(); let facts = task_of(store.as_ref(), &user, task_id).await?; @@ -157,7 +168,11 @@ fn back_to(cx: &Cx) -> String { } fn redirect(cx: &Cx, refusal: Option) -> Redirect { - Ok((StatusCode::SEE_OTHER, [(header::LOCATION, back_to(cx))], Json(refusal))) + Ok(( + StatusCode::SEE_OTHER, + [(header::LOCATION, back_to(cx))], + Json(refusal), + )) } // -- the ten calls -------------------------------------------------------- @@ -208,7 +223,10 @@ struct FileIdForm { /// Shared by the route and [`task_modal`], which calls it directly rather /// than going back through its own HTTP endpoint — the same shape `pages.rs` /// reads the store straight through for its own screens. -async fn load_snapshot(cx: &Cx, task_id: &str) -> Result> { +async fn load_snapshot( + cx: &Cx, + task_id: &str, +) -> Result> { use izlek_core::detail::load; use time::OffsetDateTime; @@ -258,7 +276,9 @@ async fn load_snapshot(cx: &Cx, task_id: &str) -> Result Result) -> Result>> { +async fn fetch_task( + cx: &Cx, + Form(input): Form, +) -> Result>> { Ok(Json(load_snapshot(cx, &input.task_id).await?)) } @@ -318,7 +341,14 @@ async fn save_task(cx: &Cx, Form(input): Form) -> Redirect { let store = accounts(cx).store().clone(); let activity_ids = store - .save_task(&input.task_id, &title, &description, deadline, &user.id, OffsetDateTime::now_utc()) + .save_task( + &input.task_id, + &title, + &description, + deadline, + &user.id, + OffsetDateTime::now_utc(), + ) .await?; for activity_id in activity_ids { mail(cx).after_activity(store.clone(), activity_id); @@ -350,7 +380,13 @@ async fn assign(cx: &Cx, Form(input): Form) -> Redirect { store.assign_task(&input.task_id, &person.id).await?; let activity_id = store - .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Assigned, &person.display_name, OffsetDateTime::now_utc()) + .record_activity( + &input.task_id, + Some(&actor.id), + &ActivityKind::Assigned, + &person.display_name, + OffsetDateTime::now_utc(), + ) .await?; mail(cx).after_activity(store, activity_id); redirect(cx, None) @@ -375,7 +411,13 @@ async fn unassign(cx: &Cx, Form(input): Form) -> Redirect { } store.unassign_task(&input.task_id, &person.id).await?; let activity_id = store - .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Unassigned, &person.display_name, OffsetDateTime::now_utc()) + .record_activity( + &input.task_id, + Some(&actor.id), + &ActivityKind::Unassigned, + &person.display_name, + OffsetDateTime::now_utc(), + ) .await?; mail(cx).after_activity(store, activity_id); redirect(cx, None) @@ -407,7 +449,13 @@ async fn link_tasks(cx: &Cx, Form(input): Form) -> Redirect { Err(error) => return Err(error.into()), } let activity_id = store - .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Linked, &other.row.task_key, now) + .record_activity( + &input.task_id, + Some(&actor.id), + &ActivityKind::Linked, + &other.row.task_key, + now, + ) .await?; mail(cx).after_activity(store, activity_id); redirect(cx, None) @@ -434,7 +482,13 @@ async fn unlink_tasks(cx: &Cx, Form(input): Form) -> Redirect { let now = OffsetDateTime::now_utc(); store.clear_dependency(&blocked, &blocking, now).await?; let activity_id = store - .record_activity(&input.task_id, Some(&actor.id), &ActivityKind::Unlinked, &other.row.task_key, now) + .record_activity( + &input.task_id, + Some(&actor.id), + &ActivityKind::Unlinked, + &other.row.task_key, + now, + ) .await?; mail(cx).after_activity(store, activity_id); redirect(cx, None) @@ -462,14 +516,19 @@ async fn post_comment(cx: &Cx, Form(input): Form) -> Redirect { return redirect(cx, Some(Refusal::EmptyComment)); } - let written = store.add_comment(&input.task_id, &user.id, body, OffsetDateTime::now_utc()).await?; + let written = store + .add_comment(&input.task_id, &user.id, body, OffsetDateTime::now_utc()) + .await?; mail(cx).after_activity(store, written.activity_id); redirect(cx, None) } /// What a delete would take with it, for the confirmation step. Reads only. #[route(POST "/api/what_delete_costs")] -async fn what_delete_costs(cx: &Cx, Form(input): Form) -> Result>> { +async fn what_delete_costs( + cx: &Cx, + Form(input): Form, +) -> Result>> { if let Err(refusal) = writer_and_task(cx, &input.task_id).await { return Ok(Json(Err(refusal))); } @@ -491,7 +550,9 @@ async fn delete_task(cx: &Cx, Form(input): Form) -> Redirect { Err(refusal) => return redirect(cx, Some(refusal)), }; let store = accounts(cx).store().clone(); - let deletion = store.delete_task(&input.task_id, &user.id, OffsetDateTime::now_utc()).await?; + let deletion = store + .delete_task(&input.task_id, &user.id, OffsetDateTime::now_utc()) + .await?; // A blocker being deleted unblocks whatever was waiting only on it, which // is the same news as the blocker finishing. The freeing is committed; // the send is a separate step, off the request. @@ -501,7 +562,11 @@ async fn delete_task(cx: &Cx, Form(input): Form) -> Redirect { mail(cx).after_activity(store, deletion.activity_id); // Deleted; the referring `/?task=` no longer names anything, so land // on the board itself rather than reopening a dead modal. - Ok((StatusCode::SEE_OTHER, [(header::LOCATION, "/".to_string())], Json(None))) + Ok(( + StatusCode::SEE_OTHER, + [(header::LOCATION, "/".to_string())], + Json(None), + )) } /// Deletes an attachment's row and its bytes. A hard delete, unlike @@ -659,20 +724,6 @@ pub(crate) mod glyph { } } -/// A person as a circle. Ported from `izlek-web/src/board.rs`'s `Avatar`; that -/// component has not crossed over into this crate yet, so this is a private -/// copy rather than a shared one. -async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { - let initials = person.initials(); - let tone = person.id.bytes().fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32)) % 5; - view! { - cx => - - (initials) - - } -} - /// `Escape` for everything the task modal renders, topmost first: viewer → /// delete confirm (`confirm=delete` in URL) → open edit popovers → modal /// itself — one resolver at priority 90 on `window.__izlekEsc` (table on @@ -768,7 +819,11 @@ async fn title_control(cx: &Cx, task: &TaskDetail, may_write: bool, lang: Lang) async fn description_control(cx: &Cx, task: &TaskDetail, may_write: bool, lang: Lang) -> Result { let empty = task.description.trim().is_empty(); let no_description = t(lang, Key::NoDescription).to_string(); - let prose = if empty { no_description.clone() } else { task.description.clone() }; + let prose = if empty { + no_description.clone() + } else { + task.description.clone() + }; if !may_write { return view! { cx =>

(prose)

}; @@ -795,10 +850,18 @@ async fn description_control(cx: &Cx, task: &TaskDetail, may_write: bool, lang: } } -async fn deadline_control(cx: &Cx, task: &TaskDetail, today: Date, may_write: bool, lang: Lang) -> Result { +async fn deadline_control( + cx: &Cx, + task: &TaskDetail, + today: Date, + may_write: bool, + lang: Lang, +) -> Result { let overdue = task.is_overdue(today); let label = match task.deadline_parts(today) { - Some(parts) if parts.state == DeadlineState::Overdue => format!("{} · {}", parts.date, t(lang, Key::Overdue)), + Some(parts) if parts.state == DeadlineState::Overdue => { + format!("{} · {}", parts.date, t(lang, Key::Overdue)) + } Some(parts) => parts.date, None => t(lang, Key::NoDeadline).to_string(), }; @@ -956,12 +1019,18 @@ async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { view! { cx => } } -async fn assignee_chip(cx: &Cx, task_id: &str, person: &Person, may_write: bool, lang: Lang) -> Result { +async fn assignee_chip( + cx: &Cx, + task_id: &str, + person: &Person, + may_write: bool, + lang: Lang, +) -> Result { let remove_title = crate::i18n::take_off_this_task(lang, &person.display_name); view! { cx => - (avatar(cx, person, "avatar-sm").await?) + (crate::layout::avatar(cx, person, "avatar-sm").await?) (person.display_name.clone()) if may_write {
@@ -992,7 +1061,7 @@ async fn assignee_picker(cx: &Cx, task_id: &str, people: &[Person], lang: Lang)
@@ -1052,7 +1121,14 @@ async fn link_picker(cx: &Cx, task_id: &str, linkable: &[LinkTarget], lang: Lang } } -async fn dep_row(cx: &Cx, task_id: &str, edge: &DependencyEdge, direction: Direction, may_write: bool, lang: Lang) -> Result { +async fn dep_row( + cx: &Cx, + task_id: &str, + edge: &DependencyEdge, + direction: Direction, + may_write: bool, + lang: Lang, +) -> Result { let cleared = edge.is_cleared(); let note = match direction { Direction::BlockedBy => edge.blocked_by_label(), @@ -1128,7 +1204,7 @@ async fn comment_row(cx: &Cx, comment: &Comment, zone: UtcOffset) -> Result { view! { cx =>
- (avatar(cx, &comment.author, "avatar-lg").await?) + (crate::layout::avatar(cx, &comment.author, "avatar-lg").await?)
(comment.author.display_name.clone()) @@ -1152,7 +1228,10 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool) -> Result // a gone task id is the common case — so the language is read // the same way `board.rs`'s query-refusal branch does, English // only when there truly is nobody signed in to read one off of. - let lang = require_user(cx).await.map(|user| Lang::from_code(&user.language)).unwrap_or(Lang::En); + let lang = require_user(cx) + .await + .map(|user| Lang::from_code(&user.language)) + .unwrap_or(Lang::En); return view! { cx =>