feat: add Settings, Blocked, and Admin nav links; add is_admin to HtmlPageContext
This commit is contained in:
@@ -34,6 +34,11 @@
|
|||||||
<a href="/users/{{ uid }}">Profile</a>
|
<a href="/users/{{ uid }}">Profile</a>
|
||||||
<a href="/reviews/new">Add Review</a>
|
<a href="/reviews/new">Add Review</a>
|
||||||
<a href="/import">Import</a>
|
<a href="/import">Import</a>
|
||||||
|
<a href="/social/blocked">Blocked</a>
|
||||||
|
<a href="/settings/profile">Settings</a>
|
||||||
|
{% if ctx.is_admin %}
|
||||||
|
<a href="/admin/blocked-domains">Admin</a>
|
||||||
|
{% endif %}
|
||||||
<a href="/logout">Logout</a>
|
<a href="/logout">Logout</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="/login">Login</a>
|
<a href="/login">Login</a>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ pub struct RemoteActorView {
|
|||||||
pub struct HtmlPageContext {
|
pub struct HtmlPageContext {
|
||||||
pub user_email: Option<String>,
|
pub user_email: Option<String>,
|
||||||
pub user_id: Option<Uuid>,
|
pub user_id: Option<Uuid>,
|
||||||
|
pub is_admin: bool,
|
||||||
pub register_enabled: bool,
|
pub register_enabled: bool,
|
||||||
pub rss_url: String,
|
pub rss_url: String,
|
||||||
pub page_title: String,
|
pub page_title: String,
|
||||||
|
|||||||
@@ -46,21 +46,24 @@ pub(crate) async fn build_page_context(
|
|||||||
csrf_token: String,
|
csrf_token: String,
|
||||||
) -> HtmlPageContext {
|
) -> HtmlPageContext {
|
||||||
let uuid = user_id.as_ref().map(|u| u.value());
|
let uuid = user_id.as_ref().map(|u| u.value());
|
||||||
let user_email = if let Some(ref id) = user_id {
|
let (user_email, is_admin) = if let Some(ref id) = user_id {
|
||||||
state
|
let user = state
|
||||||
.app_ctx
|
.app_ctx
|
||||||
.user_repository
|
.user_repository
|
||||||
.find_by_id(id)
|
.find_by_id(id)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.flatten()
|
.flatten();
|
||||||
.map(|u| u.email().value().to_string())
|
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 {
|
} else {
|
||||||
None
|
(None, false)
|
||||||
};
|
};
|
||||||
HtmlPageContext {
|
HtmlPageContext {
|
||||||
user_email,
|
user_email,
|
||||||
user_id: uuid,
|
user_id: uuid,
|
||||||
|
is_admin,
|
||||||
register_enabled: state.app_ctx.config.allow_registration,
|
register_enabled: state.app_ctx.config.allow_registration,
|
||||||
rss_url: "/feed.rss".to_string(),
|
rss_url: "/feed.rss".to_string(),
|
||||||
page_title: "Movies Diary".to_string(),
|
page_title: "Movies Diary".to_string(),
|
||||||
@@ -104,6 +107,7 @@ pub async fn get_login_page(
|
|||||||
let ctx = HtmlPageContext {
|
let ctx = HtmlPageContext {
|
||||||
user_email: None,
|
user_email: None,
|
||||||
user_id: None,
|
user_id: None,
|
||||||
|
is_admin: false,
|
||||||
register_enabled: state.app_ctx.config.allow_registration,
|
register_enabled: state.app_ctx.config.allow_registration,
|
||||||
rss_url: "/feed.rss".to_string(),
|
rss_url: "/feed.rss".to_string(),
|
||||||
page_title: "Login — Movies Diary".to_string(),
|
page_title: "Login — Movies Diary".to_string(),
|
||||||
@@ -170,6 +174,7 @@ pub async fn get_register_page(
|
|||||||
let ctx = HtmlPageContext {
|
let ctx = HtmlPageContext {
|
||||||
user_email: None,
|
user_email: None,
|
||||||
user_id: None,
|
user_id: None,
|
||||||
|
is_admin: false,
|
||||||
register_enabled: true,
|
register_enabled: true,
|
||||||
rss_url: "/feed.rss".to_string(),
|
rss_url: "/feed.rss".to_string(),
|
||||||
page_title: "Register — Movies Diary".to_string(),
|
page_title: "Register — Movies Diary".to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user