Skip to content

Commit

Permalink
refactor: remove Merchant and Organization parents
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsMani committed Oct 25, 2024
1 parent f3151ad commit 4917cc9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
8 changes: 1 addition & 7 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2902,12 +2902,6 @@ pub enum ParentGroup {
Workflows,
Analytics,
Users,
// TODO: To be deprecated
#[serde(rename = "MerchantAccess")]
Merchant,
// TODO: To be deprecated
#[serde(rename = "OrganizationAccess")]
Organization,
Recon,
Account,
}
Expand All @@ -2934,7 +2928,7 @@ pub enum Resource {
Recon,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, serde::Serialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, serde::Serialize, Hash)]
#[serde(rename_all = "snake_case")]
pub enum PermissionScope {
Read = 0,
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/core/user_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ pub async fn get_parent_group_info(
description,
scopes: PermissionGroup::iter()
.filter_map(|group| (group.parent() == parent_group).then_some(group.scope()))
// TODO: Remove this hashset conversion when merhant access
// and organization access groups are removed
.collect::<HashSet<_>>()
.into_iter()
.collect(),
})
.collect::<Vec<_>>();
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/core/user_role/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ pub async fn get_parent_info_for_role(
.get_permission_groups()
.iter()
.filter_map(|group| (group.parent() == parent_group).then_some(group.scope()))
// TODO: Remove this hashset conversion when merhant access
// and organization access groups are removed
.collect::<HashSet<_>>()
.into_iter()
.collect(),
})
.collect();
Expand Down
4 changes: 1 addition & 3 deletions crates/router/src/services/authorization/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ pub fn get_parent_group_description(group: ParentGroup) -> &'static str {
ParentGroup::Workflows => "Create, modify and delete Routing, 3DS Decision Manager, Surcharge Decision Manager",
ParentGroup::Analytics => "View Analytics",
ParentGroup::Users => "Manage and invite Users to the Team",
ParentGroup::Merchant => "Create, modify and delete Merchant Details like api keys, webhooks, etc",
ParentGroup::Organization =>"Manage organization level tasks like create new Merchant accounts, Organization level roles, etc",
ParentGroup::Account => "Create, modify and delete Merchant Details like api keys, webhooks, etc",
ParentGroup::Recon => "View and manage reconciliation reports",
ParentGroup::Account => "Manage Account Details",
}
}
23 changes: 14 additions & 9 deletions crates/router/src/services/authorization/permission_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ impl PermissionGroupExt for PermissionGroup {
Self::WorkflowsView | Self::WorkflowsManage => ParentGroup::Workflows,
Self::AnalyticsView => ParentGroup::Analytics,
Self::UsersView | Self::UsersManage => ParentGroup::Users,
Self::MerchantDetailsView | Self::MerchantDetailsManage => ParentGroup::Merchant,
Self::OrganizationManage => ParentGroup::Organization,
Self::ReconOps => ParentGroup::Recon,
Self::AccountView | Self::AccountManage => ParentGroup::Account,
Self::MerchantDetailsView
| Self::OrganizationManage
| Self::MerchantDetailsManage
| Self::AccountView
| Self::AccountManage => ParentGroup::Account,
}
}

Expand All @@ -58,10 +60,14 @@ impl PermissionGroupExt for PermissionGroup {
Self::ConnectorsView => vec![Self::ConnectorsView],
Self::ConnectorsManage => vec![Self::ConnectorsView, Self::ConnectorsManage],

Self::WorkflowsView => vec![Self::WorkflowsView],
Self::WorkflowsManage => vec![Self::WorkflowsView, Self::WorkflowsManage],
Self::WorkflowsView => vec![Self::WorkflowsView, Self::ConnectorsView],
Self::WorkflowsManage => vec![
Self::WorkflowsView,
Self::WorkflowsManage,
Self::ConnectorsView,
],

Self::AnalyticsView => vec![Self::AnalyticsView],
Self::AnalyticsView => vec![Self::AnalyticsView, Self::OperationsView],

Self::UsersView => vec![Self::UsersView],
Self::UsersManage => {
Expand Down Expand Up @@ -99,7 +105,7 @@ impl ParentGroupExt for ParentGroup {
Self::Workflows => WORKFLOWS.to_vec(),
Self::Analytics => ANALYTICS.to_vec(),
Self::Users => USERS.to_vec(),
Self::Merchant | Self::Organization | Self::Account => ACCOUNT.to_vec(),
Self::Account => ACCOUNT.to_vec(),
Self::Recon => RECON.to_vec(),
}
}
Expand Down Expand Up @@ -146,11 +152,10 @@ pub static OPERATIONS: [Resource; 8] = [

pub static CONNECTORS: [Resource; 2] = [Resource::Connector, Resource::Account];

pub static WORKFLOWS: [Resource; 5] = [
pub static WORKFLOWS: [Resource; 4] = [
Resource::Routing,
Resource::ThreeDsDecisionManager,
Resource::SurchargeDecisionManager,
Resource::Connector,
Resource::Account,
];

Expand Down
10 changes: 4 additions & 6 deletions crates/router/src/services/authorization/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,16 @@ pub fn get_resource_name(resource: &Resource, entity_type: &EntityType) -> &'sta
(Resource::Mandate, _) => "Mandates",
(Resource::Customer, _) => "Customers",
(Resource::Payout, _) => "Payouts",
(Resource::ApiKey, _) => "ApiKeys",
(Resource::Connector, _) => {
"Payment Processors, Payout Processors and Fraud & Risk Managers"
}
(Resource::ApiKey, _) => "Api Keys",
(Resource::Connector, _) => "Payment Processors, Payout Processors, Fraud & Risk Managers",
(Resource::Routing, _) => "Routing",
(Resource::ThreeDsDecisionManager, _) => "3DS Decision Manager",
(Resource::SurchargeDecisionManager, _) => "Surcharge Decision Manager",
(Resource::Analytics, _) => "Analytics",
(Resource::Report, _) => "Reports",
(Resource::Report, _) => "Operation Reports",
(Resource::User, _) => "Users",
(Resource::WebhookEvent, _) => "Webhook Events",
(Resource::Recon, _) => "Recon",
(Resource::Recon, _) => "Reconciliation Reports",
(Resource::Account, EntityType::Profile) => "Business Profile Account",
(Resource::Account, EntityType::Merchant) => "Merchant Account",
(Resource::Account, EntityType::Organization) => "Organization Account",
Expand Down

0 comments on commit 4917cc9

Please sign in to comment.