Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(user_roles): Add `recon roles` and `product_type` filtering (#11775)

Grovy-3170b908ce364b5d
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index b61823fcb4..d876ca5981 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -137,6 +137,7 @@ crates/router/src/types/api/verify_connector @juspay/hyperswitch-dashboard
crates/router/src/types/api/verify_connector.rs @juspay/hyperswitch-dashboard
crates/router/src/types/domain/user @juspay/hyperswitch-dashboard
crates/router/src/types/domain/user.rs @juspay/hyperswitch-dashboard
+crates/router/src/types/domain/role.rs @juspay/hyperswitch-dashboard
crates/router/src/types/storage/user.rs @juspay/hyperswitch-dashboard
crates/router/src/types/storage/user_role.rs @juspay/hyperswitch-dashboard
crates/router/src/types/storage/dashboard_metadata.rs @juspay/hyperswitch-dashboard
diff --git a/crates/api_models/src/events/user.rs b/crates/api_models/src/events/user.rs
index 3948365911..0f833aadd3 100644
--- a/crates/api_models/src/events/user.rs
+++ b/crates/api_models/src/events/user.rs
@@ -12,20 +12,20 @@ use crate::user::{
GetMetaDataRequest, GetMetaDataResponse, GetMultipleMetaDataPayload, SetMetaDataRequest,
},
AcceptInviteFromEmailRequest, AcceptInviteResponse, AuthSelectRequest, AuthorizeResponse,
- BeginTotpResponse, ChangePasswordRequest, CloneConnectorRequest, ConnectAccountRequest,
- CreateInternalUserRequest, CreateTenantUserRequest, CreateUserAuthenticationMethodRequest,
- CreateUserAuthenticationMethodResponse, EmbeddedTokenInfoResponse, ForgotPasswordRequest,
- GetSsoAuthUrlRequest, GetUserAuthenticationMethodsRequest, GetUserDetailsResponse,
- GetUserInternalDetailsResponse, GetUserRoleDetailsRequest, GetUserRoleDetailsResponseV2,
- InviteUserRequest, IssueEmbeddedTokenResponse, ListUsersInternalRequest,
- ListUsersInternalResponse, PlatformAccountCreateRequest, PlatformAccountCreateResponse,
- ReInviteUserRequest, RecoveryCodes, ResetPasswordRequest, RotatePasswordRequest,
- SendVerifyEmailRequest, SignUpRequest, SignUpWithMerchantIdRequest, SsoSignInRequest,
- SwitchMerchantRequest, SwitchOrganizationRequest, SwitchProfileRequest, TokenResponse,
- TwoFactorAuthStatusResponse, TwoFactorStatus, UpdateUserAccountDetailsRequest,
- UpdateUserAuthenticationMethodRequest, UserFromEmailRequest, UserMerchantAccountResponse,
- UserMerchantCreate, UserOrgMerchantCreateRequest, VerifyEmailRequest,
- VerifyRecoveryCodeRequest, VerifyTotpRequest,
+ AuthorizeTokenRequest, BeginTotpResponse, ChangePasswordRequest, CloneConnectorRequest,
+ ConnectAccountRequest, CreateInternalUserRequest, CreateTenantUserRequest,
+ CreateUserAuthenticationMethodRequest, CreateUserAuthenticationMethodResponse,
+ EmbeddedTokenInfoResponse, ForgotPasswordRequest, GetSsoAuthUrlRequest,
+ GetUserAuthenticationMethodsRequest, GetUserDetailsResponse, GetUserInternalDetailsResponse,
+ GetUserRoleDetailsRequest, GetUserRoleDetailsResponseV2, InviteUserRequest,
+ IssueEmbeddedTokenResponse, ListUsersInternalRequest, ListUsersInternalResponse,
+ PlatformAccountCreateRequest, PlatformAccountCreateResponse, ReInviteUserRequest,
+ RecoveryCodes, ResetPasswordRequest, RotatePasswordRequest, SendVerifyEmailRequest,
+ SignUpRequest, SignUpWithMerchantIdRequest, SsoSignInRequest, SwitchMerchantRequest,
+ SwitchOrganizationRequest, SwitchProfileRequest, TokenResponse, TwoFactorAuthStatusResponse,
+ TwoFactorStatus, UpdateUserAccountDetailsRequest, UpdateUserAuthenticationMethodRequest,
+ UserFromEmailRequest, UserMerchantAccountResponse, UserMerchantCreate,
+ UserOrgMerchantCreateRequest, VerifyEmailRequest, VerifyRecoveryCodeRequest, VerifyTotpRequest,
};
common_utils::impl_api_event_type!(
@@ -83,7 +83,8 @@ common_utils::impl_api_event_type!(
EmbeddedTokenInfoResponse,
GetUserInternalDetailsResponse,
ListUsersInternalRequest,
- ListUsersInternalResponse
+ ListUsersInternalResponse,
+ AuthorizeTokenRequest
)
);
diff --git a/crates/api_models/src/user.rs b/crates/api_models/src/user.rs
index 9a98cbbd12..c0354232e6 100644
--- a/crates/api_models/src/user.rs
+++ b/crates/api_models/src/user.rs
@@ -508,3 +508,9 @@ pub struct GetUserInternalDetailsResponse {
pub struct ListUsersInternalResponse {
pub users: Vec<GetUserInternalDetailsResponse>,
}
+
+#[derive(Debug, serde::Deserialize, serde::Serialize)]
+pub struct AuthorizeTokenRequest {
+ pub token: Secret<String>,
+ pub permission: String,
+}
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index f5f1976f4d..59e6cdf205 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -9528,6 +9528,14 @@ pub enum PermissionGroup {
InternalManage,
ThemeView,
ThemeManage,
+ ReconSourcesView,
+ ReconSourcesManage,
+ ReconExceptionsView,
+ ReconExceptionsManage,
+ ReconTransactionsView,
+ ReconTransactionsManage,
+ ReconRulesView,
+ ReconRulesManage,
}
#[derive(
@@ -9544,6 +9552,10 @@ pub enum ParentGroup {
Account,
Internal,
Theme,
+ ReconSources,
+ ReconExceptions,
+ ReconTransactions,
+ ReconRules,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
@@ -9576,6 +9588,12 @@ pub enum Resource {
Subscription,
InternalConnector,
Theme,
+ ReconIngestion,
+ ReconTransformation,
+ ReconException,
+ ReconStagingEntry,
+ ReconTransaction,
+ ReconRule,
}
#[derive(
diff --git a/crates/diesel_models/src/role.rs b/crates/diesel_models/src/role.rs
index 67fb04099c..5e1b294f10 100644
--- a/crates/diesel_models/src/role.rs
+++ b/crates/diesel_models/src/role.rs
@@ -21,6 +21,7 @@ pub struct Role {
pub entity_type: enums::EntityType,
pub profile_id: Option<id_type::ProfileId>,
pub tenant_id: id_type::TenantId,
+ pub merchant_product_type: Option<enums::MerchantProductType>,
}
#[derive(router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
@@ -40,6 +41,7 @@ pub struct RoleNew {
pub entity_type: enums::EntityType,
pub profile_id: Option<id_type::ProfileId>,
pub tenant_id: id_type::TenantId,
+ pub merchant_product_type: Option<enums::MerchantProductType>,
}
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 7013e26d71..f6fd4a1351 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -1666,6 +1666,8 @@ diesel::table! {
profile_id -> Nullable<Varchar>,
#[max_length = 64]
tenant_id -> Varchar,
+ #[max_length = 64]
+ merchant_product_type -> Nullable<Varchar>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 600ed9fc5f..f129f0195f 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -1601,6 +1601,8 @@ diesel::table! {
profile_id -> Nullable<Varchar>,
#[max_length = 64]
tenant_id -> Varchar,
+ #[max_length = 64]
+ merchant_product_type -> Nullable<Varchar>,
}
}
diff --git a/crates/router/src/consts/user_role.rs b/crates/router/src/consts/user_role.rs
index 3cc2cb2688..1ddb80226d 100644
--- a/crates/router/src/consts/user_role.rs
+++ b/crates/router/src/consts/user_role.rs
@@ -15,3 +15,13 @@ pub const ROLE_ID_PROFILE_CUSTOMER_SUPPORT: &str = "profile_customer_support";
pub const INTERNAL_USER_MERCHANT_ID: &str = "juspay000";
pub const MAX_ROLE_NAME_LENGTH: usize = 64;
+
+pub const ROLE_ID_RECON_MERCHANT_ADMIN: &str = "recon_merchant_admin";
+pub const ROLE_ID_RECON_MERCHANT_DATA_ENGINEER: &str = "recon_merchant_data_engineer";
+pub const ROLE_ID_RECON_MERCHANT_OPERATOR: &str = "recon_merchant_operator";
+pub const ROLE_ID_RECON_MERCHANT_VIEW_ONLY: &str = "recon_merchant_view_only";
+
+pub const ROLE_ID_RECON_PROFILE_ADMIN: &str = "recon_profile_admin";
+pub const ROLE_ID_RECON_PROFILE_DATA_ENGINEER: &str = "recon_profile_data_engineer";
+pub const ROLE_ID_RECON_PROFILE_OPERATOR: &str = "recon_profile_operator";
+pub const ROLE_ID_RECON_PROFILE_VIEW_ONLY: &str = "recon_profile_view_only";
diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs
index c962974510..c3ab7b8449 100644
--- a/crates/router/src/core/user.rs
+++ b/crates/router/src/core/user.rs
@@ -7,7 +7,7 @@ use api_models::{
payments::RedirectionResponse,
user::{self as user_api, InviteMultipleUserResponse, NameIdUnit},
};
-use common_enums::{connector_enums, EntityType, UserAuthType};
+use common_enums::{connector_enums, EntityType, MerchantProductType, UserAuthType};
use common_utils::{
fp_utils, type_name,
types::{keymanager::Identifier, user::LineageContext},
@@ -24,12 +24,14 @@ use error_stack::{report, ResultExt};
use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};
use router_env::{env, logger};
use storage_impl::errors::StorageError;
+#[cfg(feature = "v1")]
+use subscriptions::RouterResponse;
#[cfg(not(feature = "email"))]
use user_api::dashboard_metadata::SetMetaDataRequest;
-#[cfg(feature = "v1")]
-use super::admin;
use super::errors::{StorageErrorExt, UserErrors, UserResponse, UserResult};
+#[cfg(feature = "v1")]
+use super::{admin, errors::ApiErrorResponse};
use crate::{
consts,
core::encryption::send_request_to_key_service_for_user,
@@ -38,7 +40,11 @@ use crate::{
user_role::ListUserRolesByUserIdPayload,
},
routes::{app::ReqState, SessionState},
- services::{authentication as auth, authorization::roles, openidconnect, ApplicationResponse},
+ services::{
+ authentication::{self as auth, blacklist::BlackList},
+ authorization::{self, permissions::Permission, roles},
+ openidconnect, ApplicationResponse,
+ },
types::{domain, transformers::ForeignInto},
utils::{
self,
@@ -732,6 +738,40 @@ async fn handle_invitation(
.attach_printable(format!("role_id = {} is not invitable", request.role_id))?;
}
+ match req_role_info.get_entity_type() {
+ EntityType::Tenant | EntityType::Organization => {}
+ EntityType::Merchant | EntityType::Profile => {
+ let merchant_key_store = state
+ .store
+ .get_merchant_key_store_by_merchant_id(
+ &user_from_token.merchant_id,
+ &state.store.get_master_key().to_vec().into(),
+ )
+ .await
+ .change_context(UserErrors::InternalServerError)
+ .attach_printable("Failed to retrieve merchant key store by merchant_id")?;
+
+ let merchant_account = state
+ .store
+ .find_merchant_account_by_merchant_id(
+ &user_from_token.merchant_id,
+ &merchant_key_store,
+ )
+ .await
+ .to_not_found_response(UserErrors::MerchantIdNotFound)?;
+
+ let merchant_product_type = merchant_account
+ .product_type
+ .unwrap_or(MerchantProductType::Orchestration);
+ if req_role_info.get_merchant_product_type() != merchant_product_type {
+ Err(report!(UserErrors::InvalidRoleId)).attach_printable(format!(
+ "role_id = {} is not for product_type = {}",
+ request.role_id, merchant_product_type
+ ))?;
+ }
+ }
+ }
+
let invitee_email = domain::UserEmail::from_pii_email(request.email.clone())?;
let invitee_user = state
.global_store
@@ -4136,3 +4176,28 @@ pub async fn list_members_for_entity(
},
))
}
+
+#[cfg(feature = "v1")]
+pub async fn authorize_token(
+ state: SessionState,
+ payload: user_api::AuthorizeTokenRequest,
+) -> RouterResponse<()> {
+ let permission: Permission =
+ payload
+ .permission
+ .parse()
+ .map_err(|_| ApiErrorResponse::InvalidRequestData {
+ message: "Invalid permission".to_string(),
+ })?;
+
+ let token = auth::decode_jwt::<auth::AuthToken>(&payload.token.expose(), &state).await?;
+
+ if token.check_in_blacklist(&state).await? {
+ return Err(ApiErrorResponse::InvalidJwtToken.into());
+ }
+
+ let role_info = authorization::get_role_info(&state, &token).await?;
+ authorization::check_permission(permission, &role_info)?;
+
+ Ok(ApplicationResponse::StatusOk)
+}
diff --git a/crates/router/src/core/user_role/role.rs b/crates/router/src/core/user_role/role.rs
index 81d5153d9b..036500acac 100644
--- a/crates/router/src/core/user_role/role.rs
+++ b/crates/router/src/core/user_role/role.rs
@@ -1,7 +1,7 @@
use std::{cmp, collections::HashSet, ops::Not};
use api_models::user_role::role as role_api;
-use common_enums::{EntityType, ParentGroup, PermissionGroup};
+use common_enums::{EntityType, MerchantProductType, ParentGroup, PermissionGroup};
use common_utils::generate_id_with_default_len;
use diesel_models::role::{ListRolesByEntityPayload, RoleNew, RoleUpdate};
use error_stack::{report, ResultExt};
@@ -116,7 +116,35 @@ pub async fn create_role(
let role_name = RoleName::new(req.role_name)?;
- utils::user_role::validate_role_groups(&req.groups)?;
+ let merchant_key_store = state
+ .store
+ .get_merchant_key_store_by_merchant_id(
+ &user_from_token.merchant_id,
+ &state.store.get_master_key().to_vec().into(),
+ )
+ .await
+ .change_context(UserErrors::InternalServerError)
+ .attach_printable("Failed to retrieve merchant key store by merchant_id")?;
+
+ let merchant_account = state
+ .store
+ .find_merchant_account_by_merchant_id(&user_from_token.merchant_id, &merchant_key_store)
+ .await
+ .to_not_found_response(UserErrors::MerchantIdNotFound)?;
+
+ let merchant_product_type = merchant_account
+ .product_type
+ .unwrap_or(MerchantProductType::Orchestration);
+
+ match role_entity_type {
+ EntityType::Tenant | EntityType::Organization => {
+ utils::user_role::validate_role_groups(&req.groups, None)?
+ }
+ EntityType::Merchant | EntityType::Profile => {
+ utils::user_role::validate_role_groups(&req.groups, Some(merchant_product_type))?
+ }
+ };
+
utils::user_role::validate_role_name(
&state,
&role_name,
@@ -161,6 +189,9 @@ pub async fn create_role(
last_modified_at: now,
profile_id,
tenant_id: user_from_token.tenant_id.unwrap_or(state.tenant.tenant_id),
+ // TODO: Set this to null when custom roles at org level are enabled, since product type is currently a merchant-level concept only.
+ // Ensure this column is backfilled during migration.
+ merchant_product_type: Some(merchant_product_type),
})
.await
.to_duplicate_response(UserErrors::RoleNameAlreadyExists)?;
@@ -218,7 +249,35 @@ pub async fn create_role_v2(
let permission_groups =
utils::user_role::parent_group_info_request_to_permission_groups(&req.parent_groups)?;
- utils::user_role::validate_role_groups(&permission_groups)?;
+ let merchant_key_store = state
+ .store
+ .get_merchant_key_store_by_merchant_id(
+ &user_from_token.merchant_id,
+ &state.store.get_master_key().to_vec().into(),
+ )
+ .await
+ .change_context(UserErrors::InternalServerError)
+ .attach_printable("Failed to retrieve merchant key store by merchant_id")?;
+
+ let merchant_account = state
+ .store
+ .find_merchant_account_by_merchant_id(&user_from_token.merchant_id, &merchant_key_store)
+ .await
+ .to_not_found_response(UserErrors::MerchantIdNotFound)?;
+
+ let merchant_product_type = merchant_account
+ .product_type
+ .unwrap_or(MerchantProductType::Orchestration);
+
+ match role_entity_type {
+ EntityType::Tenant | EntityType::Organization => {
+ utils::user_role::validate_role_groups(&permission_groups, None)?
+ }
+ EntityType::Merchant | EntityType::Profile => {
+ utils::user_role::validate_role_groups(&permission_groups, Some(merchant_product_type))?
+ }
+ }
+
utils::user_role::validate_role_name(
&state,
&role_name,
@@ -263,6 +322,9 @@ pub async fn create_role_v2(
last_modified_at: now,
profile_id,
tenant_id: user_from_token.tenant_id.unwrap_or(state.tenant.tenant_id),
+ // TODO: Set this to null when custom roles at org level are enabled, since product type is currently a merchant-level concept only.
+ // Ensure this column is backfilled during migration.
+ merchant_product_type: Some(merchant_product_type),
})
.await
.to_duplicate_response(UserErrors::RoleNameAlreadyExists)?;
@@ -439,7 +501,37 @@ pub async fn update_role(
}
if let Some(ref groups) = req.groups {
- utils::user_role::validate_role_groups(groups)?;
+ let merchant_product_type = match role_info.get_entity_type() {
+ EntityType::Tenant | EntityType::Organization => None,
+ EntityType::Merchant | EntityType::Profile => {
+ let merchant_key_store = state
+ .store
+ .get_merchant_key_store_by_merchant_id(
+ &user_from_token.merchant_id,
+ &state.store.get_master_key().to_vec().into(),
+ )
+ .await
+ .change_context(UserErrors::InternalServerError)
+ .attach_printable("Failed to retrieve merchant key store by merchant_id")?;
+
+ let merchant_account = state
+ .store
+ .find_merchant_account_by_merchant_id(
+ &user_from_token.merchant_id,
+ &merchant_key_store,
+ )
+ .await
+ .to_not_found_response(UserErrors::MerchantIdNotFound)?;
+
+ Some(
+ merchant_account
+ .product_type
+ .unwrap_or(MerchantProductType::Orchestration),
+ )
+ }
+ };
+
+ utils::user_role::validate_role_groups(groups, merchant_product_type)?;
}
let updated_role = state
@@ -643,6 +735,7 @@ pub async fn list_roles_at_entity_level(
.to_owned();
let is_lineage_data_required = false;
+ let merchant_id = user_from_token.merchant_id.clone();
let custom_roles = match req.entity_type {
EntityType::Tenant | EntityType::Organization => state
.global_store
@@ -659,7 +752,7 @@ pub async fn list_roles_at_entity_level(
EntityType::Merchant => state
.global_store
.generic_list_roles_by_entity_type(
- ListRolesByEntityPayload::Merchant(user_from_token.merchant_id),
+ ListRolesByEntityPayload::Merchant(merchant_id),
is_lineage_data_required,
tenant_id,
user_from_token.org_id,
@@ -671,10 +764,7 @@ pub async fn list_roles_at_entity_level(
EntityType::Profile => state
.global_store
.generic_list_roles_by_entity_type(
- ListRolesByEntityPayload::Profile(
- user_from_token.merchant_id,
- user_from_token.profile_id,
- ),
+ ListRolesByEntityPayload::Profile(merchant_id, user_from_token.profile_id),
is_lineage_data_required,
tenant_id,
user_from_token.org_id,
@@ -686,6 +776,36 @@ pub async fn list_roles_at_entity_level(
role_info_vec.extend(custom_roles.into_iter().map(roles::RoleInfo::from));
+ match req.entity_type {
+ EntityType::Tenant | EntityType::Organization => {}
+ EntityType::Merchant | EntityType::Profile => {
+ let merchant_key_store = state
+ .store
+ .get_merchant_key_store_by_merchant_id(
+ &user_from_token.merchant_id,
+ &state.store.get_master_key().to_vec().into(),
+ )
+ .await
+ .change_context(UserErrors::InternalServerError)
+ .attach_printable("Failed to retrieve merchant key store by merchant_id")?;
+
+ let product_type = state
+ .store
+ .find_merchant_account_by_merchant_id(
+ &user_from_token.merchant_id,
+ &merchant_key_store,
+ )
+ .await
+ .map(|merchant_account| {
+ merchant_account
+ .product_type
+ .unwrap_or(MerchantProductType::Orchestration)
+ })
+ .to_not_found_response(UserErrors::MerchantIdNotFound)?;
+ role_info_vec.retain(|role_info| role_info.get_merchant_product_type() == product_type);
+ }
+ }
+
let list_minimal_role_info = role_info_vec
.into_iter()
.filter_map(|role_info| {
diff --git a/crates/router/src/db/role.rs b/crates/router/src/db/role.rs
index ecb962d8d2..7e5131438a 100644
--- a/crates/router/src/db/role.rs
+++ b/crates/router/src/db/role.rs
@@ -227,6 +227,7 @@ impl RoleInterface for MockDb {
last_modified_by: role.last_modified_by,
profile_id: role.profile_id,
tenant_id: role.tenant_id,
+ merchant_product_type: role.merchant_product_type,
};
roles.push(role.clone());
Ok(role)
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index b1b2dad037..8485aed744 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -3144,7 +3144,8 @@ impl User {
)
.service(
web::resource("/members").route(web::get().to(user::list_members_for_entity)),
- ),
+ )
+ .service(web::resource("/authorize").route(web::post().to(user::authorize_token))),
);
route
diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rs
index 83f9aa5803..be4bed22fe 100644
--- a/crates/router/src/routes/lock_utils.rs
+++ b/crates/router/src/routes/lock_utils.rs
@@ -346,7 +346,8 @@ impl From<Flow> for ApiIdentifier {
| Flow::CreateRoleV2
| Flow::UpdateRole
| Flow::UserFromEmail
- | Flow::ListUsersInLineage => Self::UserRole,
+ | Flow::ListUsersInLineage
+ | Flow::AuthorizeUserToken => Self::UserRole,
Flow::GetActionUrl | Flow::SyncOnboardingStatus | Flow::ResetTrackingId => {
Self::ConnectorOnboarding
}
diff --git a/crates/router/src/routes/user.rs b/crates/router/src/routes/user.rs
index 2eec75f0fe..acbd98e47e 100644
--- a/crates/router/src/routes/user.rs
+++ b/crates/router/src/routes/user.rs
@@ -1241,3 +1241,25 @@ pub async fn list_members_for_entity(
))
.await
}
+
+#[cfg(feature = "v1")]
+pub async fn authorize_token(
+ state: web::Data<AppState>,
+ http_req: HttpRequest,
+ json_payload: web::Json<user_api::AuthorizeTokenRequest>,
+) -> HttpResponse {
+ let flow = Flow::AuthorizeUserToken;
+ Box::pin(api::server_wrap(
+ flow,
+ state.clone(),
+ &http_req,
+ json_payload.into_inner(),
+ |state, _: (), payload, _| user_core::authorize_token(state, payload),
+ &auth::InternalMerchantIdProfileIdAuth(auth::DashboardNoPermissionAuth {
+ allow_connected: true,
+ allow_platform: true,
+ }),
+ api_locking::LockAction::NotApplicable,
+ ))
+ .await
+}
diff --git a/crates/router/src/services/authorization/info.rs b/crates/router/src/services/authorization/info.rs
index a76f24bee1..dc70ac8def 100644
--- a/crates/router/src/services/authorization/info.rs
+++ b/crates/router/src/services/authorization/info.rs
@@ -50,6 +50,14 @@ fn get_group_description(group: PermissionGroup) -> Option<&'static str> {
PermissionGroup::ThemeView => Some("View Themes"),
PermissionGroup::ThemeManage => Some("Manage Themes"),
PermissionGroup::InternalManage => None, // Internal group, no user-facing description
+ PermissionGroup::ReconSourcesView => Some("View recon ingestion and transformation configs and files"),
+ PermissionGroup::ReconSourcesManage => Some("Create and edit recon ingestion and transformation configs and download files"),
+ PermissionGroup::ReconExceptionsView => Some("Investigate Exceptions and view resolutions"),
+ PermissionGroup::ReconExceptionsManage => Some("Investigate and resolve recon exceptions"),
+ PermissionGroup::ReconTransactionsView => Some("View recon staging entries and transactions"),
+ PermissionGroup::ReconTransactionsManage => Some("View and edit recon staging entries and transactions"),
+ PermissionGroup::ReconRulesView => Some("View reconciliation rules"),
+ PermissionGroup::ReconRulesManage => Some("Create and edit reconciliation rules"),
}
}
@@ -65,5 +73,9 @@ pub fn get_parent_group_description(group: ParentGroup) -> Option<&'static str>
ParentGroup::ReconReports => Some("View, manage reconciliation reports and analytics"),
ParentGroup::Theme => Some("Manage and view themes for the organization"),
ParentGroup::Internal => None, // Internal group, no user-facing description
+ ParentGroup::ReconSources => Some("Recon ingestion and transformation pipelines"),
+ ParentGroup::ReconExceptions => Some("Recon exception investigation and resolution"),
+ ParentGroup::ReconTransactions => Some("Recon staging entries and transactions"),
+ ParentGroup::ReconRules => Some("Reconciliation rules"),
}
}
diff --git a/crates/router/src/services/authorization/permission_groups.rs b/crates/router/src/services/authorization/permission_groups.rs
index 7767373dce..4e5545fc69 100644
--- a/crates/router/src/services/authorization/permission_groups.rs
+++ b/crates/router/src/services/authorization/permission_groups.rs
@@ -4,12 +4,14 @@ use common_enums::{EntityType, ParentGroup, PermissionGroup, PermissionScope, Re
use strum::IntoEnumIterator;
use super::permissions;
+use crate::db::domain::role::RoleProductCategory;
pub trait PermissionGroupExt {
fn scope(&self) -> PermissionScope;
fn parent(&self) -> ParentGroup;
fn resources(&self) -> Vec<Resource>;
fn accessible_groups(&self) -> Vec<PermissionGroup>;
+ fn get_role_product_category(&self) -> RoleProductCategory;
}
impl PermissionGroupExt for PermissionGroup {
@@ -23,7 +25,11 @@ impl PermissionGroupExt for PermissionGroup {
| Self::AccountView
| Self::ReconOpsView
| Self::ReconReportsView
- | Self::ThemeView => PermissionScope::Read,
+ | Self::ThemeView
+ | Self::ReconSourcesView
+ | Self::ReconTransactionsView
+ | Self::ReconExceptionsView
+ | Self::ReconRulesView => PermissionScope::Read,
Self::OperationsManage
| Self::ConnectorsManage
@@ -33,7 +39,11 @@ impl PermissionGroupExt for PermissionGroup {
| Self::ReconOpsManage
| Self::ReconReportsManage
| Self::InternalManage
- | Self::ThemeManage => PermissionScope::Write,
+ | Self::ThemeManage
+ | Self::ReconSourcesManage
+ | Self::ReconExceptionsManage
+ | Self::ReconTransactionsManage
+ | Self::ReconRulesManage => PermissionScope::Write,
}
}
@@ -50,6 +60,12 @@ impl PermissionGroupExt for PermissionGroup {
Self::ReconOpsView | Self::ReconOpsManage => ParentGroup::ReconOps,
Self::ReconReportsView | Self::ReconReportsManage => ParentGroup::ReconReports,
Self::InternalManage => ParentGroup::Internal,
+ Self::ReconSourcesView | Self::ReconSourcesManage => ParentGroup::ReconSources,
+ Self::ReconExceptionsView | Self::ReconExceptionsManage => ParentGroup::ReconExceptions,
+ Self::ReconTransactionsView | Self::ReconTransactionsManage => {
+ ParentGroup::ReconTransactions
+ }
+ Self::ReconRulesView | Self::ReconRulesManage => ParentGroup::ReconRules,
}
}
@@ -95,6 +111,75 @@ impl PermissionGroupExt for PermissionGroup {
Self::InternalManage => vec![Self::InternalManage],
Self::ThemeView => vec![Self::ThemeView, Self::AccountView],
Self::ThemeManage => vec![Self::ThemeManage, Self::AccountView],
+
+ Self::ReconSourcesView => vec![
+ Self::ReconSourcesView,
+ Self::ReconTransactionsView,
+ Self::ReconRulesView,
+ ],
+ Self::ReconSourcesManage => vec![
+ Self::ReconSourcesManage,
+ Self::ReconSourcesView,
+ Self::ReconTransactionsView,
+ Self::ReconRulesView,
+ ],
+ Self::ReconExceptionsView => vec![
+ Self::ReconExceptionsView,
+ Self::ReconTransactionsView,
+ Self::ReconRulesView,
+ ],
+ Self::ReconExceptionsManage => vec![
+ Self::ReconExceptionsManage,
+ Self::ReconTransactionsView,
+ Self::ReconRulesView,
+ ],
+ Self::ReconTransactionsView => vec![Self::ReconTransactionsView, Self::ReconRulesView],
+ Self::ReconTransactionsManage => vec![
+ Self::ReconTransactionsManage,
+ Self::ReconTransactionsView,
+ Self::ReconRulesView,
+ ],
+ Self::ReconRulesView => vec![Self::ReconRulesView, Self::ReconTransactionsView],
+ Self::ReconRulesManage => vec![
+ Self::ReconRulesManage,
+ Self::ReconRulesView,
+ Self::ReconTransactionsView,
+ ],
+ }
+ }
+
+ fn get_role_product_category(&self) -> RoleProductCategory {
+ match self {
+ // Common across every product — not validated against the merchant's category.
+ Self::UsersView | Self::UsersManage => RoleProductCategory::Dashboard,
+
+ // Orchestration-only groups.
+ Self::OperationsView
+ | Self::OperationsManage
+ | Self::ConnectorsView
+ | Self::ConnectorsManage
+ | Self::WorkflowsView
+ | Self::WorkflowsManage
+ | Self::AnalyticsView
+ | Self::AccountView
+ | Self::AccountManage
+ | Self::ReconReportsView
+ | Self::ReconReportsManage
+ | Self::ReconOpsView
+ | Self::ReconOpsManage
+ | Self::InternalManage
+ | Self::ThemeView
+ | Self::ThemeManage => RoleProductCategory::Orchestration,
+
+ // Recon-only groups.
+ Self::ReconSourcesView
+ | Self::ReconSourcesManage
+ | Self::ReconExceptionsView
+ | Self::ReconExceptionsManage
+ | Self::ReconTransactionsView
+ | Self::ReconTransactionsManage
+ | Self::ReconRulesView
+ | Self::ReconRulesManage => RoleProductCategory::Recon,
}
}
}
@@ -121,6 +206,10 @@ impl ParentGroupExt for ParentGroup {
Self::ReconReports => RECON_REPORTS.to_vec(),
Self::Internal => INTERNAL.to_vec(),
Self::Theme => THEME.to_vec(),
+ Self::ReconSources => RECON_SOURCES.to_vec(),
+ Self::ReconExceptions => RECON_EXCEPTIONS.to_vec(),
+ Self::ReconTransactions => RECON_TRANSACTIONS.to_vec(),
+ Self::ReconRules => RECON_RULES.to_vec(),
}
}
@@ -208,3 +297,12 @@ pub static RECON_REPORTS: [Resource; 4] = [
];
pub static THEME: [Resource; 1] = [Resource::Theme];
+
+pub static RECON_SOURCES: [Resource; 2] = [Resource::ReconIngestion, Resource::ReconTransformation];
+
+pub static RECON_EXCEPTIONS: [Resource; 1] = [Resource::ReconException];
+
+pub static RECON_TRANSACTIONS: [Resource; 2] =
+ [Resource::ReconStagingEntry, Resource::ReconTransaction];
+
+pub static RECON_RULES: [Resource; 1] = [Resource::ReconRule];
diff --git a/crates/router/src/services/authorization/permissions.rs b/crates/router/src/services/authorization/permissions.rs
index 2181d9d0eb..e5f1127c2a 100644
--- a/crates/router/src/services/authorization/permissions.rs
+++ b/crates/router/src/services/authorization/permissions.rs
@@ -110,7 +110,31 @@ generate_permissions! {
Theme: {
scopes: [Read,Write],
entities: [Organization]
- }
+ },
+ ReconIngestion: {
+ scopes: [Read, Write],
+ entities: [Profile]
+ },
+ ReconTransformation: {
+ scopes: [Read, Write],
+ entities: [Profile]
+ },
+ ReconException: {
+ scopes: [Read, Write],
+ entities: [Profile]
+ },
+ ReconStagingEntry: {
+ scopes: [Read, Write],
+ entities: [Profile]
+ },
+ ReconTransaction: {
+ scopes: [Read, Write],
+ entities: [Profile]
+ },
+ ReconRule: {
+ scopes: [Read, Write],
+ entities: [Profile]
+ },
]
}
@@ -148,6 +172,12 @@ pub fn get_resource_name(resource: Resource, entity_type: EntityType) -> Option<
(Resource::Account, EntityType::Tenant) => Some("Tenant Account"),
(Resource::Theme, _) => Some("Themes"),
(Resource::InternalConnector, _) => None,
+ (Resource::ReconIngestion, _) => Some("Recon Ingestion Configs"),
+ (Resource::ReconTransformation, _) => Some("Recon Transformation Configs"),
+ (Resource::ReconException, _) => Some("Recon Exception Management"),
+ (Resource::ReconStagingEntry, _) => Some("Recon Staging Entries"),
+ (Resource::ReconTransaction, _) => Some("Recon Transactions"),
+ (Resource::ReconRule, _) => Some("Recon Rules"),
}
}
diff --git a/crates/router/src/services/authorization/roles.rs b/crates/router/src/services/authorization/roles.rs
index b12df95389..c0cdc93671 100644
--- a/crates/router/src/services/authorization/roles.rs
+++ b/crates/router/src/services/authorization/roles.rs
@@ -4,7 +4,7 @@ use std::collections::HashSet;
#[cfg(feature = "recon")]
use api_models::enums::ReconPermissionScope;
-use common_enums::{EntityType, PermissionGroup, Resource, RoleScope};
+use common_enums::{EntityType, MerchantProductType, PermissionGroup, Resource, RoleScope};
use common_utils::{errors::CustomResult, id_type};
#[cfg(feature = "recon")]
@@ -25,6 +25,7 @@ pub struct RoleInfo {
is_deletable: bool,
is_updatable: bool,
is_internal: bool,
+ merchant_product_type: MerchantProductType,
}
impl RoleInfo {
@@ -69,6 +70,10 @@ impl RoleInfo {
self.is_updatable
}
+ pub fn get_merchant_product_type(&self) -> MerchantProductType {
+ self.merchant_product_type
+ }
+
pub fn get_resources_set(&self) -> HashSet<Resource> {
self.get_permission_groups()
.iter()
@@ -176,6 +181,9 @@ impl From<diesel_models::role::Role> for RoleInfo {
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: role
+ .merchant_product_type
+ .unwrap_or(MerchantProductType::Orchestration),
}
}
}
diff --git a/crates/router/src/services/authorization/roles/predefined_roles.rs b/crates/router/src/services/authorization/roles/predefined_roles.rs
index 83e1b94a22..feb0b238a6 100644
--- a/crates/router/src/services/authorization/roles/predefined_roles.rs
+++ b/crates/router/src/services/authorization/roles/predefined_roles.rs
@@ -1,6 +1,6 @@
use std::{collections::HashMap, sync::LazyLock};
-use common_enums::{EntityType, PermissionGroup, RoleScope};
+use common_enums::{EntityType, MerchantProductType, PermissionGroup, RoleScope};
use super::RoleInfo;
use crate::consts;
@@ -37,6 +37,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: false,
is_updatable: false,
is_internal: true,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -60,6 +61,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: false,
is_updatable: false,
is_internal: true,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -84,6 +86,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: false,
is_updatable: false,
is_internal: true,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
@@ -116,6 +119,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: false,
is_updatable: false,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
@@ -150,6 +154,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
@@ -182,6 +187,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -205,6 +211,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -225,6 +232,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -248,6 +256,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -273,6 +282,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -294,6 +304,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
@@ -322,6 +333,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -343,6 +355,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -363,6 +376,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -384,6 +398,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -406,6 +421,7 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
roles.insert(
@@ -425,7 +441,192 @@ pub static PREDEFINED_ROLES: LazyLock<HashMap<&'static str, RoleInfo>> = LazyLoc
is_deletable: true,
is_updatable: true,
is_internal: false,
+ merchant_product_type: MerchantProductType::Orchestration,
},
);
+ // Recon Roles
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_MERCHANT_ADMIN,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconSourcesView,
+ PermissionGroup::ReconSourcesManage,
+ PermissionGroup::ReconExceptionsView,
+ PermissionGroup::ReconExceptionsManage,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::ReconTransactionsManage,
+ PermissionGroup::UsersView,
+ PermissionGroup::UsersManage,
+ PermissionGroup::ReconRulesView,
+ PermissionGroup::ReconRulesManage,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_MERCHANT_ADMIN.to_string(),
+ role_name: "recon_merchant_admin".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Merchant,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_MERCHANT_DATA_ENGINEER,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconSourcesView,
+ PermissionGroup::ReconSourcesManage,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::UsersView,
+ PermissionGroup::ReconRulesView,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_MERCHANT_DATA_ENGINEER.to_string(),
+ role_name: "recon_merchant_data_engineer".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Merchant,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_MERCHANT_OPERATOR,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconExceptionsView,
+ PermissionGroup::ReconExceptionsManage,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::ReconTransactionsManage,
+ PermissionGroup::UsersView,
+ PermissionGroup::ReconRulesView,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_MERCHANT_OPERATOR.to_string(),
+ role_name: "recon_merchant_operator".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Merchant,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_MERCHANT_VIEW_ONLY,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconSourcesView,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::ReconExceptionsView,
+ PermissionGroup::UsersView,
+ PermissionGroup::ReconRulesView,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_MERCHANT_VIEW_ONLY.to_string(),
+ role_name: "recon_merchant_view_only".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Merchant,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+
+ // Profile Recon Roles
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_PROFILE_ADMIN,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconSourcesView,
+ PermissionGroup::ReconSourcesManage,
+ PermissionGroup::ReconExceptionsView,
+ PermissionGroup::ReconExceptionsManage,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::ReconTransactionsManage,
+ PermissionGroup::UsersView,
+ PermissionGroup::UsersManage,
+ PermissionGroup::ReconRulesView,
+ PermissionGroup::ReconRulesManage,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_PROFILE_ADMIN.to_string(),
+ role_name: "recon_profile_admin".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Profile,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_PROFILE_DATA_ENGINEER,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconSourcesView,
+ PermissionGroup::ReconSourcesManage,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::UsersView,
+ PermissionGroup::ReconRulesView,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_PROFILE_DATA_ENGINEER.to_string(),
+ role_name: "recon_profile_data_engineer".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Profile,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_PROFILE_OPERATOR,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconExceptionsView,
+ PermissionGroup::ReconExceptionsManage,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::ReconTransactionsManage,
+ PermissionGroup::UsersView,
+ PermissionGroup::ReconRulesView,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_PROFILE_OPERATOR.to_string(),
+ role_name: "recon_profile_operator".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Profile,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+ roles.insert(
+ consts::user_role::ROLE_ID_RECON_PROFILE_VIEW_ONLY,
+ RoleInfo {
+ groups: vec![
+ PermissionGroup::ReconSourcesView,
+ PermissionGroup::ReconTransactionsView,
+ PermissionGroup::ReconExceptionsView,
+ PermissionGroup::UsersView,
+ PermissionGroup::ReconRulesView,
+ ],
+ role_id: consts::user_role::ROLE_ID_RECON_PROFILE_VIEW_ONLY.to_string(),
+ role_name: "recon_profile_view_only".to_string(),
+ scope: RoleScope::Organization,
+ entity_type: EntityType::Profile,
+ is_invitable: true,
+ is_deletable: true,
+ is_updatable: true,
+ is_internal: false,
+ merchant_product_type: MerchantProductType::Recon,
+ },
+ );
+
roles
});
diff --git a/crates/router/src/types/domain.rs b/crates/router/src/types/domain.rs
index 04d1756986..16dbb7d0e5 100644
--- a/crates/router/src/types/domain.rs
+++ b/crates/router/src/types/domain.rs
@@ -83,6 +83,7 @@ mod routing {
}
pub mod payments;
+pub mod role;
pub mod types;
#[cfg(feature = "olap")]
pub mod user;
diff --git a/crates/router/src/types/domain/role.rs b/crates/router/src/types/domain/role.rs
new file mode 100644
index 0000000000..0bdb095b3d
--- /dev/null
+++ b/crates/router/src/types/domain/role.rs
@@ -0,0 +1,26 @@
+use common_enums::MerchantProductType;
+
+#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum RoleProductCategory {
+ Dashboard,
+ Orchestration,
+ Vault,
+ Recon,
+ Recovery,
+ CostObservability,
+ DynamicRouting,
+}
+
+impl From<MerchantProductType> for RoleProductCategory {
+ fn from(value: MerchantProductType) -> Self {
+ match value {
+ MerchantProductType::Orchestration => Self::Orchestration,
+ MerchantProductType::Vault => Self::Vault,
+ MerchantProductType::Recon => Self::Recon,
+ MerchantProductType::Recovery => Self::Recovery,
+ MerchantProductType::CostObservability => Self::CostObservability,
+ MerchantProductType::DynamicRouting => Self::DynamicRouting,
+ }
+ }
+}
diff --git a/crates/router/src/utils/user_role.rs b/crates/router/src/utils/user_role.rs
index 996ee2b71e..97c58117b4 100644
--- a/crates/router/src/utils/user_role.rs
+++ b/crates/router/src/utils/user_role.rs
@@ -4,7 +4,7 @@ use std::{
};
use api_models::user_role::role as role_api;
-use common_enums::{EntityType, ParentGroup, PermissionGroup};
+use common_enums::{EntityType, MerchantProductType, ParentGroup, PermissionGroup};
use common_utils::id_type;
use diesel_models::{
enums::UserRoleVersion,
@@ -20,6 +20,7 @@ use crate::{
consts,
core::errors::{UserErrors, UserResult},
db::{
+ domain::role::RoleProductCategory,
errors::StorageErrorExt,
user_role::{ListUserRolesByOrgIdPayload, ListUserRolesByUserIdPayload},
},
@@ -37,12 +38,28 @@ use crate::{
utils::user::{self as user_utils, theme as theme_utils},
};
-pub fn validate_role_groups(groups: &[PermissionGroup]) -> UserResult<()> {
+pub fn validate_role_groups(
+ groups: &[PermissionGroup],
+ merchant_product_type: Option<MerchantProductType>,
+) -> UserResult<()> {
if groups.is_empty() {
return Err(report!(UserErrors::InvalidRoleOperation))
.attach_printable("Role groups cannot be empty");
}
+ if let Some(product_type) = merchant_product_type {
+ if !groups.iter().all(|group| {
+ let role_product_category = group.get_role_product_category();
+ match role_product_category {
+ RoleProductCategory::Dashboard => true,
+ _ => role_product_category == RoleProductCategory::from(product_type),
+ }
+ }) {
+ return Err(report!(UserErrors::InvalidRoleOperation))
+ .attach_printable("Permission groups of different product types found");
+ }
+ }
+
let unique_groups: HashSet<_> = groups.iter().copied().collect();
if unique_groups.contains(&PermissionGroup::InternalManage) {
diff --git a/crates/router_derive/src/macros/generate_permissions.rs b/crates/router_derive/src/macros/generate_permissions.rs
index 9b388f102c..f0c07e3cdf 100644
--- a/crates/router_derive/src/macros/generate_permissions.rs
+++ b/crates/router_derive/src/macros/generate_permissions.rs
@@ -95,7 +95,7 @@ pub fn generate_permissions_inner(input: TokenStream) -> TokenStream {
let expanded = quote! {
#[derive(
- Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, serde::Serialize, serde::Deserialize, strum::Display
+ Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, serde::Serialize, serde::Deserialize, strum::Display, strum::EnumString
)]
pub enum Permission {
#(#enum_keys),*
diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rs
index 9852716080..7df0454270 100644
--- a/crates/router_env/src/logger/types.rs
+++ b/crates/router_env/src/logger/types.rs
@@ -743,6 +743,8 @@ pub enum Flow {
ListUsersInternal,
// List members for entity
ListMembersForEntity,
+ /// Authorize external token
+ AuthorizeUserToken,
}
/// Trait for providing generic behaviour to flow metric
diff --git a/migrations/2026-04-13-000001_add_merchant_product_type_to_roles/down.sql b/migrations/2026-04-13-000001_add_merchant_product_type_to_roles/down.sql
new file mode 100644
index 0000000000..f52c90c3cc
--- /dev/null
+++ b/migrations/2026-04-13-000001_add_merchant_product_type_to_roles/down.sql
@@ -0,0 +1 @@
+ALTER TABLE roles DROP COLUMN IF EXISTS merchant_product_type;
diff --git a/migrations/2026-04-13-000001_add_merchant_product_type_to_roles/up.sql b/migrations/2026-04-13-000001_add_merchant_product_type_to_roles/up.sql
new file mode 100644
index 0000000000..e7c0a616c2
--- /dev/null
+++ b/migrations/2026-04-13-000001_add_merchant_product_type_to_roles/up.sql
@@ -0,0 +1,3 @@
+ALTER TABLE roles ADD COLUMN IF NOT EXISTS merchant_product_type VARCHAR(64);
+
+UPDATE roles SET merchant_product_type = 'orchestration' where merchant_product_type IS NULL;