Skip to content
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

feat(user): add support to delete user #3374

Merged
merged 12 commits into from
Jan 25, 2024
Merged

feat(user): add support to delete user #3374

merged 12 commits into from
Jan 25, 2024

Conversation

apoorvdixit88
Copy link
Contributor

@apoorvdixit88 apoorvdixit88 commented Jan 17, 2024

Type of Change

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

Description

Add add new endpoint /user/user/delete that deletes the user present in the merchant account

Here we have two scenarios

  • When user is related to more than one merchant accounts: Delete the user role for that particular merchant account. User will be present in other accounts.
  • When user is part of one merchant account: Delete user role and user completely.

Additional Changes

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

Motivation and Context

Currently there is no endpoint to remove the invited users

How did you test it?

  • Singup/Singin
    Use the following curl to invite users:
curl --location 'http://localhost:8080/user/user/invite' \
--header 'Authorization: Bearer JWT' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "name": "user2",
    "role_id": "merchant_admin"
}

Use the following curl to delete invited user:

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

Cases to handle:

  • only users with permission UsersWrite can delete
  • org_admin cannot be deleted
  • internal users cannot be deleted
  • user cannot delete himself

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
  • I added a CHANGELOG entry if applicable

@apoorvdixit88 apoorvdixit88 added the A-users Area: Users label Jan 17, 2024
@apoorvdixit88 apoorvdixit88 self-assigned this Jan 17, 2024
@apoorvdixit88 apoorvdixit88 requested review from a team as code owners January 17, 2024 13:43
@apoorvdixit88 apoorvdixit88 marked this pull request as draft January 17, 2024 13:43
@apoorvdixit88 apoorvdixit88 removed the request for review from a team January 18, 2024 13:09
@apoorvdixit88 apoorvdixit88 added S-waiting-on-review Status: This PR has been implemented and needs to be reviewed C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes labels Jan 18, 2024
@apoorvdixit88 apoorvdixit88 marked this pull request as ready for review January 18, 2024 13:13
@apoorvdixit88 apoorvdixit88 linked an issue Jan 18, 2024 that may be closed by this pull request
@@ -104,4 +104,18 @@ impl DashboardMetadata {
)
.await
}

pub async fn delete_user_scoped_dashboard_metadata(
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to delete_user_scoped_dashboard_metadata_by_merchant_id

Comment on lines 164 to 169
Self::UserNotExist => AER::BadRequest(ApiError::new(
sub_code,
30,
"User does not exist in records",
None,
)),
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

.find(|&role| role.merchant_id == user_from_token.merchant_id.as_str())
{
Some(user_role) => {
let _ = can_delete_user_role(&user_role.role_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

error handling ?

consts::user_role::ROLE_ID_ORGANIZATION_ADMIN
| consts::user_role::ROLE_ID_INTERNAL_ADMIN
| consts::user_role::ROLE_ID_INTERNAL_VIEW_ONLY_USER
| consts::user_role::INTERNAL_USER_MERCHANT_ID => {
Copy link
Contributor

Choose a reason for hiding this comment

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

??

@apoorvdixit88 apoorvdixit88 requested a review from racnan January 19, 2024 10:56
@racnan
Copy link
Contributor

racnan commented Jan 19, 2024

Description indicates you're deleting user from org but looks like you're deleting user from merchant account.

.find(|&role| role.merchant_id == user_from_token.merchant_id.as_str())
{
Some(user_role) => {
utils::user::validate_deletion_permission_for_role_id(&user_role.role_id)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

user_role util instead of user util

Comment on lines 116 to 126
pub fn validate_deletion_permission_for_role_id(role_id: &str) -> UserResult<()> {
match role_id {
consts::user_role::ROLE_ID_ORGANIZATION_ADMIN
| consts::user_role::ROLE_ID_INTERNAL_ADMIN
| consts::user_role::ROLE_ID_INTERNAL_VIEW_ONLY_USER => {
Err(UserErrors::InvalidDeleteOperation.into())
.attach_printable("Deletion not allowed for users with specific role id")
}
_ => Ok(()),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

make this property of predefined permission.

ivor11
ivor11 previously approved these changes Jan 19, 2024
Copy link
Contributor

@racnan racnan left a comment

Choose a reason for hiding this comment

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

Please test locally.

@@ -176,6 +176,7 @@ impl From<Flow> for ApiIdentifier {
| Flow::ForgotPassword
| Flow::ResetPassword
| Flow::InviteUser
| Flow::DeleteUser
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 in UserRoles

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.

LGTM

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jan 25, 2024
Merged via the queue into main with commit 7777710 Jan 25, 2024
10 checks passed
@Gnanasundari24 Gnanasundari24 deleted the delete-user branch January 25, 2024 07:22
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jan 28, 2024
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 M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: delete / deactivate user
6 participants