Skip to content

Implement user deletion functionality - #2811

Merged
NatSquared merged 11 commits into
mainfrom
DEP-245-delete-users
Apr 9, 2026
Merged

Implement user deletion functionality#2811
NatSquared merged 11 commits into
mainfrom
DEP-245-delete-users

Conversation

@NatSquared

Copy link
Copy Markdown
Collaborator

Issue #: 🎟️ DEP-239

Description of changes:

  • Feature Add "delete user" functionality to user management section
    • Added a "Delete User" button to the user details page in the admin view, visible only to super admins.
    • Updated the API to include a DELETE endpoint for users, which checks for appropriate permissions and handles cascading deletions of related data (e.g. role assignments).
    • Added success and error messages to provide feedback on the deletion process.
    • Reworked the user details component to rearrange the existing layout and accommodate the new delete button, while ensuring a clear and intuitive user experience.

User Guide update ticket (if applicable):

@codecov-commenter

codecov-commenter commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.71956% with 120 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.31%. Comparing base (f054e52) to head (48fd174).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...ponents/userManagement/userDetails/UserDetails.tsx 65.38% 27 Missing ⚠️
...ents/userManagement/common/RoleAssignmentModal.tsx 57.37% 26 Missing ⚠️
...nents/userManagement/common/useEngagementSearch.ts 26.08% 17 Missing ⚠️
api/src/api/services/staff_user_service.py 38.88% 11 Missing ⚠️
...s/userManagement/common/EngagementAutocomplete.tsx 28.57% 10 Missing ⚠️
.../userManagement/userDetails/UserDetailsContext.tsx 65.00% 7 Missing ⚠️
api/src/api/resources/staff_user.py 45.45% 6 Missing ⚠️
.../components/userManagement/common/ModalActions.tsx 57.14% 3 Missing ⚠️
...nts/userManagement/userDetails/AddToEngagement.tsx 57.14% 3 Missing ⚠️
...ponents/userManagement/listing/ActionsDropDown.tsx 0.00% 2 Missing ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2811      +/-   ##
==========================================
- Coverage   75.32%   75.31%   -0.01%     
==========================================
  Files         525      529       +4     
  Lines       20143    20164      +21     
  Branches     1564     1490      -74     
==========================================
+ Hits        15172    15187      +15     
- Misses       4965     4971       +6     
  Partials        6        6              
Flag Coverage Δ
api 86.14% <41.37%> (-0.12%) ⬇️
web 62.00% <57.43%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
api/src/api/config.py 97.29% <ø> (ø)
web/src/apiManager/endpoints/index.ts 100.00% <ø> (ø)
...userManagement/userDetails/UserDetailsSkeleton.tsx 80.00% <100.00%> (-20.00%) ⬇️
...rc/components/userManagement/userDetails/index.tsx 100.00% <100.00%> (ø)
web/src/styles/Theme.tsx 87.50% <ø> (ø)
...ponents/userManagement/listing/AssignRoleModal.tsx 85.71% <66.66%> (+38.09%) ⬆️
...nents/userManagement/listing/ReassignRoleModal.tsx 85.71% <66.66%> (+15.71%) ⬆️
...ts/userManagement/userDetails/UserStatusButton.tsx 62.06% <83.33%> (+0.66%) ⬆️
web/src/services/userService/index.ts 24.09% <66.66%> (ø)
...ponents/userManagement/listing/ActionsDropDown.tsx 44.00% <0.00%> (-1.84%) ⬇️
... and 11 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@NatSquared
NatSquared marked this pull request as ready for review April 8, 2026 01:01

@jareth-whitney jareth-whitney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Everything looks good, I'm just wondering if we need to handle cascading with other tables when a user is deleted. Perhaps the deactivation filter is enough to get around the cascading, just something to consider. Approved!

status_code=HTTPStatus.BAD_REQUEST,
)

if actor_external_id and db_user.external_id.lower() == actor_external_id.lower():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perfect, I was wondering it this would be here. We should definitely stop people from deleting theirselves.

if db_user is None:
raise BusinessException(error='User not found.', status_code=HTTPStatus.NOT_FOUND)

if db_user.status_id != UserStatus.INACTIVE.value:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do we have to do in order to deactivate a user?

if (savedUser.status_id !== USER_STATUS.INACTIVE.value)
return dispatch(openNotification({ severity: 'error', text: 'User must be deactivated before deletion.' }));
if (isSelf)
return dispatch(openNotification({ severity: 'error', text: 'You cannot delete your own account.' }));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the front-end redundancies, I think it's important to have these checks front and back.

onClick={handleDeleteUser}
fullWidth
loading={isDeletingUser}
disabled={!canDeleteUser}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So the delete user item will appear if you're a super admin, but there are some scenarios where it will still be disabled (like if it's yourself, etc). Makes sense.

Comment thread CHANGELOG.MD
- Added a "Delete User" button to the user details page in the admin view, visible only to super admins.
- Updated the API to include a DELETE endpoint for users, which checks for appropriate permissions and handles cascading deletions of related data (e.g. role assignments).
- Added success and error messages to provide feedback on the deletion process.
- Reworked the user details component to rearrange the existing layout and accommodate the new delete button, while ensuring a clear and intuitive user experience.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should there be any cascades for other tables when a user is deleted? Or does the de-activation filter deal with that? For instance, what happens if someone is a project lead, then is deleted?

@sonarqubecloud

sonarqubecloud Bot commented Apr 9, 2026

Copy link
Copy Markdown

@NatSquared
NatSquared merged commit 712b6a9 into main Apr 9, 2026
16 checks passed
@NatSquared
NatSquared deleted the DEP-245-delete-users branch April 9, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants