Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast: add roles check to views::v2::path::pathfinding #8449

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions editoast/src/views/v2/path/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::sync::Arc;
use axum::extract::Json;
use axum::extract::Path;
use axum::extract::State;
use axum::Extension;
use editoast_authz::BuiltinRole;
use editoast_schemas::rolling_stock::LoadingGaugeType;
use editoast_schemas::train_schedule::PathItemLocation;
use serde::Deserialize;
Expand All @@ -27,6 +29,8 @@ use crate::redis_utils::RedisConnection;
use crate::views::get_app_version;
use crate::views::v2::path::path_item_cache::PathItemCache;
use crate::views::v2::path::PathfindingError;
use crate::views::AuthorizationError;
use crate::views::AuthorizerExt;
use crate::AppState;
use editoast_models::DbConnection;

Expand Down Expand Up @@ -75,9 +79,18 @@ async fn post(
core_client,
..
}): State<AppState>,
Extension(authorizer): AuthorizerExt,
Path(infra_id): Path<i64>,
Json(path_input): Json<PathfindingInput>,
) -> Result<Json<PathfindingResult>> {
let authorized = authorizer
.check_roles([BuiltinRole::InfraRead].into())
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
}

let conn = &mut db_pool.get().await?;
let mut redis_conn = redis.get_connection().await?;
let infra = Infra::retrieve_or_fail(conn, infra_id, || PathfindingError::InfraNotFound {
Expand Down
Loading