The nav knows its audience — and the menu says settings once, nowhere
Browse files at this commitaec6e7096cb6becc3d138e526aa64f23d1c47aceParent: f09d14a- feat
- the nav knows its audience — and the menu says settings once, nowhere
7 changed files +31 -16
- crates/izlek-web/src/board.rs +1 -1
- crates/izlek-web/src/layout.rs +7 -6
- crates/izlek-web/src/logs.rs +1 -1
- crates/izlek-web/src/rules.rs +1 -1
- crates/izlek-web/src/settings.rs +1 -1
- crates/izlek-web/tests/http.rs +20 -0
- style/main.scss +0 -6
crates/izlek-web/src/board.rsmodified+1 -1
| @@ -550,7 +550,7 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result { | |||
| 550 | <span class="wordmark-text">"izlek"</span> | 550 | <span class="wordmark-text">"izlek"</span> |
| 551 | <span class="wordmark-dot"></span> | 551 | <span class="wordmark-dot"></span> |
| 552 | </a> | 552 | </a> |
| 553 | - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Board, lang).await?) | 553 | + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Board, user.role, lang).await?) |
| 554 | <div class="spacer"></div> | 554 | <div class="spacer"></div> |
| 555 | (crate::layout::user_menu(cx, &crate::detail::Me::from(user), lang).await?) | 555 | (crate::layout::user_menu(cx, &crate::detail::Me::from(user), lang).await?) |
| 556 | </header> | 556 | </header> |
crates/izlek-web/src/layout.rsmodified+7 -6
| @@ -45,8 +45,8 @@ pub(crate) async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { | |||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | /// The topbar's signed-in identity: the display name, opening on hover or | 47 | /// The topbar's signed-in identity: the display name, opening on hover or |
| 48 | -/// focus onto details (name, address, role), settings and sign-out. Shared | 48 | +/// focus onto details (name, address, role) and sign-out. Shared by every |
| 49 | -/// by every signed-in page's topbar (board, settings, mail rules, logs). | 49 | +/// signed-in page's topbar (board, settings, mail rules, logs). |
| 50 | pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result { | 50 | pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result { |
| 51 | let role_key = match me.role { | 51 | let role_key = match me.role { |
| 52 | izlek_core::Role::Admin => Key::RoleAdminOption, | 52 | izlek_core::Role::Admin => Key::RoleAdminOption, |
| @@ -69,8 +69,6 @@ pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result { | |||
| 69 | <div class="user-menu-name">(me.display_name.clone())</div> | 69 | <div class="user-menu-name">(me.display_name.clone())</div> |
| 70 | <div class="user-menu-email">(me.email.clone())</div> | 70 | <div class="user-menu-email">(me.email.clone())</div> |
| 71 | <div class="user-menu-role">(t(lang, role_key))</div> | 71 | <div class="user-menu-role">(t(lang, role_key))</div> |
| 72 | - <div class="user-menu-divider"></div> | ||
| 73 | - <a class="user-menu-item" href="/settings">(t(lang, Key::Settings))</a> | ||
| 74 | <form class="user-menu-item-form" method="post" action="/api/sign_out" data-hard=""> | 72 | <form class="user-menu-item-form" method="post" action="/api/sign_out" data-hard=""> |
| 75 | <button class="user-menu-item" type="submit">(t(lang, Key::SignOut))</button> | 73 | <button class="user-menu-item" type="submit">(t(lang, Key::SignOut))</button> |
| 76 | </form> | 74 | </form> |
| @@ -111,19 +109,22 @@ impl NavPage { | |||
| 111 | } | 109 | } |
| 112 | 110 | ||
| 113 | /// The topbar's page nav, shared by every signed-in page: the four pages | 111 | /// The topbar's page nav, shared by every signed-in page: the four pages |
| 114 | -/// with the current one marked. Plain `<a>`s — the soft-nav forwarder | 112 | +/// with the current one marked, the admin-only ones (rules, logs) shown |
| 113 | +/// only to roles that can administer. Plain `<a>`s — the soft-nav forwarder | ||
| 115 | /// swaps them like any same-origin link, so `data-hard` stays off. | 114 | /// swaps them like any same-origin link, so `data-hard` stays off. |
| 116 | -pub async fn topbar_nav(cx: &Cx, active: NavPage, lang: Lang) -> Result { | 115 | +pub async fn topbar_nav(cx: &Cx, active: NavPage, role: izlek_core::Role, lang: Lang) -> Result { |
| 117 | view! { | 116 | view! { |
| 118 | cx => | 117 | cx => |
| 119 | <nav class="topbar-nav-links"> | 118 | <nav class="topbar-nav-links"> |
| 120 | for page in NavPage::ALL { | 119 | for page in NavPage::ALL { |
| 120 | + if role.can_administer() || !matches!(page, NavPage::Rules | NavPage::Logs) { | ||
| 121 | <a | 121 | <a |
| 122 | class=(if page == active { "topbar-nav topbar-nav-on" } else { "topbar-nav" }) | 122 | class=(if page == active { "topbar-nav topbar-nav-on" } else { "topbar-nav" }) |
| 123 | href=(page.href()) | 123 | href=(page.href()) |
| 124 | > | 124 | > |
| 125 | (t(lang, page.label())) | 125 | (t(lang, page.label())) |
| 126 | </a> | 126 | </a> |
| 127 | + } | ||
| 127 | } | 128 | } |
| 128 | </nav> | 129 | </nav> |
| 129 | } | 130 | } |
crates/izlek-web/src/logs.rsmodified+1 -1
| @@ -405,7 +405,7 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot) -> Result { | |||
| 405 | <span class="wordmark-text">"izlek"</span> | 405 | <span class="wordmark-text">"izlek"</span> |
| 406 | <span class="wordmark-dot"></span> | 406 | <span class="wordmark-dot"></span> |
| 407 | </a> | 407 | </a> |
| 408 | - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Logs, lang).await?) | 408 | + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Logs, me.role, lang).await?) |
| 409 | <div class="spacer"></div> | 409 | <div class="spacer"></div> |
| 410 | (crate::layout::user_menu(cx, &me, lang).await?) | 410 | (crate::layout::user_menu(cx, &me, lang).await?) |
| 411 | </header> | 411 | </header> |
crates/izlek-web/src/rules.rsmodified+1 -1
| @@ -838,7 +838,7 @@ async fn rules_page(cx: &Cx) -> Result { | |||
| 838 | <span class="wordmark-text">"izlek"</span> | 838 | <span class="wordmark-text">"izlek"</span> |
| 839 | <span class="wordmark-dot"></span> | 839 | <span class="wordmark-dot"></span> |
| 840 | </a> | 840 | </a> |
| 841 | - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Rules, lang).await?) | 841 | + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Rules, user.role, lang).await?) |
| 842 | <div class="spacer"></div> | 842 | <div class="spacer"></div> |
| 843 | (crate::layout::user_menu(cx, &crate::detail::Me::from(&user), lang).await?) | 843 | (crate::layout::user_menu(cx, &crate::detail::Me::from(&user), lang).await?) |
| 844 | </header> | 844 | </header> |
crates/izlek-web/src/settings.rsmodified+1 -1
| @@ -861,7 +861,7 @@ async fn settings_page(cx: &Cx) -> Result { | |||
| 861 | <span class="wordmark-text">"izlek"</span> | 861 | <span class="wordmark-text">"izlek"</span> |
| 862 | <span class="wordmark-dot"></span> | 862 | <span class="wordmark-dot"></span> |
| 863 | </a> | 863 | </a> |
| 864 | - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Settings, lang).await?) | 864 | + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Settings, user.role, lang).await?) |
| 865 | <div class="spacer"></div> | 865 | <div class="spacer"></div> |
| 866 | (crate::layout::user_menu(cx, &crate::detail::Me::from(&user), lang).await?) | 866 | (crate::layout::user_menu(cx, &crate::detail::Me::from(&user), lang).await?) |
| 867 | </header> | 867 | </header> |
crates/izlek-web/tests/http.rsmodified+20 -0
| @@ -4509,3 +4509,23 @@ async fn an_unknown_photo_id_is_not_found_and_the_photo_revalidates_by_etag() { | |||
| 4509 | assert_eq!(cached.status, StatusCode::NOT_MODIFIED); | 4509 | assert_eq!(cached.status, StatusCode::NOT_MODIFIED); |
| 4510 | assert!(cached.bytes.is_empty()); | 4510 | assert!(cached.bytes.is_empty()); |
| 4511 | } | 4511 | } |
| 4512 | + | ||
| 4513 | +/// The nav shows a page only to a role that can act on it: an admin's board | ||
| 4514 | +/// carries all four links, a member's carries neither Rules nor Logs. | ||
| 4515 | +#[tokio::test] | ||
| 4516 | +async fn the_nav_hides_rules_and_logs_from_a_member() { | ||
| 4517 | + let app = App::open().await; | ||
| 4518 | + let admin = admin(&app).await; | ||
| 4519 | + let member = invited(&app, &admin, "deniz@izlek.sh", "Deniz", Role::Member).await; | ||
| 4520 | + | ||
| 4521 | + let admin_board = app.get("/", Some(&admin)).await; | ||
| 4522 | + let admin_html = String::from_utf8_lossy(&admin_board.bytes).into_owned(); | ||
| 4523 | + assert!(admin_html.contains("href=\"/rules\"")); | ||
| 4524 | + assert!(admin_html.contains("href=\"/logs\"")); | ||
| 4525 | + | ||
| 4526 | + let member_board = app.get("/", Some(&member)).await; | ||
| 4527 | + let member_html = String::from_utf8_lossy(&member_board.bytes).into_owned(); | ||
| 4528 | + assert!(member_html.contains("href=\"/settings\"")); | ||
| 4529 | + assert!(!member_html.contains("href=\"/rules\"")); | ||
| 4530 | + assert!(!member_html.contains("href=\"/logs\"")); | ||
| 4531 | +} | ||
style/main.scssmodified+0 -6
| @@ -613,12 +613,6 @@ a { | |||
| 613 | text-transform: capitalize; | 613 | text-transform: capitalize; |
| 614 | } | 614 | } |
| 615 | 615 | ||
| 616 | -.user-menu-divider { | ||
| 617 | - height: 1px; | ||
| 618 | - margin: 6px 0; | ||
| 619 | - background: var(--border); | ||
| 620 | -} | ||
| 621 | - | ||
| 622 | .user-menu-item { | 616 | .user-menu-item { |
| 623 | display: flex; | 617 | display: flex; |
| 624 | align-items: center; | 618 | align-items: center; |