Skip to content

Commit

Permalink
fix(users): Check lineage across entities in invite (#6677)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsMani authored Nov 27, 2024
1 parent d4b482c commit f3424b7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/router/src/core/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit f3424b7

Please sign in to comment.