Skip to content

VSB-TUO/Prevent an admin from deleting their own account - #1400

Merged
milanmajchrak merged 1 commit into
customer/vsb-tuofrom
vsb-tuo/be-forbid-admin-self-delete
Aug 14, 2026
Merged

VSB-TUO/Prevent an admin from deleting their own account#1400
milanmajchrak merged 1 commit into
customer/vsb-tuofrom
vsb-tuo/be-forbid-admin-self-delete

Conversation

@Kasinhou

@Kasinhou Kasinhou commented Aug 10, 2026

Copy link
Copy Markdown

Backport of #1306 (68463d490f) from dtq-dev onto customer/vsb-tuo.

EPersonServiceImpl.delete() now refuses to delete the EPerson that is the current context user (unless authorization is being ignored, e.g. CLI/consumers), and EPersonRestRepository maps that IllegalStateException to 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-webapp clean; mvn -o compile -pl dspace-api clean.

Refs dataquest-dev/dspace-customers#855

Frontend counterpart: dataquest-dev/dspace-angular#1445 — 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#deleteYourselfForbidden logs in as an administrator, calls
DELETE /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:

Tests run: 93, Failures: 0, Errors: 0, Skipped: 0 - in org.dspace.app.rest.EPersonRestRepositoryIT

The base branch has 92 @Test methods 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:

Backend Request Result
without the fix DELETE /server/api/eperson/epersons/<own uuid> 204, and a follow-up GET404. The admin deleted their own account.
with the fix the same request 400 Bad Request, follow-up GET200. The account survives.
with the fix delete a different EPerson still works — row disappears from the list

The live run above was done on the JCU 9.3 pair. This branch carries a byte-identical patch — git patch-id --stable = 56b872c32d89 on 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
DSpaceBadRequestException is 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.

…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)
@Kasinhou Kasinhou self-assigned this Aug 10, 2026
@Kasinhou Kasinhou changed the title Prevent an admin from deleting their own account VSB-TUO/Prevent an admin from deleting their own account Aug 10, 2026
@Kasinhou
Kasinhou requested a review from milanmajchrak August 11, 2026 07:12
@milanmajchrak
milanmajchrak merged commit a962c2e into customer/vsb-tuo Aug 14, 2026
11 checks passed
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