forge
Explore
Log in

Don't you dare go Hollow

The avatar fallback script rides with the topbar menu: only people and settings emitted it, so every other page's faces — board cards, the task modal, the topbar itself — showed the broken-image box where a photo 404s instead of the initials beneath; user_menu is on every signed-in page, so emitting there covers them all, and a board test pins avatars-never-render-without-the-script

Browse files at this commit

8eb21374d8ca6ebaace21a1da5b62f12fb1e2259Ahmet Kaan GümüşParent: 4164a6c
crates/iz-web/src/layout.rsmodified+4 -1
@@ -136,7 +136,9 @@ pub(crate) async fn avatar_script(cx: &Cx) -> Result {
136 136
137 /// The topbar's signed-in identity: the display name, opening on hover or137 /// The topbar's signed-in identity: the display name, opening on hover or
138 /// focus onto details (name, address, role) and sign-out. Shared by every138 /// focus onto details (name, address, role) and sign-out. Shared by every
139-/// signed-in page's topbar.139+/// signed-in page's topbar — which is why `avatar_script` rides along here:
140+/// every page with avatars has this menu, and the script's guard makes the
141+/// one emission enough no matter how many avatars the page carries.
140 pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result {142 pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result {
141 let role_key = match me.role {143 let role_key = match me.role {
142 iz_core::Role::Admin => Key::RoleAdminOption,144 iz_core::Role::Admin => Key::RoleAdminOption,
@@ -159,6 +161,7 @@ pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result {
159 <a class="user-menu-item" href="/auth/logout" data-hard="">(t(lang, Key::SignOut))</a>161 <a class="user-menu-item" href="/auth/logout" data-hard="">(t(lang, Key::SignOut))</a>
160 </div>162 </div>
161 </div>163 </div>
164+ (avatar_script(cx).await?)
162 }165 }
163 }166 }
164 167
crates/iz-web/src/people.rsmodified+0 -1
@@ -198,6 +198,5 @@ async fn people_page(cx: &Cx) -> Result {
198 198
199 (crate::layout::escape_script(cx).await?)199 (crate::layout::escape_script(cx).await?)
200 (crate::detail::escape_closes(cx).await?)200 (crate::detail::escape_closes(cx).await?)
201- (crate::layout::avatar_script(cx).await?)
202 }201 }
203 }202 }
crates/iz-web/src/settings.rsmodified+0 -1
@@ -1647,6 +1647,5 @@ async fn settings_page(cx: &Cx) -> Result {
1647 (crate::dropdown::dropdown_script(cx).await?)1647 (crate::dropdown::dropdown_script(cx).await?)
1648 (crate::layout::escape_script(cx).await?)1648 (crate::layout::escape_script(cx).await?)
1649 (crate::detail::escape_closes(cx).await?)1649 (crate::detail::escape_closes(cx).await?)
1650- (crate::layout::avatar_script(cx).await?)
1651 }1650 }
1652 }1651 }
crates/iz-web/tests/http.rsmodified+88 -0
@@ -3668,6 +3668,72 @@ async fn the_viewer_renders_in_page_for_a_renderable_file_and_ignores_a_foreign_
3668 assert!(!String::from_utf8_lossy(&missing_page.bytes).contains("viewer-body"));3668 assert!(!String::from_utf8_lossy(&missing_page.bytes).contains("viewer-body"));
3669 }3669 }
3670 3670
3671+/// The PDF reader is the one viewer with a presentation mode: its overlay
3672+/// carries the Present control and the delegated listener that answers it,
3673+/// while an image's overlay carries neither.
3674+#[tokio::test]
3675+async fn the_pdf_viewer_offers_presentation_mode_and_other_viewers_do_not() {
3676+ let app = App::open().await;
3677+ let admin_cookie = admin(&app).await;
3678+ let column = first_column(&app).await;
3679+ let task = a_task(&app, &admin_cookie, &column, "Present me").await;
3680+
3681+ let pdf = b"%PDF-1.4 nothing to see".to_vec();
3682+ app.post_multipart(
3683+ "/files",
3684+ Some(&admin_cookie),
3685+ &[("task_id", &task)],
3686+ Some(("deck.pdf", "application/pdf", &pdf)),
3687+ )
3688+ .await;
3689+ let snapshot = app
3690+ .post(
3691+ "/api/fetch_task",
3692+ Some(&admin_cookie),
3693+ &[("task_id", &task)],
3694+ )
3695+ .await;
3696+ let pdf_id = attachment_id_named(&snapshot.body, "deck.pdf");
3697+
3698+ let page = app
3699+ .get(&format!("/?task={task}&file={pdf_id}"), Some(&admin_cookie))
3700+ .await;
3701+ let html = String::from_utf8_lossy(&page.bytes);
3702+ assert!(
3703+ html.contains("viewer-present"),
3704+ "no Present control on a PDF: {html}"
3705+ );
3706+ assert!(
3707+ html.contains("requestFullscreen"),
3708+ "no presentation wiring on a PDF: {html}"
3709+ );
3710+
3711+ let png = [0x89u8, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 1, 2, 3, 4];
3712+ app.post_multipart(
3713+ "/files",
3714+ Some(&admin_cookie),
3715+ &[("task_id", &task)],
3716+ Some(("spec.png", "image/png", &png)),
3717+ )
3718+ .await;
3719+ let snapshot = app
3720+ .post(
3721+ "/api/fetch_task",
3722+ Some(&admin_cookie),
3723+ &[("task_id", &task)],
3724+ )
3725+ .await;
3726+ let png_id = attachment_id_named(&snapshot.body, "spec.png");
3727+ let page = app
3728+ .get(&format!("/?task={task}&file={png_id}"), Some(&admin_cookie))
3729+ .await;
3730+ let html = String::from_utf8_lossy(&page.bytes);
3731+ assert!(
3732+ !html.contains("viewer-present"),
3733+ "an image got the PDF's Present control: {html}"
3734+ );
3735+}
3736+
3671 /// A file is opened from a section, so closing it lands back on that section:3737 /// A file is opened from a section, so closing it lands back on that section:
3672 /// the close links carry the tab the viewer was opened over, not the panel's3738 /// the close links carry the tab the viewer was opened over, not the panel's
3673 /// default.3739 /// default.
@@ -5122,6 +5188,28 @@ async fn the_avatar_is_not_found_without_an_im_photo() {
5122 .await;5188 .await;
5123 assert_eq!(photo.status, StatusCode::NOT_FOUND);5189 assert_eq!(photo.status, StatusCode::NOT_FOUND);
5124 }5190 }
5191+
5192+/// Every page with avatars carries the fallback script: the board's topbar
5193+/// and card faces are `<img>`s to 404s without it, and a bare failed `<img>`
5194+/// is the broken-image box, not the initials. Catches a page that renders
5195+/// `avatar()` without the behavior that hides the failure.
5196+#[tokio::test]
5197+async fn the_board_carries_the_avatar_fallback_script() {
5198+ let app = App::open().await;
5199+ let admin = admin(&app).await;
5200+
5201+ let page = app.get("/", Some(&admin)).await;
5202+ assert_eq!(page.status.as_u16(), 200);
5203+ let html = String::from_utf8(page.bytes).unwrap();
5204+ assert!(
5205+ html.contains("avatar-photo"),
5206+ "the topbar face is not on the board: {html}"
5207+ );
5208+ assert!(
5209+ html.contains("__izAvatar"),
5210+ "avatars without the fallback script show the broken-image box: {html}"
5211+ );
5212+}
5125 /// Polls the store until a `Rule` send for `rule_id` addressed to `recipient`5213 /// Polls the store until a `Rule` send for `rule_id` addressed to `recipient`
5126 /// exists beyond the `already` count — the engine runs off the request in a5214 /// exists beyond the `already` count — the engine runs off the request in a
5127 /// spawned task, so the row is not there yet when the triggering call5215 /// spawned task, so the row is not there yet when the triggering call