This repository has been archived on 2025-09-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
nekrochan/src/web/staff/news.rs
2025-09-28 12:59:09 +02:00

32 lines
779 B
Rust

use actix_web::{get, web::Data, HttpRequest, HttpResponse};
use askama::Template;
use crate::{
ctx::Ctx,
db::models::NewsPost,
error::NekrochanError,
filters,
web::{tcx::TemplateCtx, template_response},
};
#[derive(Template)]
#[template(path = "staff/news.html")]
struct NewsTemplate {
tcx: TemplateCtx,
news: Vec<NewsPost>,
}
#[get("/staff/news")]
pub async fn news(ctx: Data<Ctx>, req: HttpRequest) -> Result<HttpResponse, NekrochanError> {
let tcx = TemplateCtx::new(&ctx, &req).await?;
if !(tcx.perms.owner() || tcx.perms.news()) {
return Err(NekrochanError::InsufficientPermissionError);
}
let news = NewsPost::read_all(&ctx).await?;
let template = NewsTemplate { tcx, news };
template_response(&template)
}