add: user account warnings

This commit is contained in:
trisua 2025-04-11 22:12:43 -04:00
parent 535a854a47
commit 5995aaf31c
16 changed files with 459 additions and 1 deletions

View file

@ -35,6 +35,10 @@ pub fn routes() -> Router {
"/mod_panel/profile/{id}",
get(mod_panel::manage_profile_request),
)
.route(
"/mod_panel/profile/{id}/warnings",
get(mod_panel::manage_profile_warnings_request),
)
// auth
.route("/auth/register", get(auth::register_request))
.route("/auth/login", get(auth::login_request))

View file

@ -184,3 +184,51 @@ pub async fn manage_profile_request(
// return
Ok(Html(data.1.render("mod/profile.html", &context).unwrap()))
}
/// `/mod_panel/profile/{id}/warnings`
pub async fn manage_profile_warnings_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
Query(req): Query<PaginatedQuery>,
) -> impl IntoResponse {
let data = data.read().await;
let user = match get_user_from_token!(jar, data.0) {
Some(ua) => ua,
None => {
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
}
};
if !user.permissions.check(FinePermission::MANAGE_USERS) {
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
}
let profile = match data.0.get_user_by_id(id).await {
Ok(p) => p,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
};
let list = match data
.0
.get_user_warnings_by_user(profile.id, 12, req.page)
.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("items", &list);
context.insert("page", &req.page);
// return
Ok(Html(data.1.render("mod/warnings.html", &context).unwrap()))
}