Repository navigation
Gia/#283 role based acct mgt - #289
Conversation
✅ Deploy Preview for hope-for-haiti ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Greptile SummaryThis PR implements role-based access control enforcement for user account management, adding both API-level and UI-level guards against self-deactivation, unauthorized deactivation of privileged users, and permission escalation on super-admin accounts. Key changes:
Additional findings already tracked in prior reviews:
Confidence Score: 2/5
|
Additional Comments (1)
According to the PR description, the intent was to prevent deactivating users with BOTH |
|
hey gia, overall great work. In my initial ticket I noticed I made a logical mistake pertaining to non-super accounts with user_write permissions, specifically, this line: "If you DO have user_write permission, then you cannot deactivate or overwrite people with is_super and user_write. Again, thoroughly test this will all roles and accounts." What I meant to say was users that only have user_write (no is_super) should NOT be able to deactivate users with is_super OR users with user_write. Essentially, you shouldn't be able to deactivate an adjacent role or a higher role. That's my bad, I should've been more clear. Also, it looks like there are two docker command files that got caught in your commits, please remove those. If you can make this change that would be great, everything else looks perfect. thanks |
✅ Deploy Preview for hope-for-haiti ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Description
Resolves ticket number: #283
Verifies correct role-based account management/permissions.
Explain what your code changes:
Implemented comprehensive API-level and UI-level enforcement for user account management to prevent unauthorized deactivations and permission escalation.
Self-Deactivation Protection: Added logic to the PATCH /api/users/[id] route to prevent any user (including Super Admins) from setting their own enabled status to false.
Permission Hierarchy Enforcement: Restricted users with userWrite from deactivating or modifying permissions for accounts that possess both isSuper and userWrite privileges.
Access Control: Verified that users without userWrite permission are strictly blocked from accessing any "deactivate" or "update" functionality on the user management page.
UI Hardening: Removed the deactivation option from the UI popup for self-targeting actions to provide a smoother user experience and prevent invalid requests.
List the steps you took to test your code:
All enforcement rules were validated via Postman using session cookies extracted from local Chrome DevTools.
Test 1: Logged in as Super Admin and attempted a PATCH request to my own ID with {"enabled": false}. Result: 403 Forbidden.
Test 2: Logged in as Staff Admin and attempted to deactivate the Super Admin (ID 1). Result: 403 Forbidden.
Test 3: Logged in as Staff Admin and attempted to strip permissions from a Super Admin. Result: 403 Forbidden.
Test 4: Logged in as Distribution Lead (no userWrite) and attempted to deactivate a different user. Result: 403 Forbidden.
Manual UI Check: Confirmed the "Deactivate" button is hidden/removed in the browser when viewing my own account profile.
Checklist