add: allow mods to view user notifications
This commit is contained in:
parent
d44004e86b
commit
0983a3bb84
5 changed files with 44 additions and 15 deletions
|
@ -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<State>,
|
||||
Query(props): Query<NotificationsProps>,
|
||||
) -> 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<State>,
|
||||
Query(props): Query<RequestsProps>,
|
||||
Query(props): Query<NotificationsProps>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue