forge
Explore
Log in

Don't you dare go Hollow

Avatar from im, new-folder rides the house modal

Browse files at this commit

b6f064c66ead0e9e3bfbdd05ab0434c2d55444a6Ahmet Kaan GümüşParent: 4283bb6
  • feat
    • avatar from im, new-folder rides the house modal
Show full message
feat(ui): avatar from im, new-folder rides the house modal

The user menu's avatar spot shows the real photo now: im's photo route
accepts registered-app credentials (im 569b89d), in proxies it through
GET /avatar/{id} (own id only, im's one-answer 404 discipline, fnv1a
ETag + immutable cache), and the initials block stays as the fallback
when im has no photo.

New folder stops being a bordered disclosure box in the toolbar: the
compact "+ New folder" summary opens iz's confirm-details idiom — a
scrimmed, centered modal with the labelled name field. A refused create
reopens the modal with the sentence inside; the POST route is
unchanged.
crates/in-client/src/lib.rsmodified+30 -0
@@ -117,6 +117,36 @@ pub async fn current_user(cx: &Cx) -> Option<User> {
117 }117 }
118 }118 }
119 119
120+/// The person's profile photo from im, if im has one. `None` on 404 and on
121+/// anything else that is not the bytes — a dropped connection, a body that
122+/// will not read, a reply without a mime — because a missing face must never
123+/// fail the page around it: the caller renders its initials instead.
124+///
125+/// Authenticated as the app, not the browser: `Authorization: Basic
126+/// base64(client_id ":" client_secret)` against im's `/photo/{user_id}`,
127+/// the same credentials the introspection round-trip posts with.
128+pub async fn photo_for(cx: &Cx, user_id: &str) -> Option<(Vec<u8>, String)> {
129+ let state = client(cx);
130+ let reply = state
131+ .http
132+ .get(format!("{}/photo/{user_id}", state.config.issuer))
133+ .basic_auth(&state.config.client_id, Some(&state.config.client_secret))
134+ .send()
135+ .await
136+ .ok()?;
137+ if !reply.status().is_success() {
138+ return None;
139+ }
140+ let mime = reply
141+ .headers()
142+ .get(reqwest::header::CONTENT_TYPE)?
143+ .to_str()
144+ .ok()?
145+ .to_string();
146+ let bytes = reply.bytes().await.ok()?.to_vec();
147+ Some((bytes, mime))
148+}
149+
120 /// Path of im's RFC 7662 introspection endpoint, relative to the issuer.150 /// Path of im's RFC 7662 introspection endpoint, relative to the issuer.
121 const INTROSPECT_PATH: &str = "/introspect";151 const INTROSPECT_PATH: &str = "/introspect";
122 152
crates/in-web/src/avatar.rsadded+69 -0
@@ -0,0 +1,69 @@
1+//! The signed-in person's face, proxied from im.
2+//!
3+//! `GET /avatar/{user_id}` answers with im's photo bytes for the caller's own
4+//! id — anything else (another id, no photo, im unreachable) is the same 404,
5+//! and a browser without a session is refused outright. Served with the same
6+//! fnv1a ETag + immutable cache as im's own photo route, so the topbar's
7+//! `<img>` revalidates rather than refetches.
8+
9+use topcoat::context::Cx;
10+use topcoat::router::request::headers as request_headers;
11+use topcoat::router::{HeaderMap, HeaderValue, StatusCode, header, path_param, route};
12+use crate::server::require_user;
13+
14+path_param!(user_id);
15+
16+fn not_found() -> (StatusCode, HeaderMap, Vec<u8>) {
17+ (StatusCode::NOT_FOUND, HeaderMap::new(), Vec::new())
18+}
19+
20+/// `GET /avatar/{user_id}`: im's photo for the caller, or the same not-found
21+/// a stranger would see — never a `403`, which would confirm the id belongs
22+/// to somebody else's account.
23+#[route(GET "/avatar/{user_id}")]
24+async fn avatar(cx: &Cx) -> topcoat::Result<(StatusCode, HeaderMap, Vec<u8>)> {
25+ let target: &str = path_param::<UserId>(cx);
26+
27+ let user = match require_user(cx).await {
28+ Ok(user) => user,
29+ // An `<img>` has no page to carry a refusal on; 401 names the fix
30+ // the way the live channel's does.
31+ Err(_) => return Ok((StatusCode::UNAUTHORIZED, HeaderMap::new(), Vec::new())),
32+ };
33+ // v1: one's own face only — anyone else's id reads exactly like no
34+ // photo, so one account's face can never be probed through another's.
35+ if target != user.id {
36+ return Ok(not_found());
37+ }
38+ let Some((bytes, mime)) = in_client::photo_for(cx, target).await else {
39+ return Ok(not_found());
40+ };
41+
42+ let etag = format!("\"{:x}\"", crate::files::fnv1a(&bytes));
43+ let mut headers = HeaderMap::new();
44+ headers.insert(
45+ header::ETAG,
46+ HeaderValue::from_str(&etag).unwrap_or(HeaderValue::from_static("\"0\"")),
47+ );
48+ // The bytes are im's to version and this URL carries no stamp of its
49+ // own, so a changed photo may take up to a year to show — the price of
50+ // proxying without a stamp channel, and the same trade the thumbnail
51+ // route already makes. `private` because the route is gated and a shared
52+ // proxy must not answer a stranger from another account's entry.
53+ headers.insert(
54+ header::CACHE_CONTROL,
55+ HeaderValue::from_static("private, max-age=31536000, immutable"),
56+ );
57+ headers.insert(
58+ header::CONTENT_TYPE,
59+ HeaderValue::from_str(&mime).unwrap_or(HeaderValue::from_static("application/octet-stream")),
60+ );
61+
62+ let if_none_match = request_headers(cx)
63+ .get(header::IF_NONE_MATCH)
64+ .and_then(|value| value.to_str().ok());
65+ if if_none_match == Some(etag.as_str()) {
66+ return Ok((StatusCode::NOT_MODIFIED, headers, Vec::new()));
67+ }
68+ Ok((StatusCode::OK, headers, bytes))
69+}
crates/in-web/src/drive.rsmodified+25 -9
@@ -149,7 +149,7 @@ fn human_size(bytes: u64) -> String {
149 }149 }
150 }150 }
151 fn page_refusal(cx: &Cx) -> Option<Refusal> {151 fn page_refusal(cx: &Cx) -> Option<Refusal> {
152- ["create", "rename", "move", "delete", "upload"]152+ ["rename", "move", "delete", "upload"]
153 .iter()153 .iter()
154 .find_map(|call| refusal_of(cx, call))154 .find_map(|call| refusal_of(cx, call))
155 }155 }
@@ -204,6 +204,10 @@ async fn drive(cx: &Cx) -> Result {
204 };204 };
205 let destinations = folder_tree(store.as_ref(), &user.id).await;205 let destinations = folder_tree(store.as_ref(), &user.id).await;
206 let refusal = page_refusal(cx);206 let refusal = page_refusal(cx);
207+ // The create-folder answer belongs to the modal, not the page line: a
208+ // refused create reopens it with the sentence inside, iz's confirm idiom.
209+ let create_refusal = refusal_of(cx, "create");
210+ let create_open = create_refusal.is_some();
207 // A link minted from this surface redirects back here with the plaintext211 // A link minted from this surface redirects back here with the plaintext
208 // token on `?created=` — rendered once, like the settings page does.212 // token on `?created=` — rendered once, like the settings page does.
209 let created = created_token(uri(cx).query().unwrap_or(""));213 let created = created_token(uri(cx).query().unwrap_or(""));
@@ -247,14 +251,26 @@ async fn drive(cx: &Cx) -> Result {
247 aria-label=(t(language, Key::SearchPlaceholder))251 aria-label=(t(language, Key::SearchPlaceholder))
248 >252 >
249 </form>253 </form>
250- <details class="tag-new">254+ <details class="confirm-details" open=(create_open)>
251- <summary class="tag-new-open">(t(language, Key::NewFolder))</summary>255+ <summary class="quiet new-folder-open">"+ "(t(language, Key::NewFolder))</summary>
252- <form class="tag-form" method="post" action="/api/folder/create">256+ <div class="confirm">
253- <input type="hidden" name="parent_id" value=(current_id.clone())>257+ <div class="confirm-title">(t(language, Key::NewFolder))</div>
254- <input class="field-input" type="text" name="name" maxlength="255"258+ <form class="new-folder-form" method="post" action="/api/folder/create">
255- placeholder=(t(language, Key::FolderName)) required="" aria-label=(t(language, Key::FolderName))>259+ <input type="hidden" name="parent_id" value=(current_id.clone())>
256- <button class="primary" type="submit">(t(language, Key::CreateFolder))</button>260+ <label class="field">
257- </form>261+ <span class="field-label">(t(language, Key::FolderName))</span>
262+ <input class="field-input" type="text" name="name" maxlength="255"
263+ required="" aria-label=(t(language, Key::FolderName))>
264+ </label>
265+ <div class="confirm-row">
266+ <div class="spacer"></div>
267+ <button class="primary" type="submit">(t(language, Key::CreateFolder))</button>
268+ </div>
269+ if let Some(refusal) = create_refusal {
270+ <p class="field-error" role="alert">(refusal.message_in(language))</p>
271+ }
272+ </form>
273+ </div>
258 </details>274 </details>
259 </div>275 </div>
260 if let Some(refusal) = refusal {276 if let Some(refusal) = refusal {
crates/in-web/src/layout.rsmodified+40 -3
@@ -75,8 +75,12 @@ pub(crate) async fn wordmark(cx: &Cx) -> Result {
75 }75 }
76 76
77 /// A person as a circle (or, on the Instrument skin, a square): the initials,77 /// A person as a circle (or, on the Instrument skin, a square): the initials,
78-/// toned by the id so every account has its own colour. Shared by the78+/// toned by the id so every account has its own colour, with the im photo
79-/// topbar user menu on every signed-in page.79+/// over it when im has one. Whether im has one is not known cheaply — the
80+/// photo is the app's credentialed fetch, not the browser's — so the `<img>`
81+/// always renders and hides itself on error (see `avatar_script`), leaving
82+/// the initials beneath as the fallback. Shared by the topbar user menu on
83+/// every signed-in page.
80 pub(crate) async fn avatar(cx: &Cx, user: &User, extra: &str) -> Result {84 pub(crate) async fn avatar(cx: &Cx, user: &User, extra: &str) -> Result {
81 let tone = user85 let tone = user
82 .id86 .id
@@ -86,12 +90,44 @@ pub(crate) async fn avatar(cx: &Cx, user: &User, extra: &str) -> Result {
86 let class = format!("avatar avatar-tone-{tone} {extra}");90 let class = format!("avatar avatar-tone-{tone} {extra}");
87 let name = user.display_name.clone();91 let name = user.display_name.clone();
88 let initials = initials_of(&user.display_name);92 let initials = initials_of(&user.display_name);
93+ let src = format!("/avatar/{}", user.id);
89 view! {94 view! {
90 cx =>95 cx =>
91- <span class=(class) data-name=(name)>(initials)</span>96+ <span class="avatar-stack">
97+ <span class=(class.clone()) data-name=(name.clone())>(initials)</span>
98+ <img class=(format!("{class} avatar-photo")) src=(src) alt="" data-name=(name)>
99+ </span>
92 }100 }
93 }101 }
94 102
103+/// The photo half's client half: a missing photo must fall back to the
104+/// initials beneath it, and a bare `<img>` to a 404 shows the broken-image
105+/// box instead. One document-level capture `error` listener hides every
106+/// `img.avatar-photo` that fails, plus a sweep for the ones already failed
107+/// before it ran; hiding is registered through `__inOwn` so the live morph
108+/// — which owns no names, only what the client declares — does not strip it
109+/// back off on the next refresh.
110+pub async fn avatar_script(cx: &Cx) -> Result {
111+ use topcoat::view::Unescaped;
112+ const JS: &str = "\
113+ (function () { \
114+ if (window.__inAvatar) { return; } \
115+ window.__inAvatar = true; \
116+ function hide(img) { \
117+ if (window.__inOwn) { window.__inOwn(img, [], ['style']); } \
118+ img.style.display = 'none'; \
119+ } \
120+ document.addEventListener('error', function (e) { \
121+ var img = e.target && e.target.closest ? e.target.closest('img.avatar-photo') : null; \
122+ if (img) { hide(img); } \
123+ }, true); \
124+ document.querySelectorAll('img.avatar-photo').forEach(function (img) { \
125+ if (img.complete && img.naturalWidth === 0) { hide(img); } \
126+ }); \
127+ })();";
128+ view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
129+}
130+
95 /// The first letters of the first two words, uppercased — "Ada Lovelace"131 /// The first letters of the first two words, uppercased — "Ada Lovelace"
96 /// wears "AL", a bare address wears its first letter.132 /// wears "AL", a bare address wears its first letter.
97 fn initials_of(name: &str) -> String {133 fn initials_of(name: &str) -> String {
@@ -195,6 +231,7 @@ pub async fn topbar(cx: &Cx, active: NavPage, user: &User, lang: Lang) -> Result
195 (topbar_nav(cx, active, lang).await?)231 (topbar_nav(cx, active, lang).await?)
196 (user_menu(cx, user, lang).await?)232 (user_menu(cx, user, lang).await?)
197 </header>233 </header>
234+ (avatar_script(cx).await?)
198 }235 }
199 }236 }
200 237
crates/in-web/src/lib.rsmodified+1 -0
@@ -3,6 +3,7 @@
3 // first overflow.3 // first overflow.
4 #![recursion_limit = "256"]4 #![recursion_limit = "256"]
5 5
6+pub mod avatar;
6 pub mod drive;7 pub mod drive;
7 pub mod dropdown;8 pub mod dropdown;
8 pub mod files;9 pub mod files;
crates/in-web/tests/http.rsmodified+202 -9
@@ -41,6 +41,7 @@ fn asset_dir() -> PathBuf {
41 struct FakeIm {41 struct FakeIm {
42 addr: std::net::SocketAddr,42 addr: std::net::SocketAddr,
43 tokens: Arc<Mutex<HashMap<String, serde_json::Value>>>,43 tokens: Arc<Mutex<HashMap<String, serde_json::Value>>>,
44+ photos: Arc<Mutex<HashMap<String, (Vec<u8>, String)>>>,
44 }45 }
45 46
46 impl FakeIm {47 impl FakeIm {
@@ -49,13 +50,17 @@ impl FakeIm {
49 let addr = listener.local_addr().unwrap();50 let addr = listener.local_addr().unwrap();
50 let tokens: Arc<Mutex<HashMap<String, serde_json::Value>>> =51 let tokens: Arc<Mutex<HashMap<String, serde_json::Value>>> =
51 Arc::new(Mutex::new(HashMap::new()));52 Arc::new(Mutex::new(HashMap::new()));
53+ let photos: Arc<Mutex<HashMap<String, (Vec<u8>, String)>>> =
54+ Arc::new(Mutex::new(HashMap::new()));
52 let map = tokens.clone();55 let map = tokens.clone();
56+ let pmap = photos.clone();
53 tokio::spawn(async move {57 tokio::spawn(async move {
54 loop {58 loop {
55 let Ok((socket, _)) = listener.accept().await else {59 let Ok((socket, _)) = listener.accept().await else {
56 return;60 return;
57 };61 };
58 let map = map.clone();62 let map = map.clone();
63+ let pmap = pmap.clone();
59 tokio::spawn(async move {64 tokio::spawn(async move {
60 use tokio::io::{AsyncReadExt, AsyncWriteExt};65 use tokio::io::{AsyncReadExt, AsyncWriteExt};
61 let mut socket = socket;66 let mut socket = socket;
@@ -92,10 +97,22 @@ impl FakeIm {
92 let len = content_length(&head);97 let len = content_length(&head);
93 let body: Vec<u8> = req[body_start..body_start + len].to_vec();98 let body: Vec<u8> = req[body_start..body_start + len].to_vec();
94 req.drain(..body_start + len);99 req.drain(..body_start + len);
95- let answer = answer_for(&map, &first, &body);100+ let (status, content_type, payload) = match photo_answer(&pmap, &head, &first) {
96- let payload = serde_json::to_vec(&answer).unwrap();101+ Some(photo) => photo,
102+ None => match answer_for(&map, &first, &body) {
103+ Some(answer) => (
104+ "200 OK",
105+ "application/json".to_string(),
106+ serde_json::to_vec(&answer).unwrap(),
107+ ),
108+ // Anything but the introspection route is
109+ // nothing at all, the way the real im 404s
110+ // unknown paths rather than answering them.
111+ None => ("404 Not Found", "text/plain".to_string(), Vec::new()),
112+ },
113+ };
97 let response = format!(114 let response = format!(
98- "HTTP/1.1 200 OK\r\ncontent-type: application/json\r\ncontent-length: {}\r\n\r\n",115+ "HTTP/1.1 {status}\r\ncontent-type: {content_type}\r\ncontent-length: {}\r\n\r\n",
99 payload.len()116 payload.len()
100 );117 );
101 if socket.write_all(response.as_bytes()).await.is_err() {118 if socket.write_all(response.as_bytes()).await.is_err() {
@@ -108,12 +125,57 @@ impl FakeIm {
108 });125 });
109 }126 }
110 });127 });
111- Self { addr, tokens }128+ Self { addr, tokens, photos }
112 }129 }
113 130
114 fn url(&self) -> String {131 fn url(&self) -> String {
115 format!("http://{}", self.addr)132 format!("http://{}", self.addr)
116 }133 }
134+
135+ /// Stores the photo `GET /photo/{user_id}` answers with — the bytes and
136+ /// the mime im would serve for this account.
137+ fn set_photo(&self, user_id: &str, bytes: Vec<u8>, mime: &str) {
138+ self.photos
139+ .lock()
140+ .unwrap()
141+ .insert(user_id.to_string(), (bytes, mime.to_string()));
142+ }
143+}
144+
145+/// The Basic credential the app presents for `GET /photo/*`: `in-test:s3cr3t`.
146+const PHOTO_BASIC: &str = "Basic aW4tdGVzdDpzM2NyM3Q=";
147+
148+/// Answers `GET /photo/{id}` from the photo map — the app's Basic credential
149+/// or nothing, a missing photo exactly like a missing person. `None` for
150+/// anything else, which stays the introspection JSON.
151+fn photo_answer(
152+ photos: &Arc<Mutex<HashMap<String, (Vec<u8>, String)>>>,
153+ head: &str,
154+ request_line: &str,
155+) -> Option<(&'static str, String, Vec<u8>)> {
156+ let mut parts = request_line.split_whitespace();
157+ if parts.next() != Some("GET") {
158+ return None;
159+ }
160+ let target = parts.next().unwrap_or("");
161+ let path = target.split_once('?').map(|(path, _)| path).unwrap_or(target);
162+ let id = path.strip_prefix("/photo/")?;
163+ if id.is_empty() || id.contains('/') {
164+ return None;
165+ }
166+ let authed = head
167+ .lines()
168+ .filter_map(|line| line.split_once(':'))
169+ .any(|(name, value)| {
170+ name.trim().eq_ignore_ascii_case("authorization") && value.trim() == PHOTO_BASIC
171+ });
172+ if !authed {
173+ return Some(("404 Not Found", "text/plain".to_string(), Vec::new()));
174+ }
175+ match photos.lock().unwrap().get(id) {
176+ Some((bytes, mime)) => Some(("200 OK", mime.clone(), bytes.clone())),
177+ None => Some(("404 Not Found", "text/plain".to_string(), Vec::new())),
178+ }
117 }179 }
118 180
119 fn headers_end(req: &[u8]) -> Option<usize> {181 fn headers_end(req: &[u8]) -> Option<usize> {
@@ -150,16 +212,15 @@ fn decode(raw: &str) -> String {
150 }212 }
151 out213 out
152 }214 }
153-
154 fn answer_for(215 fn answer_for(
155 map: &Arc<Mutex<HashMap<String, serde_json::Value>>>,216 map: &Arc<Mutex<HashMap<String, serde_json::Value>>>,
156 request_line: &str,217 request_line: &str,
157 body: &[u8],218 body: &[u8],
158-) -> serde_json::Value {219+) -> Option<serde_json::Value> {
159 let mut head = request_line.split_whitespace();220 let mut head = request_line.split_whitespace();
160 let is_introspect = head.next() == Some("POST") && head.next() == Some(in_client::introspect_path());221 let is_introspect = head.next() == Some("POST") && head.next() == Some(in_client::introspect_path());
161 if !is_introspect {222 if !is_introspect {
162- return serde_json::json!({"active": false});223+ return None;
163 }224 }
164 let text = String::from_utf8_lossy(body).to_string();225 let text = String::from_utf8_lossy(body).to_string();
165 let token = text226 let token = text
@@ -168,8 +229,8 @@ fn answer_for(
168 .find(|(name, _)| *name == "token")229 .find(|(name, _)| *name == "token")
169 .map(|(_, value)| decode(value));230 .map(|(_, value)| decode(value));
170 match token.and_then(|token| map.lock().unwrap().get(&token).cloned()) {231 match token.and_then(|token| map.lock().unwrap().get(&token).cloned()) {
171- Some(claims) => claims,232+ Some(claims) => Some(claims),
172- None => serde_json::json!({"active": false}),233+ None => Some(serde_json::json!({"active": false})),
173 }234 }
174 }235 }
175 236
@@ -2421,3 +2482,135 @@ async fn settings_lives_in_the_user_menu_not_the_topbar() {
2421 let issuer = format!("href=\"{}/\"", app.config.oidc.issuer);2482 let issuer = format!("href=\"{}/\"", app.config.oidc.issuer);
2422 assert!(menu.contains(&issuer), "no profile link to the issuer: {menu}");2483 assert!(menu.contains(&issuer), "no profile link to the issuer: {menu}");
2423 }2484 }
2485+
2486+#[tokio::test]
2487+async fn avatar_serves_own_photo_with_etag() {
2488+ let app = TestApp::build().await;
2489+ let cookie = app.sign_in("sub-face", "face@in.test", "Face").await;
2490+ let me = owner_of(&app, "sub-face").await;
2491+ app.fake.set_photo(&me, tiny_png(), "image/png");
2492+
2493+ let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await;
2494+ assert_eq!(face.status, StatusCode::OK);
2495+ assert_eq!(face.content_type.as_deref(), Some("image/png"));
2496+ assert_eq!(
2497+ face.cache_control.as_deref(),
2498+ Some("private, max-age=31536000, immutable")
2499+ );
2500+ assert_eq!(face.bytes, tiny_png());
2501+
2502+ let etag = face.etag.clone().expect("no etag on the avatar");
2503+ let cached = app
2504+ .get_with_if_none_match(&format!("/avatar/{me}"), Some(&cookie), &etag)
2505+ .await;
2506+ assert_eq!(cached.status, StatusCode::NOT_MODIFIED);
2507+ assert!(cached.bytes.is_empty());
2508+
2509+ // The user menu wears the photo over the initials, with the fallback script.
2510+ let page = app.get("/drive", Some(&cookie)).await;
2511+ assert_eq!(page.status, StatusCode::OK);
2512+ let body = page.text();
2513+ assert!(
2514+ body.contains(&format!("src=\"/avatar/{me}\"")),
2515+ "menu wears no photo img"
2516+ );
2517+ assert!(body.contains("avatar-stack"), "no initials stack under the photo");
2518+ assert!(body.contains("__inAvatar"), "no avatar fallback script");
2519+}
2520+
2521+#[tokio::test]
2522+async fn avatar_without_photo_is_not_found() {
2523+ let app = TestApp::build().await;
2524+ let cookie = app.sign_in("sub-noface", "noface@in.test", "NoFace").await;
2525+ let me = owner_of(&app, "sub-noface").await;
2526+
2527+ let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await;
2528+ assert_eq!(face.status, StatusCode::NOT_FOUND);
2529+ assert!(face.bytes.is_empty());
2530+}
2531+
2532+#[tokio::test]
2533+async fn avatar_for_someone_else_is_not_found() {
2534+ let app = TestApp::build().await;
2535+ let alice = app.sign_in("sub-alice-face", "alice@in.test", "Alice").await;
2536+ let bob = app.sign_in("sub-bob-face", "bob@in.test", "Bob").await;
2537+ let bob_id = owner_of(&app, "sub-bob-face").await;
2538+ app.fake.set_photo(&bob_id, tiny_png(), "image/png");
2539+
2540+ // Bob's face through Alice's session: the same 404 as no photo at all,
2541+ // never a hint that Bob has one.
2542+ let face = app.get(&format!("/avatar/{bob_id}"), Some(&alice)).await;
2543+ assert_eq!(face.status, StatusCode::NOT_FOUND);
2544+ assert!(face.bytes.is_empty());
2545+
2546+ // And an id that names nobody at all.
2547+ let ghost = app
2548+ .get("/avatar/00000000000000000000000000", Some(&alice))
2549+ .await;
2550+ assert_eq!(ghost.status, StatusCode::NOT_FOUND);
2551+
2552+ // Bob himself still sees his own.
2553+ let own = app.get(&format!("/avatar/{bob_id}"), Some(&bob)).await;
2554+ assert_eq!(own.status, StatusCode::OK);
2555+ assert_eq!(own.bytes, tiny_png());
2556+}
2557+
2558+#[tokio::test]
2559+async fn avatar_without_session_is_unauthorized() {
2560+ let app = TestApp::build().await;
2561+ let face = app.get("/avatar/anyone", None).await;
2562+ assert_eq!(face.status, StatusCode::UNAUTHORIZED);
2563+}
2564+
2565+#[tokio::test]
2566+async fn drive_new_folder_rides_a_confirm_modal() {
2567+ let app = TestApp::build().await;
2568+ let cookie = app.sign_in("sub-newfolder", "newfolder@in.test", "NewFolder").await;
2569+
2570+ let page = app.get("/drive", Some(&cookie)).await;
2571+ assert_eq!(page.status, StatusCode::OK);
2572+ let body = page.text();
2573+
2574+ // The filterbar carries the confirm modal, not the old disclosure box.
2575+ assert!(body.contains("confirm-details"), "no confirm modal on the drive");
2576+ assert!(!body.contains("tag-new"), "old disclosure box still rendered");
2577+ let details_at = body.find("confirm-details").expect("no confirm modal");
2578+ let details_end = body[details_at..].find("</details>").expect("modal never closes");
2579+ let details = &body[details_at..details_at + details_end];
2580+ assert!(
2581+ details.contains("action=\"/api/folder/create\""),
2582+ "create form escapes the modal: {details}"
2583+ );
2584+ assert!(details.contains("name=\"parent_id\""), "no parent field: {details}");
2585+ assert!(details.contains("name=\"name\""), "no name field: {details}");
2586+ assert!(details.contains("Create folder"), "no submit: {details}");
2587+
2588+ // Creating through the POST still lands.
2589+ let answer = app
2590+ .post("/api/folder/create", Some(&cookie), &[("parent_id", ""), ("name", "dup")])
2591+ .await;
2592+ assert!(answer.accepted(), "clean create refused: {:?}", answer.location);
2593+
2594+ // A refused create reopens the modal with the sentence inside — and only there.
2595+ let answer = app
2596+ .post("/api/folder/create", Some(&cookie), &[("parent_id", ""), ("name", "dup")])
2597+ .await;
2598+ assert_eq!(answer.status, StatusCode::SEE_OTHER);
2599+ assert!(
2600+ answer.body.contains("NameTaken"),
2601+ "dupe was not refused: {}",
2602+ answer.body
2603+ );
2604+ let page = app.get("/drive?refusal=name-taken&on=create", Some(&cookie)).await;
2605+ assert_eq!(page.status, StatusCode::OK);
2606+ let body = page.text();
2607+ assert!(
2608+ body.contains("<details class=\"confirm-details\" open"),
2609+ "refused create left the modal shut"
2610+ );
2611+ assert_eq!(
2612+ body.matches("<p class=\"field-error\"").count(),
2613+ 1,
2614+ "create refusal shows twice — or nowhere"
2615+ );
2616+}
style/main.scssmodified+29 -0
@@ -743,6 +743,22 @@ a {
743 padding: 0;743 padding: 0;
744 border-top: none;744 border-top: none;
745 }745 }
746+// The filterbar's new-folder trigger wears the quiet button skin; the
747+// disclosure marker stays hidden, the '+' is literal text. The open panel
748+// is the shared `.confirm` modal — no bar-local rules, so opening it never
749+// reflows the bar the way the old disclosure box did.
750+.new-folder-open {
751+ list-style: none;
752+
753+ &::marker, &::-webkit-details-marker { display: none; }
754+}
755+
756+.new-folder-form {
757+ display: flex;
758+ flex-direction: column;
759+ gap: 12px;
760+ margin-top: 8px;
761+}
746 762
747 .segmented {763 .segmented {
748 display: flex;764 display: flex;
@@ -1066,6 +1082,19 @@ img.avatar {
1066 display: block;1082 display: block;
1067 }1083 }
1068 1084
1085+// The topbar face: the initials block stays beneath and the photo, when im
1086+// has one, covers it — a missing photo hides itself (see `avatar_script` in
1087+// `layout.rs`) and the initials show through. One grid cell shared by both,
1088+// so no absolute positioning and no second copy of the avatar's size; the
1089+// overlap rule for grouped faces is unwound here, where the pair is one face.
1090+.avatar-stack {
1091+ display: inline-grid;
1092+ flex: none;
1093+
1094+ > * { grid-area: 1 / 1; }
1095+ > .avatar + .avatar { margin-left: 0; }
1096+}
1097+
1069 // The avatar leads the profile panel. Without a photo it is itself the1098 // The avatar leads the profile panel. Without a photo it is itself the
1070 // upload control — the file input rides its `form` attribute to a hidden1099 // upload control — the file input rides its `form` attribute to a hidden
1071 // sibling form, so nothing nests inside the profile form. With one, the1100 // sibling form, so nothing nests inside the profile form. With one, the