feat(users): add support for profile user delete#5541
Conversation
32070eb to
0aee7a6
Compare
a4e797c to
5aa44b5
Compare
ThisIsMani
left a comment
There was a problem hiding this comment.
This might break when org level roles are updatable or deletable.
crates/router/src/core/user_role.rs
Outdated
| if !target_role_info.is_deletable() | ||
| || !utils::user_role::is_valid_entity_operation( | ||
| deletion_requestor_role_info.get_entity_type(), | ||
| target_role_info.get_entity_type(), | ||
| ) | ||
| { |
There was a problem hiding this comment.
Handle these errors separately.
crates/router/src/core/user_role.rs
Outdated
| .attach_printable("User is not associated with the merchant"); | ||
| } | ||
|
|
||
| // If user has no more role associated with it then deleting user |
There was a problem hiding this comment.
Change this comment or move this to bottom.
For V1 org_level roles are neither updatable nor deletable. With V2 it will work fine. Also we won't be introducing org_level roles in V1. |
| (dsl::org_id | ||
| .eq(org_id.clone()) | ||
| .and(dsl::merchant_id.is_null().and(dsl::profile_id.is_null()))) | ||
| .or(dsl::org_id.eq(org_id.clone()).and( | ||
| dsl::merchant_id | ||
| .eq(merchant_id.clone()) | ||
| .and(dsl::profile_id.is_null()), | ||
| )) | ||
| .or(dsl::org_id.eq(org_id).and( | ||
| dsl::merchant_id | ||
| .eq(merchant_id) | ||
| .and(dsl::profile_id.eq(profile_id)), | ||
| )), | ||
| ) |
There was a problem hiding this comment.
lets have this as a helper function.
| .or(dsl::org_id.eq(org_id).and( | ||
| dsl::merchant_id | ||
| .eq(merchant_id) | ||
| .and(dsl::profile_id.eq(profile_id)), | ||
| )), |
There was a problem hiding this comment.
put this under if let Some(_).
| let predicate = dsl::user_id | ||
| .eq(user_id) | ||
| .and( | ||
| (dsl::org_id | ||
| .eq(org_id.clone()) | ||
| .and(dsl::merchant_id.is_null().and(dsl::profile_id.is_null()))) | ||
| .or(dsl::org_id.eq(org_id.clone()).and( | ||
| dsl::merchant_id | ||
| .eq(merchant_id.clone()) | ||
| .and(dsl::profile_id.is_null()), | ||
| )) | ||
| .or(dsl::org_id.eq(org_id).and( | ||
| dsl::merchant_id | ||
| .eq(merchant_id) | ||
| .and(dsl::profile_id.eq(profile_id)), | ||
| )), | ||
| ) | ||
| .and(dsl::version.eq(version)); |
crates/router/src/core/user_role.rs
Outdated
| UserRoleVersion::V2, | ||
| ) | ||
| .await | ||
| .change_context(UserErrors::InternalServerError) |
| if !user_role_deleted_flag { | ||
| return Err(report!(UserErrors::InvalidDeleteOperation)) | ||
| .attach_printable("User is not associated with the merchant"); |
crates/router/src/utils/user_role.rs
Outdated
| pub fn entity_level(entity_type: EntityType) -> u8 { | ||
| match entity_type { | ||
| EntityType::Internal => 3, | ||
| EntityType::Organization => 2, | ||
| EntityType::Merchant => 1, | ||
| EntityType::Profile => 0, | ||
| } | ||
| } |
There was a problem hiding this comment.
ThisIsMani
left a comment
There was a problem hiding this comment.
Please remove the old delete function.
crates/router/src/core/user_role.rs
Outdated
| .change_context(UserErrors::InternalServerError)?; | ||
|
|
||
| // If user has no more role associated with him then deleting user | ||
| if user_roles.is_empty() { |
There was a problem hiding this comment.
You can check if v2 roles are also empty.
crates/router/src/db/kafka_store.rs
Outdated
| .list_user_roles_by_user_id(user_id, version) | ||
| .await | ||
| ) -> CustomResult<storage::UserRole, errors::StorageError> { | ||
| self.find_user_role_by_user_id_and_lineage( |
There was a problem hiding this comment.
| self.find_user_role_by_user_id_and_lineage( | |
| self.diesel_store.find_user_role_by_user_id_and_lineage( |
There was a problem hiding this comment.
In kakfaStore if we can self.functions will causes stack_overflow. So avoid following that.
crates/router/src/db/kafka_store.rs
Outdated
| profile_id: Option<&String>, | ||
| version: enums::UserRoleVersion, | ||
| ) -> CustomResult<storage::UserRole, errors::StorageError> { | ||
| self.delete_user_role_by_user_id_and_lineage( |
There was a problem hiding this comment.
| self.delete_user_role_by_user_id_and_lineage( | |
| self.diesel_store.delete_user_role_by_user_id_and_lineage( |
There was a problem hiding this comment.
In kakfaStore if we can self.functions will causes stack_overflow. So avoid following that.
Type of Change
Description
Additional Changes
Motivation and Context
Closes #5540
How did you test it?
Use the curl to delete user role
Checklist
cargo +nightly fmt --allcargo clippy