Factorize RON error response for not authorized content
This commit is contained in:
parent
f23fd2b832
commit
f31167dd95
2 changed files with 20 additions and 38 deletions
|
|
@ -1,9 +1,6 @@
|
|||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{ErrorResponse, Result},
|
||||
};
|
||||
use axum::response::Result;
|
||||
|
||||
use crate::{consts, data::db, data::model, ron_utils::ron_error};
|
||||
use crate::{data::db, data::model, ron_utils::ron_error_not_autorized};
|
||||
|
||||
pub async fn check_user_rights_recipe(
|
||||
connection: &db::Connection,
|
||||
|
|
@ -12,10 +9,7 @@ pub async fn check_user_rights_recipe(
|
|||
) -> Result<()> {
|
||||
match user {
|
||||
Some(user) if connection.can_edit_recipe(user.id, recipe_id).await? => Ok(()),
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,10 +20,7 @@ pub async fn check_user_rights_recipe_group(
|
|||
) -> Result<()> {
|
||||
match user {
|
||||
Some(user) if connection.can_edit_recipe_group(user.id, group_id).await? => Ok(()),
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,10 +37,7 @@ pub async fn check_user_rights_recipe_groups(
|
|||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -60,10 +48,7 @@ pub async fn check_user_rights_recipe_step(
|
|||
) -> Result<()> {
|
||||
match user {
|
||||
Some(user) if connection.can_edit_recipe_step(user.id, step_id).await? => Ok(()),
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,10 +65,7 @@ pub async fn check_user_rights_recipe_steps(
|
|||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,10 +82,7 @@ pub async fn check_user_rights_recipe_ingredient(
|
|||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,10 +99,7 @@ pub async fn check_user_rights_recipe_ingredients(
|
|||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -140,9 +116,6 @@ pub async fn check_user_rights_shopping_list_entry(
|
|||
{
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))),
|
||||
_ => Err(ron_error_not_autorized()),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue