Per-user instrument/ledger density, rebuilt settings page
Browse files at this commitd3811f16ab8925f6cb3e0e37f1f9fdc84ef1605dParent: 29f6365- feat
- per-user instrument/ledger density, rebuilt settings page
13 changed files +419 -116
- crates/in-core/migrations/0002_ui.sql +6 -0
- crates/in-core/src/store/mod.rs +9 -0
- crates/in-core/src/store/reconcile.rs +32 -25
- crates/in-core/src/store/schema.rs +6 -2
- crates/in-core/src/store/turso_store.rs +21 -3
- crates/in-core/tests/store.rs +65 -0
- crates/in-web/src/i18n.rs +3 -0
- crates/in-web/src/layout.rs +8 -6
- crates/in-web/src/server.rs +7 -1
- crates/in-web/src/settings.rs +148 -78
- crates/in-web/tests/http.rs +89 -0
- style/_instrument.scss +5 -1
- style/main.scss +20 -0
crates/in-core/migrations/0002_ui.sqladded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +-- The person's UI density: 'ledger' or 'instrument', read by `root_layout` | |
| 2 | +-- into `data-ui`. The DEFAULT is the backfill: SQLite fills every existing | |
| 3 | +-- row with it as the column is added. Databases already carrying the column | |
| 4 | +-- never see this file applied piecemeal — they reach the declared shape | |
| 5 | +-- through `in reconcile`, whose copy map backfills the same value. | |
| 6 | +ALTER TABLE user ADD COLUMN ui TEXT NOT NULL DEFAULT 'ledger'; |
crates/in-core/src/store/mod.rsmodified+9 -0
| @@ -93,6 +93,9 @@ pub struct User { | ||
| 93 | 93 | /// file that can be restored still costs. Recomputed from the rows after |
| 94 | 94 | /// every mutation, never blindly incremented. |
| 95 | 95 | pub used_bytes: u64, |
| 96 | + /// Display-only, the way `quota_bytes` is data: 'ledger' or 'instrument', | |
| 97 | + /// read by `root_layout` into `data-ui`. Nothing stored depends on it. | |
| 98 | + pub ui: String, | |
| 96 | 99 | pub created_at: OffsetDateTime, |
| 97 | 100 | pub last_seen_at: Option<OffsetDateTime>, |
| 98 | 101 | } |
| @@ -358,6 +361,12 @@ pub trait Store: 'static + Send + Sync { | ||
| 358 | 361 | /// layer reads this and treats the person as signed out. |
| 359 | 362 | async fn set_user_disabled(&self, user_id: &str, disabled: bool) -> Result<()>; |
| 360 | 363 | |
| 364 | + /// Writes the person's UI density: `ledger` or `instrument`, read by | |
| 365 | + /// `root_layout` into `data-ui`. Anything else is refused with | |
| 366 | + /// [`StoreError::Corrupt`] — the same refusal a bad enum read from the | |
| 367 | + /// row gets, because a bad enum written is a corrupt row. | |
| 368 | + async fn set_user_ui(&self, id: &str, ui: &str) -> Result<()>; | |
| 369 | + | |
| 361 | 370 | // -- folders ----------------------------------------------------------- |
| 362 | 371 | |
| 363 | 372 | /// Creates a folder. A parent of another owner is [`StoreError::CrossOwner`], |
crates/in-core/src/store/reconcile.rsmodified+32 -25
| @@ -202,26 +202,34 @@ struct TableMap { | ||
| 202 | 202 | columns: Vec<(&'static str, String)>, |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | -/// Builds the explicit column map. Every table maps every column to its old | |
| 206 | -/// self: In's first schema is the declared one, so a database old enough to | |
| 207 | -/// be reconciled carries the same columns, and the map is the receipt that | |
| 208 | -/// says nothing was dropped, renamed or defaulted on the way across. | |
| 209 | -fn build_maps() -> Vec<TableMap> { | |
| 205 | +/// Builds the explicit column map. Unchanged tables map every column to its | |
| 206 | +/// old self; the user table carries the migration-specific expression for | |
| 207 | +/// `ui`: a database old enough to predate the column starts on the schema's | |
| 208 | +/// own default rather than on an empty string, which no writer would ever | |
| 209 | +/// store and no reader would ever honour. | |
| 210 | +fn build_maps(old_has_ui: bool) -> Vec<TableMap> { | |
| 210 | 211 | vec![ |
| 211 | 212 | TableMap { |
| 212 | 213 | name: "user", |
| 213 | - columns: old_cols(&[ | |
| 214 | - "id", | |
| 215 | - "oidc_sub", | |
| 216 | - "email", | |
| 217 | - "display_name", | |
| 218 | - "admin", | |
| 219 | - "disabled", | |
| 220 | - "quota_bytes", | |
| 221 | - "used_bytes", | |
| 222 | - "created_at", | |
| 223 | - "last_seen_at", | |
| 224 | - ]), | |
| 214 | + columns: { | |
| 215 | + let mut columns = old_cols(&[ | |
| 216 | + "id", | |
| 217 | + "oidc_sub", | |
| 218 | + "email", | |
| 219 | + "display_name", | |
| 220 | + "admin", | |
| 221 | + "disabled", | |
| 222 | + "quota_bytes", | |
| 223 | + "used_bytes", | |
| 224 | + ]); | |
| 225 | + columns.push(if old_has_ui { | |
| 226 | + ("ui", "old.ui".into()) | |
| 227 | + } else { | |
| 228 | + ("ui", "'ledger'".into()) | |
| 229 | + }); | |
| 230 | + columns.extend(old_cols(&["created_at", "last_seen_at"])); | |
| 231 | + columns | |
| 232 | + }, | |
| 225 | 233 | }, |
| 226 | 234 | TableMap { |
| 227 | 235 | name: "folder", |
| @@ -363,14 +371,15 @@ async fn validate_maps(conn: &Connection, maps: &[TableMap]) -> Result<()> { | ||
| 363 | 371 | /// main schema, in foreign-key-safe order: owners before folders, folders |
| 364 | 372 | /// before the files and sessions that name them, everything before the |
| 365 | 373 | /// shares that name all of it. |
| 366 | -async fn copy_data(_old_conn: &Connection, new_conn: &Connection, path: &str) -> Result<()> { | |
| 374 | +async fn copy_data(old_conn: &Connection, new_conn: &Connection, path: &str) -> Result<()> { | |
| 367 | 375 | let escaped = path.replace('\'', "''"); |
| 368 | 376 | new_conn |
| 369 | 377 | .execute(&format!("ATTACH DATABASE '{}' AS old", escaped), ()) |
| 370 | 378 | .await |
| 371 | 379 | .map_err(|e| StoreError::Backend(e.to_string()))?; |
| 372 | 380 | |
| 373 | - let maps = build_maps(); | |
| 381 | + let old_has_ui = old_has_column(old_conn, "user", "ui").await?; | |
| 382 | + let maps = build_maps(old_has_ui); | |
| 374 | 383 | validate_maps(new_conn, &maps).await?; |
| 375 | 384 | |
| 376 | 385 | // Foreign keys stay off during the copy and are checked by `verify` |
| @@ -555,12 +564,10 @@ fn backup_name(path: &str) -> Result<String> { | ||
| 555 | 564 | } |
| 556 | 565 | } |
| 557 | 566 | |
| 558 | -/// A probe the copy plan can ask: whether the old database already carries | |
| 559 | -/// `column` on `table`. Unused while the declared schema is the first one — | |
| 560 | -/// every database old enough to be reconciled predates every column it | |
| 561 | -/// would probe — and kept because the second migration will need exactly | |
| 562 | -/// this question on its first day. | |
| 563 | -#[allow(dead_code)] | |
| 567 | +/// A probe the copy plan asks: whether the old database already carries | |
| 568 | +/// `column` on `table`. A column the second migration added is absent on a | |
| 569 | +/// database old enough to predate it, and the map backfills the default | |
| 570 | +/// instead of reading a column that is not there. | |
| 564 | 571 | async fn old_has_column(conn: &Connection, table: &str, column: &str) -> Result<bool> { |
| 565 | 572 | let mut rows = conn |
| 566 | 573 | .query(&format!("PRAGMA table_info({table})"), ()) |
crates/in-core/src/store/schema.rsmodified+6 -2
| @@ -11,8 +11,12 @@ use turso::Connection; | ||
| 11 | 11 | |
| 12 | 12 | /// The declared migrations, in order. An empty database is built by applying |
| 13 | 13 | /// them one after another; each one applies cleanly to what the ones before |
| 14 | -/// it built, so their concatenation is itself a valid whole-schema script. | |
| 15 | -pub(crate) const MIGRATIONS: &[&str] = &[include_str!("../../migrations/0001_init.sql")]; | |
| 14 | +/// it built (`0002` is `ALTER`s), so their concatenation is itself a valid | |
| 15 | +/// whole-schema script. | |
| 16 | +pub(crate) const MIGRATIONS: &[&str] = &[ | |
| 17 | + include_str!("../../migrations/0001_init.sql"), | |
| 18 | + include_str!("../../migrations/0002_ui.sql"), | |
| 19 | +]; | |
| 16 | 20 | |
| 17 | 21 | /// The whole declared schema — every migration applied in order — as one |
| 18 | 22 | /// batch of SQL. |
crates/in-core/src/store/turso_store.rsmodified+21 -3
| @@ -36,7 +36,7 @@ const UPLOADS_DIR: &str = "uploads"; | ||
| 36 | 36 | const THUMB_SOURCE_CAP: u64 = 64 * 1024 * 1024; |
| 37 | 37 | |
| 38 | 38 | const USER_COLUMNS: &str = |
| 39 | - "id, oidc_sub, email, display_name, admin, disabled, quota_bytes, used_bytes, created_at, last_seen_at"; | |
| 39 | + "id, oidc_sub, email, display_name, admin, disabled, quota_bytes, used_bytes, ui, created_at, last_seen_at"; | |
| 40 | 40 | const FOLDER_COLUMNS: &str = "id, owner_id, parent_id, name, created_at, deleted_at"; |
| 41 | 41 | const FILE_COLUMNS: &str = |
| 42 | 42 | "id, owner_id, folder_id, name, mime, size_bytes, thumb_state, created_at, updated_at, deleted_at"; |
| @@ -713,8 +713,9 @@ fn user_from(row: &Row) -> Result<User> { | ||
| 713 | 713 | disabled: row.get::<i64>(5).map_err(backend)? != 0, |
| 714 | 714 | quota_bytes: row.get::<i64>(6).map_err(backend)?.max(0) as u64, |
| 715 | 715 | used_bytes: row.get::<i64>(7).map_err(backend)?.max(0) as u64, |
| 716 | - created_at: parse_stamp(&text(row, 8)?)?, | |
| 717 | - last_seen_at: opt_stamp(row, 9)?, | |
| 716 | + ui: text(row, 8)?, | |
| 717 | + created_at: parse_stamp(&text(row, 9)?)?, | |
| 718 | + last_seen_at: opt_stamp(row, 10)?, | |
| 718 | 719 | }) |
| 719 | 720 | } |
| 720 | 721 | |
| @@ -946,6 +947,23 @@ impl Store for TursoStore { | ||
| 946 | 947 | Ok(()) |
| 947 | 948 | } |
| 948 | 949 | |
| 950 | + async fn set_user_ui(&self, id: &str, ui: &str) -> Result<()> { | |
| 951 | + if ui != "ledger" && ui != "instrument" { | |
| 952 | + return Err(StoreError::Corrupt(format!("ui {ui:?}"))); | |
| 953 | + } | |
| 954 | + let conn = self.conn.lock().await; | |
| 955 | + let n = conn | |
| 956 | + .execute("UPDATE user SET ui = ?1 WHERE id = ?2", params![ui, id]) | |
| 957 | + .await | |
| 958 | + .map_err(backend)?; | |
| 959 | + if n == 0 { | |
| 960 | + return Err(StoreError::NotFound); | |
| 961 | + } | |
| 962 | + drop(conn); | |
| 963 | + self.announce([Topic::Admin(id.to_string())]); | |
| 964 | + Ok(()) | |
| 965 | + } | |
| 966 | + | |
| 949 | 967 | async fn create_folder( |
| 950 | 968 | &self, |
| 951 | 969 | owner_id: &str, |
crates/in-core/tests/store.rsmodified+65 -0
| @@ -1120,3 +1120,68 @@ async fn add_share_user_needs_the_owner() { | ||
| 1120 | 1120 | scratch.store.add_share_user(&user.id, ShareKind::File, &file.id, &stranger.id, true).await.unwrap(); |
| 1121 | 1121 | assert!(scratch.store.can_see(ShareKind::File, &file.id, &stranger.id).await.unwrap()); |
| 1122 | 1122 | } |
| 1123 | + | |
| 1124 | +#[tokio::test] | |
| 1125 | +async fn a_provisioned_user_wears_the_ledger_ui() { | |
| 1126 | + let scratch = Scratch::open().await; | |
| 1127 | + let user = alice(&scratch.store).await; | |
| 1128 | + assert_eq!(user.ui, "ledger"); | |
| 1129 | +} | |
| 1130 | + | |
| 1131 | +#[tokio::test] | |
| 1132 | +async fn the_ui_round_trips_and_refuses_what_is_not_offered() { | |
| 1133 | + let scratch = Scratch::open().await; | |
| 1134 | + let user = alice(&scratch.store).await; | |
| 1135 | + scratch.store.set_user_ui(&user.id, "instrument").await.unwrap(); | |
| 1136 | + let back = scratch.store.user(&user.id).await.unwrap().unwrap(); | |
| 1137 | + assert_eq!(back.ui, "instrument"); | |
| 1138 | + // A value no settings screen offers is refused, and the row keeps what | |
| 1139 | + // the last good write left — the same Corrupt the store answers a bad | |
| 1140 | + // enum it reads. | |
| 1141 | + assert!(matches!( | |
| 1142 | + scratch.store.set_user_ui(&user.id, "dense").await, | |
| 1143 | + Err(StoreError::Corrupt(_)) | |
| 1144 | + )); | |
| 1145 | + let kept = scratch.store.user(&user.id).await.unwrap().unwrap(); | |
| 1146 | + assert_eq!(kept.ui, "instrument"); | |
| 1147 | + assert!(matches!( | |
| 1148 | + scratch.store.set_user_ui("no-such-user", "ledger").await, | |
| 1149 | + Err(StoreError::NotFound) | |
| 1150 | + )); | |
| 1151 | +} | |
| 1152 | + | |
| 1153 | +#[tokio::test] | |
| 1154 | +async fn a_first_migration_database_gains_the_ui_column_on_open() { | |
| 1155 | + // A database built from 0001 alone — the shape In was deployed with — | |
| 1156 | + // carries no `ui` column. Opening it with the current code reconciles it | |
| 1157 | + // onto the declared schema, and its people arrive wearing the default. | |
| 1158 | + let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::new())); | |
| 1159 | + std::fs::create_dir_all(&dir).unwrap(); | |
| 1160 | + let path = dir.join("in.db").to_string_lossy().into_owned(); | |
| 1161 | + { | |
| 1162 | + let db = turso::Builder::new_local(&path).build().await.unwrap(); | |
| 1163 | + let conn = db.connect().unwrap(); | |
| 1164 | + conn.execute_batch(include_str!("../migrations/0001_init.sql")) | |
| 1165 | + .await | |
| 1166 | + .unwrap(); | |
| 1167 | + conn.execute( | |
| 1168 | + "INSERT INTO user (id, oidc_sub, email, display_name, admin, disabled, \ | |
| 1169 | + quota_bytes, used_bytes, created_at, last_seen_at) \ | |
| 1170 | + VALUES ('u-old', 'sub-old', 'old@example.com', 'Old', 1, 0, 100, 0, \ | |
| 1171 | + '2026-08-01T00:00:00Z', '2026-08-01T00:00:00Z')", | |
| 1172 | + (), | |
| 1173 | + ) | |
| 1174 | + .await | |
| 1175 | + .unwrap(); | |
| 1176 | + } | |
| 1177 | + let storage = dir.join("storage"); | |
| 1178 | + let store = TursoStore::open(&path, Some(&storage)).await.unwrap(); | |
| 1179 | + let user = store.user_by_oidc_sub("sub-old").await.unwrap().unwrap(); | |
| 1180 | + assert_eq!(user.ui, "ledger"); | |
| 1181 | + // And the carried row takes a new preference like any other. | |
| 1182 | + store.set_user_ui(&user.id, "instrument").await.unwrap(); | |
| 1183 | + let back = store.user(&user.id).await.unwrap().unwrap(); | |
| 1184 | + assert_eq!(back.ui, "instrument"); | |
| 1185 | + drop(store); | |
| 1186 | + let _ = std::fs::remove_dir_all(&dir); | |
| 1187 | +} |
crates/in-web/src/i18n.rsmodified+3 -0
| @@ -161,6 +161,7 @@ pub enum Key { | ||
| 161 | 161 | ViewOnly, |
| 162 | 162 | NoLinks, |
| 163 | 163 | ManageLinks, |
| 164 | + UiLabel, | |
| 164 | 165 | } |
| 165 | 166 | |
| 166 | 167 | pub fn t(lang: Lang, key: Key) -> &'static str { |
| @@ -259,6 +260,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 259 | 260 | ViewOnly => "View only — preview, no downloads", |
| 260 | 261 | NoLinks => "No share links yet.", |
| 261 | 262 | ManageLinks => "Share links", |
| 263 | + UiLabel => "Interface", | |
| 262 | 264 | }, |
| 263 | 265 | Lang::Tr => match key { |
| 264 | 266 | Cancel => "Vazgeç", |
| @@ -353,6 +355,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 353 | 355 | ViewOnly => "Yalnızca görüntüleme — önizleme, indirme yok", |
| 354 | 356 | NoLinks => "Henüz paylaşım bağlantısı yok.", |
| 355 | 357 | ManageLinks => "Paylaşım bağlantıları", |
| 358 | + UiLabel => "Arayüz", | |
| 356 | 359 | }, |
| 357 | 360 | } |
| 358 | 361 | } |
crates/in-web/src/layout.rsmodified+8 -6
| @@ -850,12 +850,14 @@ const STYLE: Asset = asset!("assets/main.css"); | ||
| 850 | 850 | |
| 851 | 851 | #[layout("/")] |
| 852 | 852 | async fn root_layout(cx: &Cx, slot: Result) -> Result { |
| 853 | - // v1 has no per-user theme or language: every page renders light, and | |
| 854 | - // the language comes off the request's Accept-Language header. | |
| 855 | - let asking = match current_user(cx).await { | |
| 856 | - Ok(user) => user.is_some(), | |
| 857 | - Err(_) => false, | |
| 853 | + // The one per-user chrome knob: the UI density, read off the request's | |
| 854 | + // own user. Signed-out (or unreadable) renders ledger, the default. | |
| 855 | + let me = match current_user(cx).await { | |
| 856 | + Ok(user) => user.as_ref(), | |
| 857 | + Err(_) => None, | |
| 858 | 858 | }; |
| 859 | + let asking = me.is_some(); | |
| 860 | + let ui = me.as_ref().map_or("ledger", |user| user.ui.as_str()); | |
| 859 | 861 | let lang = crate::i18n::lang(cx); |
| 860 | 862 | |
| 861 | 863 | let content = match slot { |
| @@ -878,7 +880,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result { | ||
| 878 | 880 | let build = STYLE.id().as_u64().to_string(); |
| 879 | 881 | view! { |
| 880 | 882 | <!DOCTYPE html> |
| 881 | - <html lang=(lang.code()) data-ui="ledger" data-build=(build)> | |
| 883 | + <html lang=(lang.code()) data-ui=(ui) data-build=(build)> | |
| 882 | 884 | <head> |
| 883 | 885 | <meta charset="utf-8"> |
| 884 | 886 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
crates/in-web/src/server.rsmodified+7 -1
| @@ -212,6 +212,8 @@ pub enum Refusal { | ||
| 212 | 212 | AncestorTrashed, |
| 213 | 213 | /// The store failed to say. Never a sign-in prompt — see `require_user`. |
| 214 | 214 | Unavailable, |
| 215 | + /// The ui field was not one of the values the form offers. | |
| 216 | + BadUi, | |
| 215 | 217 | } |
| 216 | 218 | |
| 217 | 219 | impl Refusal { |
| @@ -232,6 +234,7 @@ impl Refusal { | ||
| 232 | 234 | Refusal::BadChunk => "That piece arrived damaged — send it again.".to_string(), |
| 233 | 235 | Refusal::AncestorTrashed => "Restore the folder it is in first.".to_string(), |
| 234 | 236 | Refusal::Unavailable => "Something went wrong.".to_string(), |
| 237 | + Refusal::BadUi => "That interface choice is not offered.".to_string(), | |
| 235 | 238 | } |
| 236 | 239 | } |
| 237 | 240 | |
| @@ -252,8 +255,9 @@ impl Refusal { | ||
| 252 | 255 | Refusal::ShareRevoked => "Bu bağlantı artık çalışmıyor.".to_string(), |
| 253 | 256 | Refusal::UploadExpired => "Bu yüklemenin süresi doldu — yeniden başlat.".to_string(), |
| 254 | 257 | Refusal::BadChunk => "Bu parça bozuk geldi — yeniden gönder.".to_string(), |
| 255 | - Refusal::AncestorTrashed => "Önce içinde olduğu klasörü geri yükle.".to_string(), | |
| 256 | 258 | Refusal::Unavailable => "Bir şeyler ters gitti.".to_string(), |
| 259 | + Refusal::AncestorTrashed => "Önce içinde olduğu klasörü geri yükle.".to_string(), | |
| 260 | + Refusal::BadUi => "Bu arayüz seçeneği sunulmuyor.".to_string(), | |
| 257 | 261 | } |
| 258 | 262 | } |
| 259 | 263 | |
| @@ -274,6 +278,7 @@ impl Refusal { | ||
| 274 | 278 | "bad-chunk" => Refusal::BadChunk, |
| 275 | 279 | "ancestor-trashed" => Refusal::AncestorTrashed, |
| 276 | 280 | "unavailable" => Refusal::Unavailable, |
| 281 | + "bad-ui" => Refusal::BadUi, | |
| 277 | 282 | _ => return None, |
| 278 | 283 | }) |
| 279 | 284 | } |
| @@ -298,6 +303,7 @@ impl Refusal { | ||
| 298 | 303 | Refusal::BadChunk => "bad-chunk", |
| 299 | 304 | Refusal::AncestorTrashed => "ancestor-trashed", |
| 300 | 305 | Refusal::Unavailable => "unavailable", |
| 306 | + Refusal::BadUi => "bad-ui", | |
| 301 | 307 | } |
| 302 | 308 | } |
| 303 | 309 | } |
crates/in-web/src/settings.rsmodified+148 -78
| @@ -117,6 +117,29 @@ async fn set_disabled(cx: &Cx, Form(input): Form<DisableForm>) -> Redirect { | ||
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | +#[derive(Deserialize)] | |
| 121 | +struct UiForm { | |
| 122 | + ui: String, | |
| 123 | +} | |
| 124 | + | |
| 125 | +/// Switches the reader's own interface between the ledger and the | |
| 126 | +/// instrument. Anything else is refused — the form only ever offers the | |
| 127 | +/// two, so another value is a hand-built post, not a typo. | |
| 128 | +#[route(POST "/api/settings/ui")] | |
| 129 | +async fn set_ui(cx: &Cx, Form(input): Form<UiForm>) -> Redirect { | |
| 130 | + let user = match require_user(cx).await { | |
| 131 | + Ok(user) => user, | |
| 132 | + Err(refusal) => return redirect_back(cx, "ui", Some(refusal)), | |
| 133 | + }; | |
| 134 | + if input.ui != "ledger" && input.ui != "instrument" { | |
| 135 | + return redirect_back(cx, "ui", Some(Refusal::BadUi)); | |
| 136 | + } | |
| 137 | + match app(cx).store.set_user_ui(&user.id, &input.ui).await { | |
| 138 | + Ok(()) => redirect_back(cx, "ui", None), | |
| 139 | + Err(error) => redirect_back(cx, "ui", Some(refusal_of(error))), | |
| 140 | + } | |
| 141 | +} | |
| 142 | + | |
| 120 | 143 | /// The reader's profile and quota, their live share links, and — for an |
| 121 | 144 | /// admin — every account with its quota and kill switch. |
| 122 | 145 | #[page("/settings")] |
| @@ -157,92 +180,139 @@ async fn settings(cx: &Cx) -> Result { | ||
| 157 | 180 | let origin = app(cx).config.listen_url(); |
| 158 | 181 | view! { |
| 159 | 182 | cx => |
| 160 | - <main class="settings-shell"> | |
| 161 | - (topbar(cx, NavPage::Settings, &fresh, language).await?) | |
| 162 | - <h1 class="settings-title">(t(language, Key::Settings))</h1> | |
| 163 | - (refusal_banner(cx, language, &["create", "revoke", "add", "remove", "quota", "disable"]).await?) | |
| 164 | - if let Some(token) = created { | |
| 183 | + (topbar(cx, NavPage::Settings, &fresh, language).await?) | |
| 184 | + <div class="settings-shell"> | |
| 185 | + <main class="settings-stage"> | |
| 186 | + <h1 class="settings-title">(t(language, Key::Settings))</h1> | |
| 187 | + (refusal_banner(cx, language, &["create", "revoke", "add", "remove", "quota", "disable", "ui"]).await?) | |
| 188 | + if let Some(token) = created { | |
| 189 | + <section class="panel"> | |
| 190 | + <div class="panel-head"> | |
| 191 | + <h2 class="panel-title">(t(language, Key::LinkCreated))</h2> | |
| 192 | + </div> | |
| 193 | + <div class="panel-body"> | |
| 194 | + <p class="field-note">(t(language, Key::CopyLinkOnce))</p> | |
| 195 | + <p class="member-link-value">(format!("{origin}/s/{token}"))</p> | |
| 196 | + </div> | |
| 197 | + </section> | |
| 198 | + } | |
| 165 | 199 | <section class="panel"> |
| 166 | - <h2 class="panel-title">(t(language, Key::LinkCreated))</h2> | |
| 200 | + <div class="panel-head"> | |
| 201 | + <h2 class="panel-title">(t(language, Key::Profile))</h2> | |
| 202 | + </div> | |
| 167 | 203 | <div class="panel-body"> |
| 168 | - <p class="field-note">(t(language, Key::CopyLinkOnce))</p> | |
| 169 | - <p class="member-link-value">(format!("{origin}/s/{token}"))</p> | |
| 204 | + <label class="field"> | |
| 205 | + <span class="field-label">(t(language, Key::DisplayName))</span> | |
| 206 | + <span class="field-static">(fresh.display_name.clone())</span> | |
| 207 | + </label> | |
| 208 | + <label class="field"> | |
| 209 | + <span class="field-label">(t(language, Key::EmailAddress))</span> | |
| 210 | + <span class="field-static">(fresh.email.clone())</span> | |
| 211 | + </label> | |
| 212 | + <div class="field"> | |
| 213 | + <span class="field-label">(t(language, Key::QuotaUsage))</span> | |
| 214 | + <span class="field-static">(format!("{} {} {}", human_bytes(fresh.used_bytes), t(language, Key::QuotaOf), human_bytes(fresh.quota_bytes)))</span> | |
| 215 | + <div class="quota-bar" role="progressbar" aria-valuenow=(quota_percent(&fresh).to_string()) aria-valuemin="0" aria-valuemax="100"> | |
| 216 | + <div class="quota-fill" style=(format!("width: {}%", quota_percent(&fresh)))></div> | |
| 217 | + </div> | |
| 218 | + </div> | |
| 219 | + <form class="field" method="post" action="/api/settings/ui"> | |
| 220 | + <label class="field"> | |
| 221 | + <span class="field-label">(t(language, Key::UiLabel))</span> | |
| 222 | + <select class="field-input" name="ui"> | |
| 223 | + <option value="instrument" selected=(fresh.ui == "instrument")>"Instrument"</option> | |
| 224 | + <option value="ledger" selected=(fresh.ui == "ledger")>"Ledger"</option> | |
| 225 | + </select> | |
| 226 | + </label> | |
| 227 | + <div class="panel-foot"> | |
| 228 | + <button class="primary" type="submit">(t(language, Key::Save))</button> | |
| 229 | + </div> | |
| 230 | + </form> | |
| 170 | 231 | </div> |
| 171 | 232 | </section> |
| 172 | - } | |
| 173 | - <section class="panel"> | |
| 174 | - <h2 class="panel-title">(t(language, Key::Profile))</h2> | |
| 175 | - <div class="panel-body"> | |
| 176 | - <p><span class="field-label">(t(language, Key::DisplayName))</span> (fresh.display_name.clone())</p> | |
| 177 | - <p><span class="field-label">(t(language, Key::EmailAddress))</span> (fresh.email.clone())</p> | |
| 178 | - <p> | |
| 179 | - <span class="field-label">(t(language, Key::QuotaUsage))</span> | |
| 180 | - (format!("{} {} {}", human_bytes(fresh.used_bytes), t(language, Key::QuotaOf), human_bytes(fresh.quota_bytes))) | |
| 181 | - </p> | |
| 182 | - <div class="quota-bar" role="progressbar" aria-valuenow=(quota_percent(&fresh).to_string()) aria-valuemin="0" aria-valuemax="100"> | |
| 183 | - <div class="quota-fill" style=(format!("width: {}%", quota_percent(&fresh)))></div> | |
| 184 | - </div> | |
| 185 | - </div> | |
| 186 | - </section> | |
| 187 | - <section class="panel"> | |
| 188 | - <h2 class="panel-title">(t(language, Key::ManageLinks))</h2> | |
| 189 | - <div class="panel-body"> | |
| 190 | - if live_links.is_empty() { | |
| 191 | - <p class="field-note">(t(language, Key::NoLinks))</p> | |
| 192 | - } | |
| 193 | - for link in live_links { | |
| 194 | - <div class="member-row"> | |
| 195 | - <span class="member-name">(format!("{} · {}", link.kind.as_str(), link.target_id.clone()))</span> | |
| 196 | - <span class="field-note">(expiry_line(language, link.expires_at))</span> | |
| 197 | - <span class="field-note">(if link.can_download { t(language, Key::CanDownload) } else { t(language, Key::ViewOnly) })</span> | |
| 198 | - <form class="pop-row-form" method="post" action="/api/share/link/revoke"> | |
| 199 | - <input type="hidden" name="id" value=(link.id.clone())> | |
| 200 | - <button type="submit">(t(language, Key::RevokeLink))</button> | |
| 201 | - </form> | |
| 202 | - </div> | |
| 203 | - } | |
| 204 | - </div> | |
| 205 | - </section> | |
| 206 | - if fresh.admin { | |
| 207 | 233 | <section class="panel"> |
| 208 | - <h2 class="panel-title">(t(language, Key::AdminPanel))</h2> | |
| 234 | + <div class="panel-head"> | |
| 235 | + <h2 class="panel-title">(t(language, Key::ManageLinks))</h2> | |
| 236 | + </div> | |
| 209 | 237 | <div class="panel-body"> |
| 210 | - <div class="member-table"> | |
| 211 | - for listed in &users { | |
| 212 | - <div class="member-row"> | |
| 213 | - <span class="member-name">(listed.display_name.clone())</span> | |
| 214 | - <span class="member-address">(listed.email.clone())</span> | |
| 215 | - <span class="field-note">(format!("{} {} {}", human_bytes(listed.used_bytes), t(language, Key::QuotaOf), human_bytes(listed.quota_bytes)))</span> | |
| 216 | - if listed.admin { | |
| 217 | - <span class="chip chip-admin">(t(language, Key::AdminBadge))</span> | |
| 218 | - } | |
| 219 | - if listed.disabled { | |
| 220 | - <span class="chip chip-off">(t(language, Key::DisabledBadge))</span> | |
| 221 | - } | |
| 222 | - <form class="pop-row-form" method="post" action="/api/settings/quota"> | |
| 223 | - <input type="hidden" name="user_id" value=(listed.id.clone())> | |
| 224 | - <input class="field-input" type="number" name="quota_bytes" min="0" value=(listed.quota_bytes.to_string()) aria-label=(t(language, Key::QuotaBytes))> | |
| 225 | - <button type="submit">(t(language, Key::SetQuota))</button> | |
| 226 | - </form> | |
| 227 | - if listed.id != fresh.id { | |
| 228 | - <form class="pop-row-form" method="post" action="/api/settings/disable"> | |
| 229 | - <input type="hidden" name="user_id" value=(listed.id.clone())> | |
| 230 | - if listed.disabled { | |
| 231 | - <input type="hidden" name="disabled" value="0"> | |
| 232 | - <button type="submit">(t(language, Key::EnableUser))</button> | |
| 233 | - } else { | |
| 234 | - <input type="hidden" name="disabled" value="1"> | |
| 235 | - <button class="quiet-danger" type="submit">(t(language, Key::DisableUser))</button> | |
| 236 | - } | |
| 237 | - </form> | |
| 238 | - } | |
| 239 | - </div> | |
| 240 | - } | |
| 241 | - </div> | |
| 238 | + if live_links.is_empty() { | |
| 239 | + <p class="field-note">(t(language, Key::NoLinks))</p> | |
| 240 | + } | |
| 241 | + for link in live_links { | |
| 242 | + <div class="member-row"> | |
| 243 | + <span class="member-name">(format!("{} · {}", link.kind.as_str(), link.target_id.clone()))</span> | |
| 244 | + <span class="field-note">(expiry_line(language, link.expires_at))</span> | |
| 245 | + <span class="field-note">(if link.can_download { t(language, Key::CanDownload) } else { t(language, Key::ViewOnly) })</span> | |
| 246 | + <form class="pop-row-form" method="post" action="/api/share/link/revoke"> | |
| 247 | + <input type="hidden" name="id" value=(link.id.clone())> | |
| 248 | + <button type="submit">(t(language, Key::RevokeLink))</button> | |
| 249 | + </form> | |
| 250 | + </div> | |
| 251 | + } | |
| 242 | 252 | </div> |
| 243 | 253 | </section> |
| 244 | - } | |
| 245 | - </main> | |
| 254 | + if fresh.admin { | |
| 255 | + <section class="panel"> | |
| 256 | + <div class="panel-head"> | |
| 257 | + <h2 class="panel-title">(t(language, Key::AdminPanel))</h2> | |
| 258 | + </div> | |
| 259 | + <div class="panel-body"> | |
| 260 | + <div class="table-pan"> | |
| 261 | + <table class="member-table"> | |
| 262 | + <thead> | |
| 263 | + <tr> | |
| 264 | + <th class="member-col-name" scope="col">(t(language, Key::NameColumn))</th> | |
| 265 | + <th class="member-col-address" scope="col">(t(language, Key::EmailAddress))</th> | |
| 266 | + <th class="member-col-account" scope="col">(t(language, Key::QuotaUsage))</th> | |
| 267 | + <th class="member-col-role" scope="col"></th> | |
| 268 | + </tr> | |
| 269 | + </thead> | |
| 270 | + <tbody> | |
| 271 | + for listed in &users { | |
| 272 | + <tr class="member-row"> | |
| 273 | + <td class="member-col-name member-name"> | |
| 274 | + <span class="member-name-row"> | |
| 275 | + (listed.display_name.clone()) | |
| 276 | + if listed.admin { | |
| 277 | + <span class="chip chip-admin">(t(language, Key::AdminBadge))</span> | |
| 278 | + } | |
| 279 | + if listed.disabled { | |
| 280 | + <span class="chip chip-off">(t(language, Key::DisabledBadge))</span> | |
| 281 | + } | |
| 282 | + </span> | |
| 283 | + </td> | |
| 284 | + <td class="member-col-address member-address">(listed.email.clone())</td> | |
| 285 | + <td class="member-col-account member-account">(format!("{} {} {}", human_bytes(listed.used_bytes), t(language, Key::QuotaOf), human_bytes(listed.quota_bytes)))</td> | |
| 286 | + <td class="member-col-role"> | |
| 287 | + <form class="pop-row-form" method="post" action="/api/settings/quota"> | |
| 288 | + <input type="hidden" name="user_id" value=(listed.id.clone())> | |
| 289 | + <input class="field-input" type="number" name="quota_bytes" min="0" value=(listed.quota_bytes.to_string()) aria-label=(t(language, Key::QuotaBytes))> | |
| 290 | + <button type="submit">(t(language, Key::SetQuota))</button> | |
| 291 | + </form> | |
| 292 | + if listed.id != fresh.id { | |
| 293 | + <form class="pop-row-form" method="post" action="/api/settings/disable"> | |
| 294 | + <input type="hidden" name="user_id" value=(listed.id.clone())> | |
| 295 | + if listed.disabled { | |
| 296 | + <input type="hidden" name="disabled" value="0"> | |
| 297 | + <button type="submit">(t(language, Key::EnableUser))</button> | |
| 298 | + } else { | |
| 299 | + <input type="hidden" name="disabled" value="1"> | |
| 300 | + <button class="quiet-danger" type="submit">(t(language, Key::DisableUser))</button> | |
| 301 | + } | |
| 302 | + </form> | |
| 303 | + } | |
| 304 | + </td> | |
| 305 | + </tr> | |
| 306 | + } | |
| 307 | + </tbody> | |
| 308 | + </table> | |
| 309 | + </div> | |
| 310 | + </div> | |
| 311 | + </section> | |
| 312 | + } | |
| 313 | + </main> | |
| 314 | + </div> | |
| 315 | + (crate::dropdown::dropdown_script(cx).await?) | |
| 246 | 316 | } |
| 247 | 317 | } |
| 248 | 318 |
crates/in-web/tests/http.rsmodified+89 -0
| @@ -1896,3 +1896,92 @@ async fn a_refused_upload_carries_a_well_formed_query() { | ||
| 1896 | 1896 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 1897 | 1897 | assert!(page.text().contains("already taken"), "{}", page.text()); |
| 1898 | 1898 | } |
| 1899 | + | |
| 1900 | +// -- settings ui picker -------------------------------------------------------- | |
| 1901 | + | |
| 1902 | +#[tokio::test] | |
| 1903 | +async fn settings_ui_picker_round_trips() { | |
| 1904 | + let app = TestApp::build().await; | |
| 1905 | + let cookie = app.sign_in("sub-ui", "ui@in.test", "Ui").await; | |
| 1906 | + let me = owner_of(&app, "sub-ui").await; | |
| 1907 | + | |
| 1908 | + // The ledger is the default, worn on `<html>` from the first render. | |
| 1909 | + assert_eq!(app.store.user(&me).await.unwrap().unwrap().ui, "ledger"); | |
| 1910 | + let page = app.get("/settings", Some(&cookie)).await; | |
| 1911 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | |
| 1912 | + assert!(page.text().contains("data-ui=\"ledger\""), "{}", page.text()); | |
| 1913 | + | |
| 1914 | + // Picking the instrument writes the row and re-renders the chrome. | |
| 1915 | + let answer = app | |
| 1916 | + .post("/api/settings/ui", Some(&cookie), &[("ui", "instrument")]) | |
| 1917 | + .await; | |
| 1918 | + assert!(answer.accepted(), "ui refused: {:?}", answer.location); | |
| 1919 | + assert_eq!( | |
| 1920 | + app.store.user(&me).await.unwrap().unwrap().ui, | |
| 1921 | + "instrument" | |
| 1922 | + ); | |
| 1923 | + let page = app.get("/settings", Some(&cookie)).await; | |
| 1924 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | |
| 1925 | + assert!( | |
| 1926 | + page.text().contains("data-ui=\"instrument\""), | |
| 1927 | + "{}", | |
| 1928 | + page.text() | |
| 1929 | + ); | |
| 1930 | + assert!(page.text().contains("name=\"ui\""), "{}", page.text()); | |
| 1931 | + | |
| 1932 | + // And back again. | |
| 1933 | + let answer = app | |
| 1934 | + .post("/api/settings/ui", Some(&cookie), &[("ui", "ledger")]) | |
| 1935 | + .await; | |
| 1936 | + assert!(answer.accepted(), "ui refused: {:?}", answer.location); | |
| 1937 | + assert_eq!(app.store.user(&me).await.unwrap().unwrap().ui, "ledger"); | |
| 1938 | +} | |
| 1939 | + | |
| 1940 | +#[tokio::test] | |
| 1941 | +async fn settings_ui_rejects_unknown_values() { | |
| 1942 | + let app = TestApp::build().await; | |
| 1943 | + let cookie = app.sign_in("sub-ui-bad", "uibad@in.test", "UiBad").await; | |
| 1944 | + let me = owner_of(&app, "sub-ui-bad").await; | |
| 1945 | + | |
| 1946 | + let answer = app | |
| 1947 | + .post("/api/settings/ui", Some(&cookie), &[("ui", "mosaic")]) | |
| 1948 | + .await; | |
| 1949 | + assert!(answer.refused("bad-ui", "ui"), "{:?}", answer.location); | |
| 1950 | + assert_eq!(app.store.user(&me).await.unwrap().unwrap().ui, "ledger"); | |
| 1951 | + | |
| 1952 | + // The carried refusal renders under the picker form. | |
| 1953 | + let page = app | |
| 1954 | + .get(answer.location.as_deref().unwrap(), Some(&cookie)) | |
| 1955 | + .await; | |
| 1956 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | |
| 1957 | + assert!( | |
| 1958 | + page.text().contains("That interface choice is not offered."), | |
| 1959 | + "{}", | |
| 1960 | + page.text() | |
| 1961 | + ); | |
| 1962 | + | |
| 1963 | + // Signed out, the same post asks to sign in first. | |
| 1964 | + let answer = app | |
| 1965 | + .post("/api/settings/ui", None, &[("ui", "instrument")]) | |
| 1966 | + .await; | |
| 1967 | + assert!(answer.refused("sign-in-first", "ui"), "{:?}", answer.location); | |
| 1968 | +} | |
| 1969 | + | |
| 1970 | +#[tokio::test] | |
| 1971 | +async fn settings_panels_nest_inside_the_stage() { | |
| 1972 | + let app = TestApp::build().await; | |
| 1973 | + let admin = app.sign_in("sub-stage", "stage@in.test", "Stage").await; | |
| 1974 | + let page = app.get("/settings", Some(&admin)).await; | |
| 1975 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | |
| 1976 | + let body = page.text(); | |
| 1977 | + let stage = body | |
| 1978 | + .find("<main class=\"settings-stage\">") | |
| 1979 | + .expect("no settings-stage"); | |
| 1980 | + let close = body.find("</main>").expect("no main close"); | |
| 1981 | + for marker in ["panel-head", "member-table", "name=\"ui\""] { | |
| 1982 | + let at = body.find(marker).unwrap_or_else(|| panic!("no {marker}")); | |
| 1983 | + assert!(stage < at && at < close, "{marker} escapes the stage"); | |
| 1984 | + } | |
| 1985 | + // The admin register is a table now: one named column per fact. | |
| 1986 | + assert!(body.contains("<th class=\"member-col-name\""), "{body}"); | |
| 1987 | +} |
style/_instrument.scssmodified+5 -1
| @@ -16,8 +16,12 @@ | ||
| 16 | 16 | height: 44px; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | + // In's drive filterbar carries a full create-folder form (iz's only holds | |
| 20 | + // chips), so the skin's fixed 40px clips it: 40px is the floor, not the | |
| 21 | + // ceiling. | |
| 19 | 22 | .filterbar { |
| 20 | - height: 40px; | |
| 23 | + min-height: 40px; | |
| 24 | + height: auto; | |
| 21 | 25 | } |
| 22 | 26 | |
| 23 | 27 | // Active nav underlines in accent, not ink. |
style/main.scssmodified+20 -0
| @@ -732,6 +732,18 @@ a { | ||
| 732 | 732 | padding: 8px 24px; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | +// The drive page's create-folder form sits inside the filterbar, where the | |
| 736 | +// column form's stacking (gap, padding, top rule) would blow the 40px | |
| 737 | +// instrument bar apart and float oddly centred in ledger too: inline here, | |
| 738 | +// so the row fits the bar in both skins. | |
| 739 | +.filterbar .tag-form { | |
| 740 | + flex-direction: row; | |
| 741 | + align-items: center; | |
| 742 | + gap: 10px; | |
| 743 | + padding: 0; | |
| 744 | + border-top: none; | |
| 745 | +} | |
| 746 | + | |
| 735 | 747 | .segmented { |
| 736 | 748 | display: flex; |
| 737 | 749 | align-items: center; |
| @@ -3129,6 +3141,14 @@ img.avatar { | ||
| 3129 | 3141 | color: var(--muted-soft); |
| 3130 | 3142 | } |
| 3131 | 3143 | |
| 3144 | +// A read-only value under a field label — the profile's name, address and | |
| 3145 | +// quota line. Same type size as a field input, without the box: the label | |
| 3146 | +// above it is the structure, not a border. | |
| 3147 | +.field-static { | |
| 3148 | + font-size: 13px; | |
| 3149 | + color: var(--ink); | |
| 3150 | +} | |
| 3151 | + | |
| 3132 | 3152 | .auth-input, |
| 3133 | 3153 | .field-input { |
| 3134 | 3154 | height: 40px; |