mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
feat(users): Send profile_id in JWT and user_info APIs (#5817)
This commit is contained in:
@ -100,6 +100,14 @@ pub async fn get_user_details(
|
||||
) -> UserResponse<user_api::GetUserDetailsResponse> {
|
||||
let user = user_from_token.get_user_from_db(&state).await?;
|
||||
let verification_days_left = utils::user::get_verification_days_left(&state, &user)?;
|
||||
let role_info = roles::RoleInfo::from_role_id(
|
||||
&state,
|
||||
&user_from_token.role_id,
|
||||
&user_from_token.merchant_id,
|
||||
&user_from_token.org_id,
|
||||
)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?;
|
||||
|
||||
Ok(ApplicationResponse::Json(
|
||||
user_api::GetUserDetailsResponse {
|
||||
@ -112,6 +120,10 @@ pub async fn get_user_details(
|
||||
org_id: user_from_token.org_id,
|
||||
is_two_factor_auth_setup: user.get_totp_status() == TotpStatus::Set,
|
||||
recovery_codes_left: user.get_recovery_codes().map(|codes| codes.len()),
|
||||
profile_id: user_from_token
|
||||
.profile_id
|
||||
.ok_or(UserErrors::JwtProfileIdMissing)?,
|
||||
entity_type: role_info.get_entity_type(),
|
||||
},
|
||||
))
|
||||
}
|
||||
@ -1185,13 +1197,12 @@ pub async fn switch_merchant_id(
|
||||
})?
|
||||
.organization_id;
|
||||
|
||||
let token = utils::user::generate_jwt_auth_token_with_attributes(
|
||||
let token = utils::user::generate_jwt_auth_token_with_attributes_without_profile(
|
||||
&state,
|
||||
user_from_token.user_id,
|
||||
request.merchant_id.clone(),
|
||||
org_id.clone(),
|
||||
user_from_token.role_id.clone(),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -2792,7 +2803,6 @@ pub async fn switch_org_for_user(
|
||||
.into());
|
||||
}
|
||||
|
||||
let key_manager_state = &(&state).into();
|
||||
let role_info = roles::RoleInfo::from_role_id(
|
||||
&state,
|
||||
&user_from_token.role_id,
|
||||
@ -2830,38 +2840,8 @@ pub async fn switch_org_for_user(
|
||||
"No user role found for the requested org_id".to_string(),
|
||||
))?;
|
||||
|
||||
let merchant_id = utils::user_role::get_single_merchant_id(&state, &user_role).await?;
|
||||
|
||||
let profile_id = if let Some(profile_id) = &user_role.profile_id {
|
||||
profile_id.clone()
|
||||
} else {
|
||||
let merchant_key_store = state
|
||||
.store
|
||||
.get_merchant_key_store_by_merchant_id(
|
||||
key_manager_state,
|
||||
&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")?;
|
||||
|
||||
state
|
||||
.store
|
||||
.list_business_profile_by_merchant_id(
|
||||
key_manager_state,
|
||||
&merchant_key_store,
|
||||
&merchant_id,
|
||||
)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.attach_printable("Failed to list business profiles by merchant_id")?
|
||||
.pop()
|
||||
.ok_or(UserErrors::InternalServerError)
|
||||
.attach_printable("No business profile found for the merchant_id")?
|
||||
.get_id()
|
||||
.to_owned()
|
||||
};
|
||||
let (merchant_id, profile_id) =
|
||||
utils::user_role::get_single_merchant_id_and_profile_id(&state, &user_role).await?;
|
||||
|
||||
let token = utils::user::generate_jwt_auth_token_with_attributes(
|
||||
&state,
|
||||
@ -2869,7 +2849,7 @@ pub async fn switch_org_for_user(
|
||||
merchant_id.clone(),
|
||||
request.org_id.clone(),
|
||||
user_role.role_id.clone(),
|
||||
Some(profile_id.clone()),
|
||||
profile_id.clone(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -3078,7 +3058,7 @@ pub async fn switch_merchant_for_user_in_org(
|
||||
merchant_id.clone(),
|
||||
org_id.clone(),
|
||||
role_id.clone(),
|
||||
Some(profile_id),
|
||||
profile_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -3183,7 +3163,7 @@ pub async fn switch_profile_for_user_in_org_and_merchant(
|
||||
user_from_token.merchant_id.clone(),
|
||||
user_from_token.org_id.clone(),
|
||||
role_id.clone(),
|
||||
Some(profile_id),
|
||||
profile_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user