From aec6e7096cb6becc3d138e526aa64f23d1c47ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 29 Aug 2026 02:45:18 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(web):=20the=20nav=20knows=20it?= =?UTF-8?q?s=20audience=20=E2=80=94=20and=20the=20menu=20says=20settings?= =?UTF-8?q?=20once,=20nowhere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/izlek-web/src/board.rs | 2 +- crates/izlek-web/src/layout.rs | 13 +++++++------ crates/izlek-web/src/logs.rs | 2 +- crates/izlek-web/src/rules.rs | 2 +- crates/izlek-web/src/settings.rs | 2 +- crates/izlek-web/tests/http.rs | 20 ++++++++++++++++++++ style/main.scss | 6 ------ 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/crates/izlek-web/src/board.rs b/crates/izlek-web/src/board.rs index de5eab7..7618483 100644 --- a/crates/izlek-web/src/board.rs +++ b/crates/izlek-web/src/board.rs @@ -550,7 +550,7 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result { "izlek" - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Board, lang).await?) + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Board, user.role, lang).await?)
(crate::layout::user_menu(cx, &crate::detail::Me::from(user), lang).await?) diff --git a/crates/izlek-web/src/layout.rs b/crates/izlek-web/src/layout.rs index 0371ed7..c8b4c42 100644 --- a/crates/izlek-web/src/layout.rs +++ b/crates/izlek-web/src/layout.rs @@ -45,8 +45,8 @@ pub(crate) async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { } /// The topbar's signed-in identity: the display name, opening on hover or -/// focus onto details (name, address, role), settings and sign-out. Shared -/// by every signed-in page's topbar (board, settings, mail rules, logs). +/// focus onto details (name, address, role) and sign-out. Shared by every +/// signed-in page's topbar (board, settings, mail rules, logs). pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result { let role_key = match me.role { izlek_core::Role::Admin => Key::RoleAdminOption, @@ -69,8 +69,6 @@ pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result {
(me.display_name.clone())
(me.email.clone())
(t(lang, role_key))
-
- (t(lang, Key::Settings))
@@ -111,19 +109,22 @@ impl NavPage { } /// The topbar's page nav, shared by every signed-in page: the four pages -/// with the current one marked. Plain ``s — the soft-nav forwarder +/// with the current one marked, the admin-only ones (rules, logs) shown +/// only to roles that can administer. Plain ``s — the soft-nav forwarder /// swaps them like any same-origin link, so `data-hard` stays off. -pub async fn topbar_nav(cx: &Cx, active: NavPage, lang: Lang) -> Result { +pub async fn topbar_nav(cx: &Cx, active: NavPage, role: izlek_core::Role, lang: Lang) -> Result { view! { cx => } diff --git a/crates/izlek-web/src/logs.rs b/crates/izlek-web/src/logs.rs index 9b0a357..c21ad77 100644 --- a/crates/izlek-web/src/logs.rs +++ b/crates/izlek-web/src/logs.rs @@ -405,7 +405,7 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot) -> Result { "izlek" - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Logs, lang).await?) + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Logs, me.role, lang).await?)
(crate::layout::user_menu(cx, &me, lang).await?) diff --git a/crates/izlek-web/src/rules.rs b/crates/izlek-web/src/rules.rs index 0777067..b49ba2b 100644 --- a/crates/izlek-web/src/rules.rs +++ b/crates/izlek-web/src/rules.rs @@ -838,7 +838,7 @@ async fn rules_page(cx: &Cx) -> Result { "izlek" - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Rules, lang).await?) + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Rules, user.role, lang).await?)
(crate::layout::user_menu(cx, &crate::detail::Me::from(&user), lang).await?) diff --git a/crates/izlek-web/src/settings.rs b/crates/izlek-web/src/settings.rs index d80f8bf..df9fd63 100644 --- a/crates/izlek-web/src/settings.rs +++ b/crates/izlek-web/src/settings.rs @@ -861,7 +861,7 @@ async fn settings_page(cx: &Cx) -> Result { "izlek" - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Settings, lang).await?) + (crate::layout::topbar_nav(cx, crate::layout::NavPage::Settings, user.role, lang).await?)
(crate::layout::user_menu(cx, &crate::detail::Me::from(&user), lang).await?) diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index 103c68a..97b1680 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -4509,3 +4509,23 @@ async fn an_unknown_photo_id_is_not_found_and_the_photo_revalidates_by_etag() { assert_eq!(cached.status, StatusCode::NOT_MODIFIED); assert!(cached.bytes.is_empty()); } + +/// The nav shows a page only to a role that can act on it: an admin's board +/// carries all four links, a member's carries neither Rules nor Logs. +#[tokio::test] +async fn the_nav_hides_rules_and_logs_from_a_member() { + let app = App::open().await; + let admin = admin(&app).await; + let member = invited(&app, &admin, "deniz@izlek.sh", "Deniz", Role::Member).await; + + let admin_board = app.get("/", Some(&admin)).await; + let admin_html = String::from_utf8_lossy(&admin_board.bytes).into_owned(); + assert!(admin_html.contains("href=\"/rules\"")); + assert!(admin_html.contains("href=\"/logs\"")); + + let member_board = app.get("/", Some(&member)).await; + let member_html = String::from_utf8_lossy(&member_board.bytes).into_owned(); + assert!(member_html.contains("href=\"/settings\"")); + assert!(!member_html.contains("href=\"/rules\"")); + assert!(!member_html.contains("href=\"/logs\"")); +} diff --git a/style/main.scss b/style/main.scss index daa3e19..5d46d96 100644 --- a/style/main.scss +++ b/style/main.scss @@ -613,12 +613,6 @@ a { text-transform: capitalize; } -.user-menu-divider { - height: 1px; - margin: 6px 0; - background: var(--border); -} - .user-menu-item { display: flex; align-items: center;