From 45563b313231a8ae7d8ea9cef9c91eb07e0fb0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 5 Sep 2026 01:35:04 +0300 Subject: [PATCH] fix(ui): avatar resolves the OIDC sub; new-folder is a plus menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The avatar proxy fetched im's photo with in's local user id, but im keys photos by its own user id — the OIDC sub. Nobody's photo ever loaded; the rig missed it because the fake provider answered every path. The route now maps the local id to the sub, and the fake provider keys photos by sub so the regression stays pinned. The new-folder modal is gone. A single + button in the toolbar opens a small menu — New folder, Upload files — per the file-explorer convention: New folder creates "New folder" (collision-suffixed) immediately and lands on the row in rename mode, focused with the name selected; Upload files targets the same multi-select picker without script. The morph-safe focus rides in:wire like every other enhancement. --- crates/in-web/src/avatar.rs | 2 +- crates/in-web/src/drive.rs | 126 +++++++++++++++++++++++-------- crates/in-web/src/i18n.rs | 7 +- crates/in-web/tests/http.rs | 145 +++++++++++++++++++++++++++++------- style/main.scss | 16 +--- 5 files changed, 222 insertions(+), 74 deletions(-) diff --git a/crates/in-web/src/avatar.rs b/crates/in-web/src/avatar.rs index eaddb34..15515eb 100644 --- a/crates/in-web/src/avatar.rs +++ b/crates/in-web/src/avatar.rs @@ -35,7 +35,7 @@ async fn avatar(cx: &Cx) -> topcoat::Result<(StatusCode, HeaderMap, Vec)> { if target != user.id { return Ok(not_found()); } - let Some((bytes, mime)) = in_client::photo_for(cx, target).await else { + let Some((bytes, mime)) = in_client::photo_for(cx, &user.oidc_sub).await else { return Ok(not_found()); }; diff --git a/crates/in-web/src/drive.rs b/crates/in-web/src/drive.rs index c4ec3c8..a5ef415 100644 --- a/crates/in-web/src/drive.rs +++ b/crates/in-web/src/drive.rs @@ -60,6 +60,7 @@ const LIMIT: u32 = 50; struct DriveQuery { folder: Option, q: Option, + edit: Option, } /// The folder the query names, if it names one this account may open: owned, @@ -149,7 +150,7 @@ fn human_size(bytes: u64) -> String { } } fn page_refusal(cx: &Cx) -> Option { - ["rename", "move", "delete", "upload"] + ["create", "rename", "move", "delete", "upload"] .iter() .find_map(|call| refusal_of(cx, call)) } @@ -204,10 +205,9 @@ async fn drive(cx: &Cx) -> Result { }; let destinations = folder_tree(store.as_ref(), &user.id).await; let refusal = page_refusal(cx); - // The create-folder answer belongs to the modal, not the page line: a - // refused create reopens it with the sentence inside, iz's confirm idiom. - let create_refusal = refusal_of(cx, "create"); - let create_open = create_refusal.is_some(); + // Which folder row (if any) renders as its rename form: iz's `?edit=` + // idiom — a server-side row swap, no client state to hold. + let edit_id = params.as_ref().and_then(|query| query.edit.clone()); // A link minted from this surface redirects back here with the plaintext // token on `?created=` — rendered once, like the settings page does. let created = created_token(uri(cx).query().unwrap_or("")); @@ -221,6 +221,16 @@ async fn drive(cx: &Cx) -> Result { .as_ref() .map(|folder| folder.name.clone()) .unwrap_or_else(|| t(language, Key::Drive).to_string()); + // The folder view without `?edit=`: the rename form's cancel target and + // the base the edit links extend. + let here = if current_id.is_empty() { + "/drive".to_string() + } else { + format!("/drive?folder={current_id}") + }; + // `here` carries no query at the root, one under a folder — the edit + // links extend it with the matching separator. + let edit_sep = if current_id.is_empty() { "?" } else { "&" }; view! { cx => @@ -251,25 +261,14 @@ async fn drive(cx: &Cx) -> Result { aria-label=(t(language, Key::SearchPlaceholder)) > -
- "+ "(t(language, Key::NewFolder)) -
-
(t(language, Key::NewFolder))
-
+
+ "+ " +
+ - -
-
- -
- if let Some(refusal) = create_refusal { - - } + +
@@ -327,14 +326,20 @@ async fn drive(cx: &Cx) -> Result { } for folder in listing.folders.iter() {
+ if edit_id.as_deref() == Some(folder.id.as_str()) { +
+ + + + (t(language, Key::Cancel)) +
+ } else { (folder.name.clone())
-
- - - -
+ (t(language, Key::Rename))
+ }
} @@ -366,7 +372,7 @@ async fn drive(cx: &Cx) -> Result { (t(language, Key::DropFilesHere)) @@ -449,6 +455,11 @@ fn query_value(query: &str, key: &str) -> Option { /// alone — two uploaders racing the same bytes would double-insert, and the /// progress the soft-nav draws knows nothing of chunks. Without script the /// form posts plainly and the 303 lands back on the folder. +/// +/// The same block carries the `?edit=` row's focus: the rename input the +/// server renders open gets focused with its name selected on arrival, so a +/// quick-created folder is ready to name. Guarded lookups — most visits +/// render no such input. async fn upload_script(cx: &Cx) -> Result { use topcoat::view::Unescaped; const JS: &str = "\ @@ -541,6 +552,16 @@ async fn upload_script(cx: &Cx) -> Result { else { window.location.href = landing; } \ })(); \ }); \ + (function () { \ + if (window.__inEditFocus) { return; } \ + window.__inEditFocus = true; \ + function focusIt() { \ + var input = document.querySelector('input[data-edit-focus]'); \ + if (input && input.focus && input.select) { input.focus(); input.select(); } \ + } \ + focusIt(); \ + document.addEventListener('in:wire', focusIt); \ + })(); \ })();"; view! { cx => } } @@ -549,10 +570,18 @@ async fn upload_script(cx: &Cx) -> Result { struct CreateFolderForm { #[serde(default)] parent_id: String, + // Absent on the + menu's quick form, which posts no name at all: the + // empty read below takes the generic-name path instead of failing the + // post. + #[serde(default)] name: String, } /// `POST /api/folder/create`: one folder under the open one, or the root. +/// +/// A form with no name is the + menu's quick create: a generic unique name +/// (`New folder`, `New folder 2`, …) and a 303 straight into that row's +/// rename form. A typed name keeps the old answer — back to the page. #[route(POST "/api/folder/create")] async fn create_folder(cx: &Cx, Form(input): Form) -> Redirect { let user = match require_user(cx).await { @@ -571,12 +600,51 @@ async fn create_folder(cx: &Cx, Form(input): Form) -> Redirect _ => return redirect(cx, Some(Refusal::NotFound)), } } + if input.name.trim().is_empty() { + return quick_folder(cx, &store, &user.id, parent).await; + } match store.create_folder(&user.id, parent, &input.name).await { Ok(_) => redirect(cx, None), Err(error) => redirect(cx, Some(store_refusal(error))), } } +/// The + menu's quick create: the first free generic name, then a 303 to the +/// folder view with that row in its rename form. The loop is the +/// collision-suffixing (`New folder 2`, …), bounded so a pathological tree +/// answers unavailable instead of spinning. +async fn quick_folder( + cx: &Cx, + store: &std::sync::Arc, + owner_id: &str, + parent: Option<&str>, +) -> Redirect { + let base = t(lang(cx).await, Key::NewFolder).to_string(); + for attempt in 0..64u32 { + let name = if attempt == 0 { + base.clone() + } else { + format!("{} {}", base, attempt + 1) + }; + match store.create_folder(owner_id, parent, &name).await { + Ok(folder) => { + let location = match parent { + Some(parent) => format!("/drive?folder={parent}&edit={}", folder.id), + None => format!("/drive?edit={}", folder.id), + }; + return Ok(( + StatusCode::SEE_OTHER, + [(header::LOCATION, location)], + Json(None), + )); + } + Err(StoreError::NameTaken) => {} + Err(error) => return redirect(cx, Some(store_refusal(error))), + } + } + redirect(cx, Some(Refusal::Unavailable)) +} + #[derive(serde::Deserialize)] struct FolderIdForm { id: String, diff --git a/crates/in-web/src/i18n.rs b/crates/in-web/src/i18n.rs index d0eb7ab..08d9260 100644 --- a/crates/in-web/src/i18n.rs +++ b/crates/in-web/src/i18n.rs @@ -113,6 +113,7 @@ pub enum Key { // Upload. Upload, UploadFile, + UploadFiles, ChooseFiles, DropFilesHere, Uploading, @@ -210,9 +211,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { UserMenuLabel => "Account", Drive => "Drive", NewFolder => "New folder", - NewFolder => "New folder", FolderName => "Folder name", - NewFolder => "New folder", CreateFolder => "Create folder", RenameFolder => "Rename folder", MoveFolder => "Move folder", @@ -225,6 +224,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { ModifiedColumn => "Changed", Upload => "Upload", UploadFile => "Upload files", + UploadFiles => "Upload files", ChooseFiles => "Choose files", DropFilesHere => "Drop files here to upload them.", Uploading => "Uploading…", @@ -312,9 +312,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { UserMenuLabel => "Hesap", Drive => "Sürücü", NewFolder => "Yeni klasör", - NewFolder => "Yeni klasör", FolderName => "Klasör adı", - NewFolder => "Yeni klasör", CreateFolder => "Klasörü oluştur", RenameFolder => "Klasörü yeniden adlandır", MoveFolder => "Klasörü taşı", @@ -327,6 +325,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { ModifiedColumn => "Değişiklik", Upload => "Yükle", UploadFile => "Dosya yükle", + UploadFiles => "Dosya yükle", ChooseFiles => "Dosya seç", DropFilesHere => "Yüklemek için dosyaları buraya bırak.", Uploading => "Yükleniyor…", diff --git a/crates/in-web/tests/http.rs b/crates/in-web/tests/http.rs index b6cfe2d..6e59934 100644 --- a/crates/in-web/tests/http.rs +++ b/crates/in-web/tests/http.rs @@ -2488,7 +2488,7 @@ async fn avatar_serves_own_photo_with_etag() { let app = TestApp::build().await; let cookie = app.sign_in("sub-face", "face@in.test", "Face").await; let me = owner_of(&app, "sub-face").await; - app.fake.set_photo(&me, tiny_png(), "image/png"); + app.fake.set_photo("sub-face", tiny_png(), "image/png"); let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await; assert_eq!(face.status, StatusCode::OK); @@ -2535,7 +2535,7 @@ async fn avatar_for_someone_else_is_not_found() { let alice = app.sign_in("sub-alice-face", "alice@in.test", "Alice").await; let bob = app.sign_in("sub-bob-face", "bob@in.test", "Bob").await; let bob_id = owner_of(&app, "sub-bob-face").await; - app.fake.set_photo(&bob_id, tiny_png(), "image/png"); + app.fake.set_photo("sub-bob-face", tiny_png(), "image/png"); // Bob's face through Alice's session: the same 404 as no photo at all, // never a hint that Bob has one. @@ -2563,54 +2563,143 @@ async fn avatar_without_session_is_unauthorized() { } #[tokio::test] -async fn drive_new_folder_rides_a_confirm_modal() { +async fn avatar_resolves_local_id_to_oidc_sub() { + // im keys photos by the OIDC sub, while `/avatar/{id}` carries the + // local row id — the two are never equal (ULID vs `sub-*`), so a photo + // map keyed by the sub 404'd before the handler translated the id. let app = TestApp::build().await; - let cookie = app.sign_in("sub-newfolder", "newfolder@in.test", "NewFolder").await; + let cookie = app.sign_in("sub-looks", "looks@in.test", "Looks").await; + let me = owner_of(&app, "sub-looks").await; + assert_ne!(me, "sub-looks", "local id collides with the sub"); + app.fake.set_photo("sub-looks", tiny_png(), "image/png"); + + let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await; + assert_eq!(face.status, StatusCode::OK); + assert_eq!(face.bytes, tiny_png()); +} + +#[tokio::test] +async fn drive_add_menu_has_two_items() { + let app = TestApp::build().await; + let cookie = app.sign_in("sub-addmenu", "addmenu@in.test", "AddMenu").await; let page = app.get("/drive", Some(&cookie)).await; assert_eq!(page.status, StatusCode::OK); let body = page.text(); - // The filterbar carries the confirm modal, not the old disclosure box. - assert!(body.contains("confirm-details"), "no confirm modal on the drive"); - assert!(!body.contains("tag-new"), "old disclosure box still rendered"); - let details_at = body.find("confirm-details").expect("no confirm modal"); - let details_end = body[details_at..].find("
").expect("modal never closes"); + // The filterbar carries one + menu, not the old confirm modal. + assert!(!body.contains("confirm-details"), "confirm modal still rendered"); + assert!(!body.contains("new-folder-form"), "modal form still rendered"); + let details_at = body.find("drive-add").expect("no + menu on the drive"); + let details_end = body[details_at..].find("").expect("menu never closes"); let details = &body[details_at..details_at + details_end]; + // New folder: a button-only quick form posting just the parent. assert!( details.contains("action=\"/api/folder/create\""), - "create form escapes the modal: {details}" + "quick form escapes the menu: {details}" ); assert!(details.contains("name=\"parent_id\""), "no parent field: {details}"); - assert!(details.contains("name=\"name\""), "no name field: {details}"); - assert!(details.contains("Create folder"), "no submit: {details}"); + assert!(!details.contains("name=\"name\""), "quick form asks for a name: {details}"); + assert!(details.contains("New folder"), "no New folder item: {details}"); + // Upload files: a label for the panel's own picker, no script needed. + assert!( + details.contains("for=\"drive-upload-input\""), + "no upload label in the menu: {details}" + ); + assert!(details.contains("Upload files"), "no Upload files item: {details}"); + assert!( + body.contains("id=\"drive-upload-input\""), + "upload input carries no id for the label" + ); +} + +#[tokio::test] +async fn drive_quick_create_names_and_edits() { + let app = TestApp::build().await; + let cookie = app.sign_in("sub-quick", "quick@in.test", "Quick").await; + let me = owner_of(&app, "sub-quick").await; + + // The + menu posts no name: generic name, 303 into that row's edit mode. + let answer = app.post("/api/folder/create", Some(&cookie), &[("parent_id", "")]).await; + assert_eq!(answer.status, StatusCode::SEE_OTHER); + let location = answer.location.clone().expect("quick create redirects nowhere"); + assert!(location.starts_with("/drive?"), "quick create leaves the drive: {location}"); + assert!(location.contains("edit="), "quick create skips edit mode: {location}"); + let edit = location + .split("edit=") + .nth(1) + .expect("no edit id") + .split('&') + .next() + .unwrap(); + assert_eq!(folder_id(&app, &me, None, "New folder").await, edit); + + // A second quick create collision-suffixes instead of colliding. + let answer = app.post("/api/folder/create", Some(&cookie), &[("parent_id", "")]).await; + let location = answer.location.clone().expect("second quick create redirects nowhere"); + let edit = location + .split("edit=") + .nth(1) + .expect("no edit id") + .split('&') + .next() + .unwrap(); + assert_eq!(folder_id(&app, &me, None, "New folder 2").await, edit); - // Creating through the POST still lands. + // A typed name keeps the old answer: back to the page, no edit mode. let answer = app - .post("/api/folder/create", Some(&cookie), &[("parent_id", ""), ("name", "dup")]) + .post("/api/folder/create", Some(&cookie), &[("parent_id", ""), ("name", "typed")]) .await; - assert!(answer.accepted(), "clean create refused: {:?}", answer.location); + assert!(answer.accepted(), "typed create refused: {:?}", answer.location); + assert!( + answer.location.as_deref().is_some_and(|location| !location.contains("edit=")), + "typed create enters edit mode: {:?}", + answer.location + ); + folder_id(&app, &me, None, "typed").await; - // A refused create reopens the modal with the sentence inside — and only there. + // A refused typed create surfaces on the page line, once. let answer = app - .post("/api/folder/create", Some(&cookie), &[("parent_id", ""), ("name", "dup")]) + .post("/api/folder/create", Some(&cookie), &[("parent_id", ""), ("name", "typed")]) .await; assert_eq!(answer.status, StatusCode::SEE_OTHER); - assert!( - answer.body.contains("NameTaken"), - "dupe was not refused: {}", - answer.body - ); + assert!(answer.body.contains("NameTaken"), "dupe was not refused: {}", answer.body); let page = app.get("/drive?refusal=name-taken&on=create", Some(&cookie)).await; assert_eq!(page.status, StatusCode::OK); - let body = page.text(); - assert!( - body.contains("