From 0983a3bb84a4ddc85852863400face991b8b9c7f Mon Sep 17 00:00:00 2001 From: trisua Date: Mon, 2 Jun 2025 21:18:19 -0400 Subject: [PATCH] add: allow mods to view user notifications --- crates/app/src/public/html/macros.lisp | 6 ---- .../src/public/html/misc/notifications.lisp | 11 ++++++++ crates/app/src/public/html/mod/profile.lisp | 12 ++++++++ .../app/src/public/html/profile/settings.lisp | 2 +- crates/app/src/routes/pages/misc.rs | 28 +++++++++++++------ 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/crates/app/src/public/html/macros.lisp b/crates/app/src/public/html/macros.lisp index 73ec5e1..188bd45 100644 --- a/crates/app/src/public/html/macros.lisp +++ b/crates/app/src/public/html/macros.lisp @@ -219,11 +219,5 @@ ("href" "/@{{ profile.username }}/outbox") ("class" "{% if selected == 'outbox' -%}active{%- endif %}") (str (text "auth:label.outbox"))) - (text "{%- endif %}") - - (text "{% if is_helper -%}") - (a - ("href" "/requests?id={{ profile.id }}") - (str (text "requests:label.requests"))) (text "{%- endif %} {%- endif %}")) (text "{%- endmacro %}") diff --git a/crates/app/src/public/html/misc/notifications.lisp b/crates/app/src/public/html/misc/notifications.lisp index dd08d58..7e6dabb 100644 --- a/crates/app/src/public/html/misc/notifications.lisp +++ b/crates/app/src/public/html/misc/notifications.lisp @@ -5,6 +5,17 @@ (text "{% endblock %} {% block body %} {{ macros::nav(selected=\"notifications\") }}") (main ("class" "flex flex-col gap-2") + + ; viewing other user's notifications warning + (text "{% if profile.id != user.id -%}") + (div + ("class" "card w-full red flex gap-2 items-center") + (text "{{ icon \"skull\" }}") + (b + (text "Viewing other user's notifications! Please be careful."))) + (text "{%- endif %}") + + ; ... (div ("class" "card-nest") (div diff --git a/crates/app/src/public/html/mod/profile.lisp b/crates/app/src/public/html/mod/profile.lisp index c8433cd..e1d6c9b 100644 --- a/crates/app/src/public/html/mod/profile.lisp +++ b/crates/app/src/public/html/mod/profile.lisp @@ -32,6 +32,18 @@ (text "{{ icon \"shield-alert\" }}") (span (text "View warnings"))) + (a + ("href" "/notifs?id={{ profile.id }}") + ("class" "button quaternary") + (text "{{ icon \"bell\" }}") + (span + (text "Notifications"))) + (a + ("href" "/requests?id={{ profile.id }}") + ("class" "button quaternary") + (text "{{ icon \"inbox\" }}") + (span + (text "Requests"))) (button ("class" "red quaternary") ("onclick" "delete_account(event)") diff --git a/crates/app/src/public/html/profile/settings.lisp b/crates/app/src/public/html/profile/settings.lisp index f4c2a08..359b1c5 100644 --- a/crates/app/src/public/html/profile/settings.lisp +++ b/crates/app/src/public/html/profile/settings.lisp @@ -638,7 +638,7 @@ ("id" "banner_file") ("name" "file") ("type" "file") - ("accept" "image/png,image/jpeg,image/avif,image/webp") + ("accept" "image/png,image/jpeg,image/avif,image/webp,image/gif") ("class" "w-content")) (button ("class" "primary") diff --git a/crates/app/src/routes/pages/misc.rs b/crates/app/src/routes/pages/misc.rs index 52f806b..e6c1581 100644 --- a/crates/app/src/routes/pages/misc.rs +++ b/crates/app/src/routes/pages/misc.rs @@ -357,10 +357,17 @@ pub async fn all_questions_request( ) } +#[derive(Deserialize)] +pub struct NotificationsProps { + #[serde(default)] + pub id: usize, +} + /// `/notifs` pub async fn notifications_request( jar: CookieJar, Extension(data): Extension, + Query(props): Query, ) -> impl IntoResponse { let data = data.read().await; let user = match get_user_from_token!(jar, data.0) { @@ -372,13 +379,24 @@ pub async fn notifications_request( } }; - let notifications = match data.0.get_notifications_by_owner(user.id).await { + let profile = if props.id != 0 { + match data.0.get_user_by_id(props.id).await { + Ok(p) => p, + Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)), + } + } else { + user.clone() + }; + + let notifications = match data.0.get_notifications_by_owner(profile.id).await { Ok(p) => p, Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)), }; let lang = get_lang!(jar, data.0); let mut context = initial_context(&data.0.0, lang, &Some(user)).await; + + context.insert("profile", &profile); context.insert("notifications", ¬ifications); // return @@ -387,17 +405,11 @@ pub async fn notifications_request( )) } -#[derive(Deserialize)] -pub struct RequestsProps { - #[serde(default)] - pub id: usize, -} - /// `/requests` pub async fn requests_request( jar: CookieJar, Extension(data): Extension, - Query(props): Query, + Query(props): Query, ) -> impl IntoResponse { let data = data.read().await; let user = match get_user_from_token!(jar, data.0) {