mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +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?;
|
||||
|
||||
|
||||
@ -744,30 +744,6 @@ pub async fn list_users_in_lineage(
|
||||
.map(|user| (user.user_id.clone(), user.email))
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
let role_info_map =
|
||||
futures::future::try_join_all(user_roles_set.iter().map(|user_role| async {
|
||||
roles::RoleInfo::from_role_id(
|
||||
&state,
|
||||
&user_role.role_id,
|
||||
&user_from_token.merchant_id,
|
||||
&user_from_token.org_id,
|
||||
)
|
||||
.await
|
||||
.map(|role_info| {
|
||||
(
|
||||
user_role.role_id.clone(),
|
||||
user_role_api::role::MinimalRoleInfo {
|
||||
role_id: user_role.role_id.clone(),
|
||||
role_name: role_info.get_role_name().to_string(),
|
||||
},
|
||||
)
|
||||
})
|
||||
}))
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
let user_role_map = user_roles_set
|
||||
.into_iter()
|
||||
.fold(HashMap::new(), |mut map, user_role| {
|
||||
@ -787,13 +763,11 @@ pub async fn list_users_in_lineage(
|
||||
.ok_or(UserErrors::InternalServerError)?,
|
||||
roles: role_id_vec
|
||||
.into_iter()
|
||||
.map(|role_id| {
|
||||
role_info_map
|
||||
.get(&role_id)
|
||||
.cloned()
|
||||
.ok_or(UserErrors::InternalServerError)
|
||||
.map(|role_id| user_role_api::role::MinimalRoleInfo {
|
||||
role_id,
|
||||
role_name: None,
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
.collect(),
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
|
||||
@ -348,7 +348,7 @@ pub async fn list_roles_at_entity_level(
|
||||
if check_type && role_info.get_entity_type() == req.entity_type {
|
||||
Some(role_api::MinimalRoleInfo {
|
||||
role_id: role_info.get_role_id().to_string(),
|
||||
role_name: role_info.get_role_name().to_string(),
|
||||
role_name: Some(role_info.get_role_name().to_string()),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user