39 řádky
982 B
Rust
Spustitelný soubor
39 řádky
982 B
Rust
Spustitelný soubor
use actix_web::{post, web::Data, HttpRequest, HttpResponse};
|
|
use serde::Deserialize;
|
|
|
|
use crate::{
|
|
ctx::Ctx, db::models::Banner, error::NekrochanError, qsform::QsForm,
|
|
web::tcx::account_from_auth,
|
|
};
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct RemoveBannersForm {
|
|
#[serde(default)]
|
|
banners: Vec<i32>,
|
|
}
|
|
|
|
#[post("/staff/actions/remove-banners")]
|
|
pub async fn remove_banners(
|
|
ctx: Data<Ctx>,
|
|
req: HttpRequest,
|
|
QsForm(form): QsForm<RemoveBannersForm>,
|
|
) -> Result<HttpResponse, NekrochanError> {
|
|
let account = account_from_auth(&ctx, &req).await?;
|
|
|
|
if !(account.perms().owner() || account.perms().banners()) {
|
|
return Err(NekrochanError::InsufficientPermissionError);
|
|
}
|
|
|
|
for id in form.banners {
|
|
if let Some(banner) = Banner::read(&ctx, id).await? {
|
|
banner.remove(&ctx).await?;
|
|
}
|
|
}
|
|
|
|
let res = HttpResponse::SeeOther()
|
|
.append_header(("Location", "/staff/banners"))
|
|
.finish();
|
|
|
|
Ok(res)
|
|
}
|