Skip to content

Commit

Permalink
refactor: remove permissions for payment link and add for apple pay
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsMani committed Nov 24, 2023
1 parent ce45d0d commit fc9a153
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
3 changes: 3 additions & 0 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "olap")]
pub mod user;

// ID generation
Expand Down Expand Up @@ -57,3 +58,5 @@ pub const LOCKER_REDIS_EXPIRY_SECONDS: u32 = 60 * 15; // 15 minutes

#[cfg(any(feature = "olap", feature = "oltp"))]
pub const JWT_TOKEN_TIME_IN_SECS: u64 = 60 * 60 * 24 * 2; // 2 days

pub const ROLE_ID_ORGANIZATION_ADMIN: &str = "org_admin";
5 changes: 0 additions & 5 deletions crates/router/src/consts/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
#[cfg(feature = "olap")]
pub const MAX_NAME_LENGTH: usize = 70;
#[cfg(feature = "olap")]
pub const MAX_COMPANY_NAME_LENGTH: usize = 70;

// USER ROLES
pub const ROLE_ID_ORGANIZATION_ADMIN: &str = "org_admin";
4 changes: 1 addition & 3 deletions crates/router/src/core/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use masking::{ExposeInterface, Secret};
use router_env::env;

use super::errors::{UserErrors, UserResponse};
use crate::{
consts::user as consts, routes::AppState, services::ApplicationResponse, types::domain,
};
use crate::{consts, routes::AppState, services::ApplicationResponse, types::domain};

pub async fn connect_account(
state: AppState,
Expand Down
8 changes: 2 additions & 6 deletions crates/router/src/routes/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use router_env::{instrument, tracing, Flow};

use crate::{
core::{api_locking, payment_link::*},
services::{api, authentication as auth, authorization::permissions::Permission},
services::{api, authentication as auth},
AppState,
};

Expand Down Expand Up @@ -118,11 +118,7 @@ pub async fn payments_link_list(
&req,
payload,
|state, auth, payload| list_payment_link(state, auth.merchant_account, payload),
auth::auth_type(
&auth::ApiKeyAuth,
&auth::JWTAuth(Permission::PaymentLinkRead),
req.headers(),
),
&auth::ApiKeyAuth,
api_locking::LockAction::NotApplicable,
)
.await
Expand Down
14 changes: 11 additions & 3 deletions crates/router/src/routes/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use router_env::{instrument, tracing, Flow};
use super::app::AppState;
use crate::{
core::{api_locking, verification},
services::{api, authentication as auth},
services::{api, authentication as auth, authorization::permissions::Permission},
};

#[instrument(skip_all, fields(flow = ?Flow::Verification))]
Expand All @@ -32,7 +32,11 @@ pub async fn apple_pay_merchant_registration(
merchant_id.clone(),
)
},
&auth::ApiKeyAuth,
auth::auth_type(
&auth::ApiKeyAuth,
&auth::JWTAuth(Permission::MerchantAccountWrite),
req.headers(),
),
api_locking::LockAction::NotApplicable,
))
.await
Expand Down Expand Up @@ -60,7 +64,11 @@ pub async fn retrieve_apple_pay_verified_domains(
mca_id.to_string(),
)
},
&auth::ApiKeyAuth,
auth::auth_type(
&auth::ApiKeyAuth,
&auth::JWTAuth(Permission::MerchantAccountRead),
req.headers(),
),
api_locking::LockAction::NotApplicable,
)
.await
Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/services/authorization/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub enum Permission {
UsersRead,
UsersWrite,
MerchantAccountCreate,
PaymentLinkRead,
}

impl Permission {
Expand Down Expand Up @@ -70,7 +69,6 @@ impl Permission {
Self::UsersRead => Some("View all the users for a merchant"),
Self::UsersWrite => Some("Invite users, assign and update roles"),
Self::MerchantAccountCreate => None,
Self::PaymentLinkRead => Some("View all Payment Links"),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl RoleInfo {
pub static PREDEFINED_PERMISSIONS: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|| {
let mut roles = HashMap::new();
roles.insert(
consts::user::ROLE_ID_ORGANIZATION_ADMIN,
consts::ROLE_ID_ORGANIZATION_ADMIN,
RoleInfo {
permissions: vec![
Permission::PaymentRead,
Expand Down Expand Up @@ -58,7 +58,6 @@ pub static PREDEFINED_PERMISSIONS: Lazy<HashMap<&'static str, RoleInfo>> = Lazy:
Permission::UsersRead,
Permission::UsersWrite,
Permission::MerchantAccountCreate,
Permission::PaymentLinkRead,
],
name: Some("Organization Admin"),
is_invitable: false,
Expand Down

0 comments on commit fc9a153

Please sign in to comment.