mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
feat(users): add global support in user roles (#6458)
This commit is contained in:
@ -598,7 +598,7 @@ async fn handle_existing_user_invitation(
|
||||
let now = common_utils::date_time::now();
|
||||
|
||||
if state
|
||||
.store
|
||||
.global_store
|
||||
.find_user_role_by_user_id_and_lineage(
|
||||
invitee_user_from_db.get_user_id(),
|
||||
&user_from_token.org_id,
|
||||
@ -614,7 +614,7 @@ async fn handle_existing_user_invitation(
|
||||
}
|
||||
|
||||
if state
|
||||
.store
|
||||
.global_store
|
||||
.find_user_role_by_user_id_and_lineage(
|
||||
invitee_user_from_db.get_user_id(),
|
||||
&user_from_token.org_id,
|
||||
@ -650,6 +650,10 @@ async fn handle_existing_user_invitation(
|
||||
EntityType::Organization => {
|
||||
user_role
|
||||
.add_entity(domain::OrganizationLevel {
|
||||
tenant_id: user_from_token
|
||||
.tenant_id
|
||||
.clone()
|
||||
.unwrap_or(state.tenant.tenant_id.clone()),
|
||||
org_id: user_from_token.org_id.clone(),
|
||||
})
|
||||
.insert_in_v2(state)
|
||||
@ -658,6 +662,10 @@ async fn handle_existing_user_invitation(
|
||||
EntityType::Merchant => {
|
||||
user_role
|
||||
.add_entity(domain::MerchantLevel {
|
||||
tenant_id: user_from_token
|
||||
.tenant_id
|
||||
.clone()
|
||||
.unwrap_or(state.tenant.tenant_id.clone()),
|
||||
org_id: user_from_token.org_id.clone(),
|
||||
merchant_id: user_from_token.merchant_id.clone(),
|
||||
})
|
||||
@ -671,6 +679,10 @@ async fn handle_existing_user_invitation(
|
||||
.ok_or(UserErrors::InternalServerError)?;
|
||||
user_role
|
||||
.add_entity(domain::ProfileLevel {
|
||||
tenant_id: user_from_token
|
||||
.tenant_id
|
||||
.clone()
|
||||
.unwrap_or(state.tenant.tenant_id.clone()),
|
||||
org_id: user_from_token.org_id.clone(),
|
||||
merchant_id: user_from_token.merchant_id.clone(),
|
||||
profile_id: profile_id.clone(),
|
||||
@ -777,6 +789,10 @@ async fn handle_new_user_invitation(
|
||||
EntityType::Organization => {
|
||||
user_role
|
||||
.add_entity(domain::OrganizationLevel {
|
||||
tenant_id: user_from_token
|
||||
.tenant_id
|
||||
.clone()
|
||||
.unwrap_or(state.tenant.tenant_id.clone()),
|
||||
org_id: user_from_token.org_id.clone(),
|
||||
})
|
||||
.insert_in_v2(state)
|
||||
@ -785,6 +801,10 @@ async fn handle_new_user_invitation(
|
||||
EntityType::Merchant => {
|
||||
user_role
|
||||
.add_entity(domain::MerchantLevel {
|
||||
tenant_id: user_from_token
|
||||
.tenant_id
|
||||
.clone()
|
||||
.unwrap_or(state.tenant.tenant_id.clone()),
|
||||
org_id: user_from_token.org_id.clone(),
|
||||
merchant_id: user_from_token.merchant_id.clone(),
|
||||
})
|
||||
@ -798,6 +818,10 @@ async fn handle_new_user_invitation(
|
||||
.ok_or(UserErrors::InternalServerError)?;
|
||||
user_role
|
||||
.add_entity(domain::ProfileLevel {
|
||||
tenant_id: user_from_token
|
||||
.tenant_id
|
||||
.clone()
|
||||
.unwrap_or(state.tenant.tenant_id.clone()),
|
||||
org_id: user_from_token.org_id.clone(),
|
||||
merchant_id: user_from_token.merchant_id.clone(),
|
||||
profile_id: profile_id.clone(),
|
||||
@ -864,6 +888,7 @@ async fn handle_new_user_invitation(
|
||||
org_id: user_from_token.org_id.clone(),
|
||||
role_id: request.role_id.clone(),
|
||||
profile_id: None,
|
||||
tenant_id: user_from_token.tenant_id.clone(),
|
||||
};
|
||||
|
||||
let set_metadata_request = SetMetaDataRequest::IsChangePasswordRequired;
|
||||
@ -909,7 +934,7 @@ pub async fn resend_invite(
|
||||
.into();
|
||||
|
||||
let user_role = match state
|
||||
.store
|
||||
.global_store
|
||||
.find_user_role_by_user_id_and_lineage(
|
||||
user.get_user_id(),
|
||||
&user_from_token.org_id,
|
||||
@ -932,7 +957,7 @@ pub async fn resend_invite(
|
||||
let user_role = match user_role {
|
||||
Some(user_role) => user_role,
|
||||
None => state
|
||||
.store
|
||||
.global_store
|
||||
.find_user_role_by_user_id_and_lineage(
|
||||
user.get_user_id(),
|
||||
&user_from_token.org_id,
|
||||
@ -1102,6 +1127,13 @@ pub async fn create_internal_user(
|
||||
}
|
||||
})?;
|
||||
|
||||
let default_tenant_id = common_utils::consts::DEFAULT_TENANT.to_string();
|
||||
|
||||
if state.tenant.tenant_id != default_tenant_id {
|
||||
return Err(UserErrors::ForbiddenTenantId)
|
||||
.attach_printable("Operation allowed only for the default tenant.");
|
||||
}
|
||||
|
||||
let internal_merchant_id = common_utils::id_type::MerchantId::get_internal_user_merchant_id(
|
||||
consts::user_role::INTERNAL_USER_MERCHANT_ID,
|
||||
);
|
||||
@ -1142,6 +1174,7 @@ pub async fn create_internal_user(
|
||||
UserStatus::Active,
|
||||
)
|
||||
.add_entity(domain::MerchantLevel {
|
||||
tenant_id: default_tenant_id,
|
||||
org_id: internal_merchant.organization_id,
|
||||
merchant_id: internal_merchant_id,
|
||||
})
|
||||
@ -1195,7 +1228,7 @@ pub async fn list_user_roles_details(
|
||||
}
|
||||
|
||||
let user_roles_set = state
|
||||
.store
|
||||
.global_store
|
||||
.list_user_roles_by_user_id(ListUserRolesByUserIdPayload {
|
||||
user_id: required_user.get_user_id(),
|
||||
org_id: Some(&user_from_token.org_id),
|
||||
@ -2372,7 +2405,7 @@ pub async fn list_orgs_for_user(
|
||||
}
|
||||
|
||||
let orgs = state
|
||||
.store
|
||||
.global_store
|
||||
.list_user_roles_by_user_id(ListUserRolesByUserIdPayload {
|
||||
user_id: user_from_token.user_id.as_str(),
|
||||
org_id: None,
|
||||
@ -2437,7 +2470,7 @@ pub async fn list_merchants_for_user_in_org(
|
||||
.change_context(UserErrors::InternalServerError)?,
|
||||
EntityType::Merchant | EntityType::Profile => {
|
||||
let merchant_ids = state
|
||||
.store
|
||||
.global_store
|
||||
.list_user_roles_by_user_id(ListUserRolesByUserIdPayload {
|
||||
user_id: user_from_token.user_id.as_str(),
|
||||
org_id: Some(&user_from_token.org_id),
|
||||
@ -2516,7 +2549,7 @@ pub async fn list_profiles_for_user_in_org_and_merchant_account(
|
||||
.change_context(UserErrors::InternalServerError)?,
|
||||
EntityType::Profile => {
|
||||
let profile_ids = state
|
||||
.store
|
||||
.global_store
|
||||
.list_user_roles_by_user_id(ListUserRolesByUserIdPayload {
|
||||
user_id: user_from_token.user_id.as_str(),
|
||||
org_id: Some(&user_from_token.org_id),
|
||||
@ -2592,7 +2625,7 @@ pub async fn switch_org_for_user(
|
||||
}
|
||||
|
||||
let user_role = state
|
||||
.store
|
||||
.global_store
|
||||
.list_user_roles_by_user_id(ListUserRolesByUserIdPayload {
|
||||
user_id: &user_from_token.user_id,
|
||||
org_id: Some(&request.org_id),
|
||||
@ -2621,6 +2654,7 @@ pub async fn switch_org_for_user(
|
||||
request.org_id.clone(),
|
||||
user_role.role_id.clone(),
|
||||
profile_id.clone(),
|
||||
user_from_token.tenant_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -2764,7 +2798,7 @@ pub async fn switch_merchant_for_user_in_org(
|
||||
|
||||
EntityType::Merchant | EntityType::Profile => {
|
||||
let user_role = state
|
||||
.store
|
||||
.global_store
|
||||
.list_user_roles_by_user_id(ListUserRolesByUserIdPayload {
|
||||
user_id: &user_from_token.user_id,
|
||||
org_id: Some(&user_from_token.org_id),
|
||||
@ -2805,6 +2839,7 @@ pub async fn switch_merchant_for_user_in_org(
|
||||
org_id.clone(),
|
||||
role_id.clone(),
|
||||
profile_id,
|
||||
user_from_token.tenant_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -2879,7 +2914,7 @@ pub async fn switch_profile_for_user_in_org_and_merchant(
|
||||
|
||||
EntityType::Profile => {
|
||||
let user_role = state
|
||||
.store
|
||||
.global_store
|
||||
.list_user_roles_by_user_id(ListUserRolesByUserIdPayload{
|
||||
user_id:&user_from_token.user_id,
|
||||
org_id: Some(&user_from_token.org_id),
|
||||
@ -2910,6 +2945,7 @@ pub async fn switch_profile_for_user_in_org_and_merchant(
|
||||
user_from_token.org_id.clone(),
|
||||
role_id.clone(),
|
||||
profile_id,
|
||||
user_from_token.tenant_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user