Skip to content

Conversation

apoorvdixit88
Copy link
Contributor

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

  • Add support to delete profile level users
  • Delete is backward compatible
  • Delete to support both V1 and V2 operations accordingly

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Closes #5540

How did you test it?

Use the curl to delete user role

curl --location --request DELETE 'http://localhost:8080/user/user/delete' \
--header 'Authorization: Bearer JWT' \
--header 'Content-Type: application/json' \
--data-raw '{
  "email": "email_to_delete"
}'

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@apoorvdixit88 apoorvdixit88 added C-feature Category: Feature request or enhancement C-refactor Category: Refactor A-users Area: Users labels Aug 6, 2024
@apoorvdixit88 apoorvdixit88 self-assigned this Aug 6, 2024
@apoorvdixit88 apoorvdixit88 requested review from a team as code owners August 6, 2024 11:03
Copy link
Contributor

@ThisIsMani ThisIsMani left a 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.

Comment on lines 379 to 384
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(),
)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle these errors separately.

.attach_printable("User is not associated with the merchant");
}

// If user has no more role associated with it then deleting user
Copy link
Contributor

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.

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Aug 12, 2024
@apoorvdixit88
Copy link
Contributor Author

This might break when org level roles are updatable or deletable.

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.

Comment on lines 148 to 161
(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)),
)),
)
Copy link
Contributor

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.

Comment on lines 156 to 160
.or(dsl::org_id.eq(org_id).and(
dsl::merchant_id
.eq(merchant_id)
.and(dsl::profile_id.eq(profile_id)),
)),
Copy link
Contributor

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(_).

Comment on lines 179 to 196
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

UserRoleVersion::V2,
)
.await
.change_context(UserErrors::InternalServerError)
Copy link
Contributor

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.

Comment on lines +468 to +470
if !user_role_deleted_flag {
return Err(report!(UserErrors::InvalidDeleteOperation))
.attach_printable("User is not associated with the merchant");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

500 is not handled.

Comment on lines 176 to 183
pub fn entity_level(entity_type: EntityType) -> u8 {
match entity_type {
EntityType::Internal => 3,
EntityType::Organization => 2,
EntityType::Merchant => 1,
EntityType::Profile => 0,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Aug 13, 2024
Copy link
Contributor

@ThisIsMani ThisIsMani left a 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.

.change_context(UserErrors::InternalServerError)?;

// If user has no more role associated with him then deleting user
if user_roles.is_empty() {
Copy link
Contributor

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.

ThisIsMani
ThisIsMani previously approved these changes Aug 14, 2024
.list_user_roles_by_user_id(user_id, version)
.await
) -> CustomResult<storage::UserRole, errors::StorageError> {
self.find_user_role_by_user_id_and_lineage(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.find_user_role_by_user_id_and_lineage(
self.diesel_store.find_user_role_by_user_id_and_lineage(

Copy link
Member

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.

profile_id: Option<&String>,
version: enums::UserRoleVersion,
) -> CustomResult<storage::UserRole, errors::StorageError> {
self.delete_user_role_by_user_id_and_lineage(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.delete_user_role_by_user_id_and_lineage(
self.diesel_store.delete_user_role_by_user_id_and_lineage(

Copy link
Member

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.

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Aug 14, 2024
Merged via the queue into main with commit 19a9180 Aug 14, 2024
14 checks passed
@Gnanasundari24 Gnanasundari24 deleted the fix-delete-user-role branch August 14, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-users Area: Users C-feature Category: Feature request or enhancement C-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: support profile level delete in V1 - V2
5 participants