Skip to content

Commit

Permalink
chore: resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kashif-m committed Nov 20, 2024
1 parent dbe8f6b commit 02c7b0d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 26 deletions.
2 changes: 0 additions & 2 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2798,7 +2798,6 @@ pub enum PermissionGroup {
OrganizationManage,
AccountView,
AccountManage,
ReconTokenView,
ReconReportsView,
ReconReportsManage,
ReconOpsView,
Expand All @@ -2815,7 +2814,6 @@ pub enum ParentGroup {
Workflows,
Analytics,
Users,
Recon,
ReconOps,
ReconReports,
Account,
Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/services/authorization/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ fn get_group_description(group: PermissionGroup) -> &'static str {
PermissionGroup::MerchantDetailsView | PermissionGroup::AccountView => "View Merchant Details",
PermissionGroup::MerchantDetailsManage | PermissionGroup::AccountManage => "Create, modify and delete Merchant Details like api keys, webhooks, etc",
PermissionGroup::OrganizationManage => "Manage organization level tasks like create new Merchant accounts, Organization level roles, etc",
PermissionGroup::ReconTokenView => "Generate and Verify reconciliation tokens",
PermissionGroup::ReconReportsView => "View and access reconciliation reports and analytics",
PermissionGroup::ReconReportsManage => "Manage reconciliation reports",
PermissionGroup::ReconOpsView => "View and access reconciliation operations",
Expand All @@ -56,7 +55,6 @@ pub fn get_parent_group_description(group: ParentGroup) -> &'static str {
ParentGroup::Analytics => "View Analytics",
ParentGroup::Users => "Manage and invite Users to the Team",
ParentGroup::Account => "Create, modify and delete Merchant Details like api keys, webhooks, etc",
ParentGroup::Recon => "Generate and verify reconciliation tokens",
ParentGroup::ReconOps => "View, manage reconciliation operations like upload and process files, run reconciliation etc",
ParentGroup::ReconReports => "View, manage reconciliation reports and analytics",
}
Expand Down
7 changes: 0 additions & 7 deletions crates/router/src/services/authorization/permission_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ impl PermissionGroupExt for PermissionGroup {
| Self::UsersView
| Self::MerchantDetailsView
| Self::AccountView
| Self::ReconTokenView
| Self::ReconOpsView
| Self::ReconReportsView => PermissionScope::Read,

Expand Down Expand Up @@ -50,7 +49,6 @@ impl PermissionGroupExt for PermissionGroup {
| Self::MerchantDetailsManage
| Self::AccountView
| Self::AccountManage => ParentGroup::Account,
Self::ReconTokenView => ParentGroup::Recon,
Self::ReconOpsView | Self::ReconOpsManage => ParentGroup::ReconOps,
Self::ReconReportsView | Self::ReconReportsManage => ParentGroup::ReconReports,
}
Expand Down Expand Up @@ -82,8 +80,6 @@ impl PermissionGroupExt for PermissionGroup {
vec![Self::UsersView, Self::UsersManage]
}

Self::ReconTokenView => vec![Self::ReconTokenView],

Self::ReconOpsView => vec![Self::ReconOpsView],
Self::ReconOpsManage => vec![Self::ReconOpsView, Self::ReconOpsManage],

Expand Down Expand Up @@ -120,7 +116,6 @@ impl ParentGroupExt for ParentGroup {
Self::Analytics => ANALYTICS.to_vec(),
Self::Users => USERS.to_vec(),
Self::Account => ACCOUNT.to_vec(),
Self::Recon => RECON.to_vec(),
Self::ReconOps => RECON_OPS.to_vec(),
Self::ReconReports => RECON_REPORTS.to_vec(),
}
Expand Down Expand Up @@ -181,8 +176,6 @@ pub static USERS: [Resource; 2] = [Resource::User, Resource::Account];

pub static ACCOUNT: [Resource; 3] = [Resource::Account, Resource::ApiKey, Resource::WebhookEvent];

pub static RECON: [Resource; 1] = [Resource::ReconToken];

pub static RECON_OPS: [Resource; 5] = [
Resource::ReconToken,
Resource::ReconFiles,
Expand Down
21 changes: 12 additions & 9 deletions crates/router/src/services/authorization/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use api_models::enums::ReconPermissionScope;
use common_enums::{EntityType, PermissionGroup, Resource, RoleScope};
use common_utils::{errors::CustomResult, id_type};

#[cfg(feature = "recon")]
use super::permission_groups::{RECON_OPS, RECON_REPORTS};
use super::{permission_groups::PermissionGroupExt, permissions::Permission};
use crate::{core::errors, routes::SessionState};

Expand Down Expand Up @@ -85,14 +87,16 @@ impl RoleInfo {
#[cfg(feature = "recon")]
pub fn get_recon_acl(&self) -> HashMap<Resource, ReconPermissionScope> {
let mut acl: HashMap<Resource, ReconPermissionScope> = HashMap::new();
let mut recon_resources = RECON_OPS.to_vec();
recon_resources.extend(RECON_REPORTS);
let recon_internal_resources = [Resource::ReconToken];
self.get_permission_groups()
.iter()
.for_each(|permission_group| match permission_group {
PermissionGroup::ReconOpsView
| PermissionGroup::ReconOpsManage
| PermissionGroup::ReconReportsView
| PermissionGroup::ReconReportsManage => {
permission_group.resources().iter().for_each(|resource| {
.for_each(|permission_group| {
permission_group.resources().iter().for_each(|resource| {
if recon_resources.contains(resource)
&& !recon_internal_resources.contains(resource)
{
let scope = match resource {
Resource::ReconAndSettlementAnalytics => ReconPermissionScope::Read,
_ => ReconPermissionScope::from(permission_group.scope()),
Expand All @@ -106,9 +110,8 @@ impl RoleInfo {
}
})
.or_insert(scope);
})
}
_ => (),
}
})
});
acl
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub static PREDEFINED_ROLES: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|
PermissionGroup::MerchantDetailsManage,
PermissionGroup::AccountManage,
PermissionGroup::OrganizationManage,
PermissionGroup::ReconTokenView,
PermissionGroup::ReconOpsManage,
PermissionGroup::ReconReportsManage,
],
Expand All @@ -53,7 +52,6 @@ pub static PREDEFINED_ROLES: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|
PermissionGroup::UsersView,
PermissionGroup::MerchantDetailsView,
PermissionGroup::AccountView,
PermissionGroup::ReconTokenView,
PermissionGroup::ReconOpsView,
PermissionGroup::ReconReportsView,
],
Expand Down Expand Up @@ -87,7 +85,6 @@ pub static PREDEFINED_ROLES: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|
PermissionGroup::MerchantDetailsManage,
PermissionGroup::AccountManage,
PermissionGroup::OrganizationManage,
PermissionGroup::ReconTokenView,
PermissionGroup::ReconOpsManage,
PermissionGroup::ReconReportsManage,
],
Expand Down Expand Up @@ -120,7 +117,6 @@ pub static PREDEFINED_ROLES: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|
PermissionGroup::AccountView,
PermissionGroup::MerchantDetailsManage,
PermissionGroup::AccountManage,
PermissionGroup::ReconTokenView,
PermissionGroup::ReconOpsManage,
PermissionGroup::ReconReportsManage,
],
Expand All @@ -145,7 +141,6 @@ pub static PREDEFINED_ROLES: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|
PermissionGroup::UsersView,
PermissionGroup::MerchantDetailsView,
PermissionGroup::AccountView,
PermissionGroup::ReconTokenView,
PermissionGroup::ReconOpsView,
PermissionGroup::ReconReportsView,
],
Expand Down Expand Up @@ -287,7 +282,6 @@ pub static PREDEFINED_ROLES: Lazy<HashMap<&'static str, RoleInfo>> = Lazy::new(|
PermissionGroup::UsersView,
PermissionGroup::MerchantDetailsView,
PermissionGroup::AccountView,
PermissionGroup::ReconTokenView,
PermissionGroup::ReconOpsView,
PermissionGroup::ReconReportsView,
],
Expand Down

0 comments on commit 02c7b0d

Please sign in to comment.