58 řádky
1.5 KiB
Rust
Spustitelný soubor
58 řádky
1.5 KiB
Rust
Spustitelný soubor
use actix_web::{
|
|
post,
|
|
web::{Bytes, Data},
|
|
HttpRequest, HttpResponse,
|
|
};
|
|
use serde::Deserialize;
|
|
use serde_qs::Config;
|
|
|
|
use crate::{ctx::Ctx, db::models::Board, error::NekrochanError, web::tcx::account_from_auth};
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct UpdateBoardsForm {
|
|
#[serde(default)]
|
|
boards: Vec<String>,
|
|
name: String,
|
|
description: String,
|
|
}
|
|
|
|
#[post("/staff/actions/update-boards")]
|
|
pub async fn update_boards(
|
|
ctx: Data<Ctx>,
|
|
req: HttpRequest,
|
|
bytes: Bytes,
|
|
) -> Result<HttpResponse, NekrochanError> {
|
|
let account = account_from_auth(&ctx, &req).await?;
|
|
|
|
if !account.perms().owner() {
|
|
return Err(NekrochanError::InsufficientPermissionError);
|
|
}
|
|
|
|
let config = Config::new(10, false);
|
|
let form: UpdateBoardsForm = config.deserialize_bytes(&bytes)?;
|
|
|
|
let name = form.name.trim().to_owned();
|
|
let description = form.description.trim().to_owned();
|
|
|
|
if name.is_empty() || name.len() > 32 {
|
|
return Err(NekrochanError::BoardNameFormatError);
|
|
}
|
|
|
|
if description.len() > 128 {
|
|
return Err(NekrochanError::DescriptionFormatError);
|
|
}
|
|
|
|
for board in form.boards {
|
|
if let Some(board) = Board::read(&ctx, board).await? {
|
|
board.update_name(&ctx, name.clone()).await?;
|
|
board.update_description(&ctx, description.clone()).await?;
|
|
}
|
|
}
|
|
|
|
let res = HttpResponse::SeeOther()
|
|
.append_header(("Location", "/staff/boards"))
|
|
.finish();
|
|
|
|
Ok(res)
|
|
}
|