diff --git a/src/app/access-control/epeople-registry/epeople-registry.component.spec.ts b/src/app/access-control/epeople-registry/epeople-registry.component.spec.ts index 5b3097dd6bd..a42b760dcfd 100644 --- a/src/app/access-control/epeople-registry/epeople-registry.component.spec.ts +++ b/src/app/access-control/epeople-registry/epeople-registry.component.spec.ts @@ -1,5 +1,5 @@ import { Router } from '@angular/router'; -import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; +import { defer, Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; import { CommonModule } from '@angular/common'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; @@ -382,6 +382,23 @@ describe('EPeopleRegistryComponent', () => { expect(modalService.open).not.toHaveBeenCalled(); expect(deleteSpy).not.toHaveBeenCalled(); })); + + it('should still show the friendly self-delete notification if the authenticated user id resolves late and the backend rejection carries no usable message', fakeAsync(() => { + modalRef.componentInstance.response = observableOf(true); + component.currentAuthenticatedUserId = EPersonMock.id; + ePersonDataServiceStub.deleteEPerson = jasmine.createSpy('deleteEPerson').and.returnValue(defer(() => { + component.currentAuthenticatedUserId = EPersonMock2.id; + return createFailedRemoteDataObject$(undefined, 400); + })); + + component.deleteEPerson(EPersonMock2); + tick(); + + expect(notificationsService.error).toHaveBeenCalled(); + let translatedKey: string; + notificationsService.error.calls.mostRecent().args[0].subscribe((value) => translatedKey = value); + expect(translatedKey).toBe('admin.access-control.epeople.notification.deleted.forbidden.self'); + })); }); describe('delete EPerson button when the isAuthorized returns false', () => { diff --git a/src/app/access-control/epeople-registry/epeople-registry.component.ts b/src/app/access-control/epeople-registry/epeople-registry.component.ts index 3e04efe00b5..14d9b245e29 100644 --- a/src/app/access-control/epeople-registry/epeople-registry.component.ts +++ b/src/app/access-control/epeople-registry/epeople-registry.component.ts @@ -224,7 +224,7 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { this.epersonService.deleteEPerson(ePerson).pipe(getFirstCompletedRemoteData()).subscribe((restResponse: RemoteData) => { if (restResponse.hasSucceeded) { this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', {name: this.dsoNameService.getName(ePerson)})); - } else if (this.deleteGuard.isSelfDeletionError(restResponse)) { + } else if (this.isCurrentUser(ePerson) || this.deleteGuard.isSelfDeletionError(restResponse)) { this.deleteGuard.showSelfDeleteNotification(); } else { this.notificationsService.error(this.translateService.get(this.labelPrefix + 'notification.deleted.failure', { diff --git a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts index c1edf22f15e..cbef5cf6033 100644 --- a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts +++ b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts @@ -1,4 +1,4 @@ -import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; +import { defer, Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; import { EPersonDeleteGuardService } from '../eperson-delete-guard.service'; import { CommonModule } from '@angular/common'; @@ -610,6 +610,21 @@ describe('EPersonFormComponent', () => { expect(modalService.open).not.toHaveBeenCalled(); expect(deleteSpy).not.toHaveBeenCalled(); }); + + it('should still show the friendly self-delete notification if the authenticated user id resolves late and the backend rejection carries no usable message', () => { + spyOn(component.epersonService, 'deleteEPerson').and.returnValue(defer(() => { + component.currentAuthenticatedUserId = eperson.id; + return createFailedRemoteDataObject$(undefined, 400); + })); + + const deleteButton = fixture.debugElement.query(By.css('.delete-button')); + deleteButton.triggerEventHandler('click', null); + + expect(notificationsService.error).toHaveBeenCalled(); + let translatedKey: string; + notificationsService.error.calls.mostRecent().args[0].subscribe((value) => translatedKey = value); + expect(translatedKey).toBe('admin.access-control.epeople.notification.deleted.forbidden.self'); + }); }); describe('self delete button', () => { diff --git a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts index 36304a67b60..85dc774a095 100644 --- a/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts +++ b/src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts @@ -535,7 +535,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy { if (restResponse?.hasSucceeded) { this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: this.dsoNameService.getName(eperson) })); void this.router.navigate([getEPersonsRoute()]); - } else if (this.deleteGuard.isSelfDeletionError(restResponse)) { + } else if (this.isCurrentUser(eperson) || this.deleteGuard.isSelfDeletionError(restResponse)) { this.deleteGuard.showSelfDeleteNotification(); } else { this.notificationsService.error(this.translateService.get(this.labelPrefix + 'notification.deleted.failure', {