ZCU-DATA/Prevent an admin from deleting their own account - #1398
Merged
milanmajchrak merged 1 commit intoAug 14, 2026
Conversation
…fal#1350) (#1306) * Issue 1349: admin user is not allowed to delete himself/herself * improve the fix: test context.getCurrentUser() for null * throw IllegalStateException rather than AuthorizeException, and allow client to see the error message (cherry picked from commit b913627) Co-authored-by: Milan Kuchtiak <kuchtiak@ufal.mff.cuni.cz> (cherry picked from commit 68463d4)
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.
Backport of #1306 (
68463d490f) fromdtq-devontocustomer/zcu-data.EPersonServiceImpl.delete()now refuses to delete the EPerson that is the current context user (unless authorization is being ignored, e.g. CLI/consumers), andEPersonRestRepositorymaps thatIllegalStateExceptionto a 400 Bad Request carrying the message, so the UI can show a friendly notification instead of a generic failure.Verified locally:
mvn -o checkstyle:check -pl dspace-api,dspace-server-webappclean;mvn -o compile -pl dspace-apiclean.Refs dataquest-dev/dspace-customers#855
Frontend counterpart: dataquest-dev/dspace-angular#1443 — the two must ship together.
How this was verified
Automated — runs on this PR
The change ships with an integration test that drives the real REST API:
EPersonRestRepositoryIT#deleteYourselfForbiddenlogs in as an administrator, callsDELETE /api/eperson/epersons/{own-id}, asserts 400, then asserts the account still exists.The Run Integration Tests CI job is green on this PR, and its log shows the class executing:
The base branch has 92
@Testmethods in that class — the 93rd is this one.Locally:
mvn -o checkstyle:check -pl dspace-api,dspace-server-webapp→ 0 violations.Manual — on a live instance
Throwaway DSpace 9.3 stack (own DB / Solr / assetstore, REST on :8091), logged in as an administrator:
DELETE /server/api/eperson/epersons/<own uuid>204, and a follow-upGET→404. The admin deleted their own account.400 Bad Request, follow-upGET→200. The account survives.The live run above was done on the JCU 9.3 pair. This branch carries a byte-identical patch —
git patch-id --stable=56b872c32d89on both — and its own Run Integration Tests job is green.Reviewer note — the message does not reach the client
The source commit intended to "allow client to see the error message", but the 400 body is DSpace's generic
{"status":400,"error":"Bad Request","message":"An exception has occurred"}— the text"You, as admin user, cannot delete yourself" never reaches the browser, because
DSpaceBadRequestExceptionis annotated@ResponseStatus(reason = "Bad Request").This does not weaken the fix: the deletion is refused server-side either way, and the frontend does not
depend on that string (it decides from its own identity check). Flagging it so nobody later builds on the
assumption that the message is visible.