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: rename Unauthenticated to Unauthorized, Unauthorized to Forbidden #10191

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4133,7 +4133,7 @@ components:
type: string
enum:
- editoast:authz:DbError
EditoastAuthorizationErrorUnauthenticated:
EditoastAuthorizationErrorForbidden:
type: object
required:
- type
Expand All @@ -4147,11 +4147,11 @@ components:
status:
type: integer
enum:
- 401
- 403
type:
type: string
enum:
- editoast:authz:Unauthenticated
- editoast:authz:Forbidden
EditoastAuthorizationErrorUnauthorized:
type: object
required:
Expand All @@ -4166,7 +4166,7 @@ components:
status:
type: integer
enum:
- 403
- 401
type:
type: string
enum:
Expand Down Expand Up @@ -4665,7 +4665,7 @@ components:
- $ref: '#/components/schemas/EditoastAttachedErrorTrackNotFound'
- $ref: '#/components/schemas/EditoastAuthorizationErrorAuthError'
- $ref: '#/components/schemas/EditoastAuthorizationErrorDbError'
- $ref: '#/components/schemas/EditoastAuthorizationErrorUnauthenticated'
- $ref: '#/components/schemas/EditoastAuthorizationErrorForbidden'
- $ref: '#/components/schemas/EditoastAuthorizationErrorUnauthorized'
- $ref: '#/components/schemas/EditoastAuthzErrorAuthz'
- $ref: '#/components/schemas/EditoastAuthzErrorDriver'
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/authz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn list_user_roles(
.await
.map_err(AuthorizationError::from)?
{
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let authorizer = auth.authorizer()?;
Expand Down Expand Up @@ -142,7 +142,7 @@ async fn grant_roles(
.await
.map_err(AuthorizationError::from)?
{
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let mut authorizer = auth.authorizer()?;
Expand Down Expand Up @@ -174,7 +174,7 @@ async fn strip_roles(
.await
.map_err(AuthorizationError::from)?
{
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let mut authorizer = auth.authorizer()?;
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn get(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let conn = &mut db_pool.get().await?;
let doc = Document::retrieve_or_fail(conn, document_id, || DocumentErrors::NotFound {
Expand Down Expand Up @@ -108,7 +108,7 @@ async fn post(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let content_type = content_type.to_string();

Expand Down Expand Up @@ -151,7 +151,7 @@ async fn delete(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let conn = &mut db_pool.get().await?;
Document::delete_static_or_fail(conn, document_id, || DocumentErrors::NotFound {
Expand Down
10 changes: 5 additions & 5 deletions editoast/src/views/electrical_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn list(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let mut conn = db_pool.get().await?;
Ok(Json(ElectricalProfileSet::list_light(&mut conn).await?))
Expand All @@ -92,7 +92,7 @@ async fn get(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let conn = &mut db_pool.get().await?;
let ep_set = ElectricalProfileSet::retrieve_or_fail(conn, electrical_profile_set_id, || {
Expand Down Expand Up @@ -131,7 +131,7 @@ async fn get_level_order(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let conn = &mut db_pool.get().await?;
let ep_set = ElectricalProfileSet::retrieve_or_fail(conn, electrical_profile_set_id, || {
Expand Down Expand Up @@ -163,7 +163,7 @@ async fn delete(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let conn = &mut db_pool.get().await?;
let deleted = ElectricalProfileSet::delete_static(conn, electrical_profile_set_id).await?;
Expand Down Expand Up @@ -201,7 +201,7 @@ async fn post_electrical_profile(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}
let ep_set = ElectricalProfileSet::changeset()
.name(ep_set_name.name)
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/attached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn attached(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let mut conn = db_pool.get().await?;
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/auto_fixes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn list_auto_fixes(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let conn = &mut db_pool.get().await?;
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/delimited_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async fn delimited_area(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

// Retrieve the infra
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/infra/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async fn edit<'a>(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

// TODO: lock for update
Expand Down Expand Up @@ -140,7 +140,7 @@ pub async fn split_track_section<'a>(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

info!(
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn list_errors(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let (page, page_size) = pagination_params
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn get_line_bbox(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let line_code: i32 = line_code.try_into().unwrap();
Expand Down
28 changes: 14 additions & 14 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn refresh(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

// Use a transaction to give scope to infra list lock
Expand Down Expand Up @@ -214,7 +214,7 @@ async fn list(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let settings = pagination_params
Expand Down Expand Up @@ -310,7 +310,7 @@ async fn get(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let infra_id = infra.infra_id;
Expand Down Expand Up @@ -356,7 +356,7 @@ async fn create(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let infra: Changeset<Infra> = infra_form.into();
Expand Down Expand Up @@ -392,7 +392,7 @@ async fn clone(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let conn = &mut db_pool.get().await?;
Expand Down Expand Up @@ -437,7 +437,7 @@ async fn delete(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

if Infra::fast_delete_static(db_pool.get().await?, infra_id).await? {
Expand Down Expand Up @@ -482,7 +482,7 @@ async fn put(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let infra_cs: Changeset<Infra> = patch.into();
Expand Down Expand Up @@ -518,7 +518,7 @@ async fn get_switch_types(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let conn = &mut db_pool.get().await?;
Expand Down Expand Up @@ -559,7 +559,7 @@ async fn get_speed_limit_tags(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let conn = &mut db_pool.get().await?;
Expand Down Expand Up @@ -603,7 +603,7 @@ async fn get_voltages(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let include_rolling_stock_modes = param.include_rolling_stock_modes;
Expand Down Expand Up @@ -637,7 +637,7 @@ async fn get_all_voltages(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let voltages = Infra::get_all_voltages(&mut db_pool.get().await?).await?;
Expand Down Expand Up @@ -673,7 +673,7 @@ async fn lock(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

set_locked(infra.infra_id, true, db_pool).await?;
Expand All @@ -700,7 +700,7 @@ async fn unlock(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

set_locked(infra.infra_id, false, db_pool).await?;
Expand Down Expand Up @@ -731,7 +731,7 @@ async fn load(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let infra_id = path.infra_id;
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn get_objects(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let infra_id = infra_id_param.infra_id;
Expand Down
2 changes: 1 addition & 1 deletion editoast/src/views/infra/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn pathfinding_view(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

// Parse and check input
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/infra/railjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn get_railjson(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let infra_id = infra.infra_id;
Expand Down Expand Up @@ -182,7 +182,7 @@ async fn post_railjson(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

if railjson.version != RAILJSON_VERSION {
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/infra/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn get_routes_from_waypoint(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let conn = &mut db_pool.get().await?;
Expand Down Expand Up @@ -159,7 +159,7 @@ async fn get_routes_track_ranges(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let db_pool = db_pool.clone();
Expand Down Expand Up @@ -224,7 +224,7 @@ async fn get_routes_nodes(
.await
.map_err(AuthorizationError::AuthError)?;
if !authorized {
return Err(AuthorizationError::Unauthorized.into());
return Err(AuthorizationError::Forbidden.into());
}

let infra = Infra::retrieve_or_fail(&mut db_pool.get().await?, params.infra_id, || {
Expand Down
Loading
Loading