fix(auth): harden user update authorization#1081
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the auth/user-management paths by preventing role escalation via user self-updates and by introducing a safeguard that blocks demoting the last remaining admin user.
Changes:
- Add
RequesterIsAdminto the UpdateUser use-case input and ignore role changes for non-admin requesters. - Prevent demoting the last admin (core auth service + API error mapping + UI localization).
- Add focused tests covering role escalation prevention and last-admin demotion behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/leafwiki-ui/src/locales/en/errors.json | Adds localized UI copy for the “last admin cannot be demoted” error template. |
| internal/wiki/auth/use_cases.go | Adds requester context to UpdateUser and conditionally applies/validates role changes. |
| internal/wiki/auth/use_cases_test.go | Adds regression/behavior tests for UpdateUser role handling and last-admin constraints. |
| internal/wiki/auth/routes.go | Makes role optional in the update request payload and passes admin-ness to the use-case. |
| internal/wiki/auth/errors.go | Adds a new auth error code and maps the core error to an API response. |
| internal/core/auth/user_store.go | Adds a store helper to count admin users. |
| internal/core/auth/user_service.go | Blocks demoting the last admin user. |
| internal/core/auth/user_service_test.go | Adds tests for last-admin demotion blocking and demotion when another admin exists. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
47c6d24 to
f88499f
Compare
Resolve merge conflicts in auth and revision code while preserving the admin role update fix and revision path validation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.