1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-22 03:11:08 +00:00

Fix page load

This commit is contained in:
Felix Ableitner 2024-11-13 10:41:55 +01:00
parent 0e7a45306d
commit d075d15b50
2 changed files with 12 additions and 3 deletions

View file

@ -1,4 +1,4 @@
use super::check_is_admin; use super::{check_is_admin, is_admin_opt};
use crate::{ use crate::{
backend::{ backend::{
database::{ database::{
@ -161,10 +161,10 @@ pub(in crate::backend::api) async fn edit_article(
#[debug_handler] #[debug_handler]
pub(in crate::backend::api) async fn get_article( pub(in crate::backend::api) async fn get_article(
Query(query): Query<GetArticleForm>, Query(query): Query<GetArticleForm>,
Extension(user): Extension<LocalUserView>, user: Option<Extension<LocalUserView>>,
data: Data<IbisData>, data: Data<IbisData>,
) -> MyResult<Json<ArticleView>> { ) -> MyResult<Json<ArticleView>> {
let is_admin = check_is_admin(&user).is_ok(); let is_admin = is_admin_opt(&user);
match (query.title, query.id) { match (query.title, query.id) {
(Some(title), None) => Ok(Json(DbArticle::read_view_title( (Some(title), None) => Ok(Json(DbArticle::read_view_title(
&title, &title,

View file

@ -36,6 +36,7 @@ use axum::{
middleware::{self, Next}, middleware::{self, Next},
response::Response, response::Response,
routing::{get, post}, routing::{get, post},
Extension,
Router, Router,
}; };
use axum_extra::extract::CookieJar; use axum_extra::extract::CookieJar;
@ -93,3 +94,11 @@ fn check_is_admin(user: &LocalUserView) -> MyResult<()> {
} }
Ok(()) Ok(())
} }
fn is_admin_opt(user: &Option<Extension<LocalUserView>>) -> bool {
if let Some(user) = user {
user.local_user.admin
} else {
false
}
}