Skip to content

Commit

Permalink
remove "Admin" from some AuthZ models
Browse files Browse the repository at this point in the history
  • Loading branch information
KavikaPalletenne committed Nov 12, 2024
1 parent 313c1ab commit 95e4564
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions backend/server/src/handler/ratings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::models::app::AppState;
use crate::models::auth::{
ApplicationCreatorAdminGivenApplicationId, ApplicationReviewerAdminGivenApplicationId,
ApplicationReviewerAdminGivenRatingId, RatingCreator, SuperUser,
ApplicationCreatorGivenApplicationId, ApplicationReviewerGivenApplicationId,
ApplicationReviewerGivenRatingId, RatingCreator, SuperUser,
};
use crate::models::error::ChaosError;
use crate::models::ratings::{NewRating, Rating};
Expand All @@ -17,7 +17,7 @@ impl RatingsHandler {
pub async fn create_rating(
State(state): State<AppState>,
Path(application_id): Path<i64>,
_admin: ApplicationCreatorAdminGivenApplicationId,
_admin: ApplicationCreatorGivenApplicationId,
mut transaction: DBTransaction<'_>,
Json(new_rating): Json<NewRating>,
) -> Result<impl IntoResponse, ChaosError> {
Expand Down Expand Up @@ -47,7 +47,7 @@ impl RatingsHandler {
pub async fn get_ratings_for_application(
State(_state): State<AppState>,
Path(application_id): Path<i64>,
_admin: ApplicationReviewerAdminGivenApplicationId,
_admin: ApplicationReviewerGivenApplicationId,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
let ratings =
Expand All @@ -60,7 +60,7 @@ impl RatingsHandler {
pub async fn get(
State(_state): State<AppState>,
Path(rating_id): Path<i64>,
_admin: ApplicationReviewerAdminGivenRatingId,
_admin: ApplicationReviewerGivenRatingId,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
let org = Rating::get_rating(rating_id, &mut transaction.tx).await?;
Expand All @@ -71,7 +71,7 @@ impl RatingsHandler {
pub async fn delete(
State(_state): State<AppState>,
Path(rating_id): Path<i64>,
_admin: ApplicationReviewerAdminGivenRatingId,
_admin: ApplicationReviewerGivenRatingId,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
Rating::delete(rating_id, &mut transaction.tx).await?;
Expand Down
22 changes: 11 additions & 11 deletions backend/server/src/models/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::service::auth::is_super_user;
use crate::service::jwt::decode_auth_token;
use crate::service::organisation::assert_user_is_admin;
use crate::service::ratings::{
assert_user_is_application_reviewer_admin_given_rating_id, assert_user_is_organisation_member,
assert_user_is_application_reviewer_given_rating_id, assert_user_is_organisation_member,
assert_user_is_rating_creator_and_organisation_member,
};
use axum::extract::{FromRef, FromRequestParts, Path};
Expand Down Expand Up @@ -157,12 +157,12 @@ where
// and ApplicationCreatorAdminGivenApplicationId, but that might change, so separating just in case.

/// Get the application reviewer given a path that contains the application id.
pub struct ApplicationReviewerAdminGivenApplicationId {
pub struct ApplicationReviewerGivenApplicationId {
pub user_id: i64,
}

#[async_trait]
impl<S> FromRequestParts<S> for ApplicationReviewerAdminGivenApplicationId
impl<S> FromRequestParts<S> for ApplicationReviewerGivenApplicationId
where
AppState: FromRef<S>,
S: Send + Sync,
Expand Down Expand Up @@ -194,17 +194,17 @@ where

assert_user_is_organisation_member(user_id, application_id, pool).await?;

Ok(ApplicationReviewerAdminGivenApplicationId { user_id })
Ok(ApplicationReviewerGivenApplicationId { user_id })
}
}

/// Get the application reviewer given a path that contains the application id.
pub struct ApplicationCreatorAdminGivenApplicationId {
pub struct ApplicationCreatorGivenApplicationId {
pub user_id: i64,
}

#[async_trait]
impl<S> FromRequestParts<S> for ApplicationCreatorAdminGivenApplicationId
impl<S> FromRequestParts<S> for ApplicationCreatorGivenApplicationId
where
AppState: FromRef<S>,
S: Send + Sync,
Expand Down Expand Up @@ -236,17 +236,17 @@ where

assert_user_is_organisation_member(user_id, application_id, pool).await?;

Ok(ApplicationCreatorAdminGivenApplicationId { user_id })
Ok(ApplicationCreatorGivenApplicationId { user_id })
}
}

/// Get the application reviewer given a path that contains the rating id.
pub struct ApplicationReviewerAdminGivenRatingId {
pub struct ApplicationReviewerGivenRatingId {
pub user_id: i64,
}

#[async_trait]
impl<S> FromRequestParts<S> for ApplicationReviewerAdminGivenRatingId
impl<S> FromRequestParts<S> for ApplicationReviewerGivenRatingId
where
AppState: FromRef<S>,
S: Send + Sync,
Expand Down Expand Up @@ -276,9 +276,9 @@ where
.await
.map_err(|_| ChaosError::BadRequest)?;

assert_user_is_application_reviewer_admin_given_rating_id(user_id, rating_id, pool).await?;
assert_user_is_application_reviewer_given_rating_id(user_id, rating_id, pool).await?;

Ok(ApplicationReviewerAdminGivenRatingId { user_id })
Ok(ApplicationReviewerGivenRatingId { user_id })
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/server/src/service/ratings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use uuid::Uuid;
/// Any member of the organisation that owns the campaign is an application
/// viewer, because all members are either directors or execs (TODO: might be
/// changed in the future).
pub async fn assert_user_is_application_reviewer_admin_given_rating_id(
pub async fn assert_user_is_application_reviewer_given_rating_id(
user_id: i64,
rating_id: i64,
pool: &Pool<Postgres>,
Expand Down

0 comments on commit 95e4564

Please sign in to comment.