diff --git a/crates/adapters/template-askama/templates/base.html b/crates/adapters/template-askama/templates/base.html index 8ea0eac..a54246f 100644 --- a/crates/adapters/template-askama/templates/base.html +++ b/crates/adapters/template-askama/templates/base.html @@ -34,6 +34,11 @@ Profile Add Review Import + Blocked + Settings + {% if ctx.is_admin %} + Admin + {% endif %} Logout {% else %} Login diff --git a/crates/application/src/ports.rs b/crates/application/src/ports.rs index 1cb92d2..dd134d0 100644 --- a/crates/application/src/ports.rs +++ b/crates/application/src/ports.rs @@ -14,6 +14,7 @@ pub struct RemoteActorView { pub struct HtmlPageContext { pub user_email: Option, pub user_id: Option, + pub is_admin: bool, pub register_enabled: bool, pub rss_url: String, pub page_title: String, diff --git a/crates/presentation/src/handlers/html.rs b/crates/presentation/src/handlers/html.rs index 8f6e03a..da3a0af 100644 --- a/crates/presentation/src/handlers/html.rs +++ b/crates/presentation/src/handlers/html.rs @@ -46,21 +46,24 @@ pub(crate) async fn build_page_context( csrf_token: String, ) -> HtmlPageContext { let uuid = user_id.as_ref().map(|u| u.value()); - let user_email = if let Some(ref id) = user_id { - state + let (user_email, is_admin) = if let Some(ref id) = user_id { + let user = state .app_ctx .user_repository .find_by_id(id) .await .ok() - .flatten() - .map(|u| u.email().value().to_string()) + .flatten(); + let email = user.as_ref().map(|u| u.email().value().to_string()); + let admin = user.as_ref().map(|u| matches!(u.role(), domain::models::UserRole::Admin)).unwrap_or(false); + (email, admin) } else { - None + (None, false) }; HtmlPageContext { user_email, user_id: uuid, + is_admin, register_enabled: state.app_ctx.config.allow_registration, rss_url: "/feed.rss".to_string(), page_title: "Movies Diary".to_string(), @@ -104,6 +107,7 @@ pub async fn get_login_page( let ctx = HtmlPageContext { user_email: None, user_id: None, + is_admin: false, register_enabled: state.app_ctx.config.allow_registration, rss_url: "/feed.rss".to_string(), page_title: "Login — Movies Diary".to_string(), @@ -170,6 +174,7 @@ pub async fn get_register_page( let ctx = HtmlPageContext { user_email: None, user_id: None, + is_admin: false, register_enabled: true, rss_url: "/feed.rss".to_string(), page_title: "Register — Movies Diary".to_string(),