diff --git a/src/backend/api/article.rs b/src/backend/api/article.rs index fff62cd..8028230 100644 --- a/src/backend/api/article.rs +++ b/src/backend/api/article.rs @@ -1,4 +1,4 @@ -use super::check_is_admin; +use super::{check_is_admin, is_admin_opt}; use crate::{ backend::{ database::{ @@ -161,10 +161,10 @@ pub(in crate::backend::api) async fn edit_article( #[debug_handler] pub(in crate::backend::api) async fn get_article( Query(query): Query, - Extension(user): Extension, + user: Option>, data: Data, ) -> MyResult> { - let is_admin = check_is_admin(&user).is_ok(); + let is_admin = is_admin_opt(&user); match (query.title, query.id) { (Some(title), None) => Ok(Json(DbArticle::read_view_title( &title, diff --git a/src/backend/api/mod.rs b/src/backend/api/mod.rs index c0e216c..529a947 100644 --- a/src/backend/api/mod.rs +++ b/src/backend/api/mod.rs @@ -36,6 +36,7 @@ use axum::{ middleware::{self, Next}, response::Response, routing::{get, post}, + Extension, Router, }; use axum_extra::extract::CookieJar; @@ -93,3 +94,11 @@ fn check_is_admin(user: &LocalUserView) -> MyResult<()> { } Ok(()) } + +fn is_admin_opt(user: &Option>) -> bool { + if let Some(user) = user { + user.local_user.admin + } else { + false + } +}