feat(user_roles): get user role details#5777
Conversation
|
Review changes with SemanticDiff. Analyzed 5 of 5 files. Overall, the semantic diff is 1% smaller than the GitHub diff.
|
crates/router/src/core/user.rs
Outdated
|
|
||
| let mut role_details_list = Vec::new(); | ||
|
|
||
| for user_role in user_roles_set { |
crates/router/src/core/user.rs
Outdated
| let role_info = if let Some(role) = | ||
| roles::predefined_roles::PREDEFINED_ROLES.get(&user_role.role_id.as_str()) | ||
| { | ||
| role.clone() | ||
| } else { | ||
| state | ||
| .store | ||
| .find_role_by_role_id_in_merchant_scope( | ||
| &user_role.role_id, | ||
| &user_role | ||
| .merchant_id | ||
| .ok_or(UserErrors::InternalServerError) | ||
| .attach_printable("Merchant id not found for custom role")?, | ||
| &user_from_token.org_id, | ||
| ) | ||
| .await | ||
| .change_context(UserErrors::InternalServerError) | ||
| .attach_printable("Failed to get custom role")? | ||
| .into() | ||
| }; |
There was a problem hiding this comment.
coz merchant id is non option param in that, he we may or may not get it.
There was a problem hiding this comment.
Make a function in roles which takes user role and gives back a role info.
If the role_id is present in the predefined roles it will not do any db calls.
Else if the entity type is org, then throw internal server error (As we don't have any org level custom roles.)
Else if the entity type is merchant, then get merchant id from the user role (if it is not there throw 500) and find the custom role.
Else if the entity type is merchant or profile, then get merchant id from the user role (if it is not there throw 500) and find the custom role.
You can change the from_role_id() function if it is possible.
| req: HttpRequest, | ||
| payload: web::Query<user_api::GetUserRoleDetailsRequest>, | ||
| ) -> HttpResponse { | ||
| let flow = Flow::GetUserRoleDetails; |
There was a problem hiding this comment.
Yes we can have, but this flow was not getting used anywhere
crates/router/src/core/user.rs
Outdated
| let merchant = match entity_type.ok_or(UserErrors::InternalServerError)? { | ||
| EntityType::Internal => { | ||
| return Err(UserErrors::InvalidRoleOperationWithMessage( | ||
| "Internal roles are not allowed for this operation".to_string(), | ||
| )); | ||
| } | ||
| EntityType::Organization => None, | ||
| EntityType::Merchant | EntityType::Profile => { | ||
| if let Some(merchant_id) = &user_role.merchant_id { | ||
| Some(NameIdUnit { | ||
| id: merchant_id.clone(), | ||
| name: merchant_map | ||
| .get(merchant_id) | ||
| .ok_or(UserErrors::InternalServerError)? | ||
| .to_owned(), | ||
| }) | ||
| } else { | ||
| return Err(UserErrors::InternalServerError); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| let profile = match entity_type.ok_or(UserErrors::InternalServerError)? { | ||
| EntityType::Internal => { | ||
| return Err(UserErrors::InvalidRoleOperationWithMessage( | ||
| "Internal roles are not allowed for this operation".to_string(), | ||
| )); | ||
| } | ||
| EntityType::Organization | EntityType::Merchant => None, | ||
| EntityType::Profile => { | ||
| if let Some(profile_id) = &user_role.profile_id { | ||
| Some(NameIdUnit { | ||
| id: profile_id.clone(), | ||
| name: profile_map | ||
| .get(profile_id) | ||
| .ok_or(UserErrors::InternalServerError)? | ||
| .to_owned(), | ||
| }) | ||
| } else { | ||
| return Err(UserErrors::InternalServerError); | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
Can be done in single match statement.
crates/router/src/core/user.rs
Outdated
| if let Some(merchant_id) = &user_role.merchant_id { | ||
| Some(NameIdUnit { | ||
| id: merchant_id.clone(), | ||
| name: merchant_map | ||
| .get(merchant_id) | ||
| .ok_or(UserErrors::InternalServerError)? | ||
| .to_owned(), | ||
| }) | ||
| } else { | ||
| return Err(UserErrors::InternalServerError); | ||
| } |
| }; | ||
|
|
||
| let (merchant_ids, merchant_profile_ids) = user_roles_set.iter().try_fold( | ||
| (Vec::new(), Vec::new()), |
There was a problem hiding this comment.
You can probably use something like Vec::with_capacity(user_roles_set.len()) here, if the size of the Vec is known beforehand, and is same as user_roles_set.
There was a problem hiding this comment.
No the size is not fix, we will be only considering those use roles, where the entity type is merchant and profile.
And ignoring the internal and organisation in this use case
* 'main' of github.com:juspay/hyperswitch: feat(customer_v2): Add customer V2 delete api (#5518) chore(version): 2024.09.05.0 feat(user_roles): get user role details (#5777) feat(users): Add profile level invites (#5793) refactor(router): profile based routes for payouts (#5794) Feat(connector): [Fiuu] Add Card Flows (#5786) fix(cypress): fix fiservemea configs for cypress (#5772) fix(cypress): `api_key` check in cypress (#5787) feat(payment_methods_v2): Implemented Diesel and Domain models for v2 (#5700) fix(payout): query for getting a list of active payout IDs (#5771) refactor(router): remove admin v2 intermediate features (#5780) feat(revert): populate payment method details in payments response (#5785) chore(version): 2024.09.04.0 fix(connector): skip 3DS in `network_transaction_id` flow for cybersource (#5781) refactor(euclid): check the authenticity of profile_id being used (#5647) feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and ProfileLevel authentication (#5729) fix(router): make customer details None in the `Psync` flow if the customer is deleted (#5732) feat(connector): [DEUTSCHE] Add template code (#5774) chore(version): 2024.09.03.1 fix(router): send post message to window.parent instead of window.top in external 3ds flow (#5778)
Type of Change
Description
Add support to get user role details
Additional Changes
Motivation and Context
Closes #5776
How did you test it?
Request:
Response
Checklist
cargo +nightly fmt --allcargo clippy