-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(users): add support for profile user delete #5541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
32070eb
to
0aee7a6
Compare
a4e797c
to
5aa44b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
crates/router/src/core/user_role.rs
Outdated
UserRoleVersion::V2, | ||
) | ||
.await | ||
.change_context(UserErrors::InternalServerError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send 400
for not found.
if !user_role_deleted_flag { | ||
return Err(report!(UserErrors::InvalidDeleteOperation)) | ||
.attach_printable("User is not associated with the merchant"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
500
is not handled.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 --all
cargo clippy