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

fix(users): Check lineage across entities in invite (#6677)

Mani Chandraf3424b757655
diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs
index c6501dac3b..2087d01dbb 100644
--- a/crates/router/src/core/user.rs
+++ b/crates/router/src/core/user.rs
@@ -642,6 +642,38 @@ async fn handle_existing_user_invitation(
return Err(UserErrors::UserExists.into());
}
+ let (org_id, merchant_id, profile_id) = match role_info.get_entity_type() {
+ EntityType::Organization => (Some(&user_from_token.org_id), None, None),
+ EntityType::Merchant => (
+ Some(&user_from_token.org_id),
+ Some(&user_from_token.merchant_id),
+ None,
+ ),
+ EntityType::Profile => (
+ Some(&user_from_token.org_id),
+ Some(&user_from_token.merchant_id),
+ Some(&user_from_token.profile_id),
+ ),
+ };
+
+ if state
+ .global_store
+ .list_user_roles_by_user_id(ListUserRolesByUserIdPayload {
+ user_id: invitee_user_from_db.get_user_id(),
+ org_id,
+ merchant_id,
+ profile_id,
+ entity_id: None,
+ version: None,
+ status: None,
+ limit: Some(1),
+ })
+ .await
+ .is_ok_and(|data| data.is_empty().not())
+ {
+ return Err(UserErrors::UserExists.into());
+ }
+
let user_role = domain::NewUserRole {
user_id: invitee_user_from_db.get_user_id().to_owned(),
role_id: request.role_id.clone(),