From 1bf06e9ec1c696c795490ad796ff4f261f0984d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Ko=C5=A1arko?= Date: Thu, 2 Jul 2026 13:03:20 +0200 Subject: [PATCH 1/4] UFAL/[Port to dtq-dev] 117 better control of user deletion in user administration page (#1335) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 117 better control of user deletion in user administration page (ufal/dspace-angular#140) * Disable self-delete and add delete warnings Prevent administrators from deleting their own account by disabling the delete button for the current authenticated user and showing a tooltip. Add a warningLabel input to the confirmation modal and render it when present. Implement logic in EPeopleRegistryComponent to determine the current user, compute a contextual delete warning (submitter, admin, or both) by querying workspace/workflow submissions, search, and group membership, and open the confirmation modal with that warning. Handle delete responses to show a friendly notification for backend 400 self-delete errors and use a generic failure notification otherwise. Update templates, component imports and helper methods (isCurrentUser, getDeleteWarningLabel, hasSubmittedItems, isAdministrator, isSelfDeletionError, showSelfDeleteNotification), and extend unit tests to cover disabled self-delete UI, composed warning labels, and notification behavior. * Prevent self-delete and show delete warnings Disable direct self-deletion and surface contextual warnings when deleting an EPerson. Template: render the delete button as disabled for the currently authenticated user and show a tooltip explaining self-delete restrictions; otherwise show the normal delete button. Component: track the current authenticated user, compute a combined warning label based on whether the EPerson is an administrator and/or has submitted items (checks workspace, workflow and archived submissions), present that warning in the confirmation modal, and handle deletion results including a friendly notification for backend self-delete errors. Added helper methods (isCurrentUser, getDeleteWarningLabel, hasSubmittedItems, isAdministrator, isSelfDeletionError, showSelfDeleteNotification) and adjusted delete flow to update canDelete$ appropriately. Tests: updated and added specs and mocks to cover the disabled self-delete UI, combined warning label usage, and the friendly self-delete error notification; added required service mocks and test setup changes. * Add EPerson delete warnings and self-delete message Add four i18n keys to en.json5 and cs.json5 for EPerson deletion flows: a forbidden self-delete message and warnings for deleting users who are submitters, administrators, or both. Provides localized English and Czech strings to surface these messages in the admin access-control UI. * Guard EPerson delete until auth ID resolved Prevent delete actions from running before the current authenticated user id is available. Add a template condition to hide the delete button until currentAuthenticatedUserId is set, add an early-return guard in deleteEPerson when the id is missing, and add a unit test ensuring the modal is not opened and delete is not called before the id is resolved. * Hide delete button until auth user ID resolved Prevent delete actions before the current authenticated user ID is available. Add *ngIf to the delete button in the template, add an early return guard in the component's delete flow when currentAuthenticatedUserId is not set, and include unit tests verifying the button is hidden and the delete/modal are not invoked until the ID is resolved. * Restrict delete button visibility and update tests Template: Wrap self-delete tooltip/button in a guard that checks epersonDto.ableToDelete and currentAuthenticatedUserId so delete UI is only rendered when deletion is allowed; simplify the enabledDeleteButton markup by removing a duplicated *ngIf on the inner button. Spec: remove unused DebugElement import, rename the test from 'should be disabled' to 'should be hidden', and update assertions to expect no delete buttons to be present (reflecting the new visibility behavior). * Detect Administrator group across paginated pages Add support for detecting Administrator group membership across paginated group lists and a unit test for it. - Introduce hasAdministratorGroupOnPage(groupsHref, currentPage) which fetches group pages (elementsPerPage=100) and recursively checks subsequent pages when the Administrator group is not found on the current page. - isAdministrator now delegates to hasAdministratorGroupOnPage starting at page 1. - Preserve error handling to return false on failures. - Add a unit test that simulates a two-page group response (administrator present on the second page) and verifies the component detects administrator membership and displays the correct warning label. * Detect Administrator group across pages Refactor group membership check to traverse paginated group lists until an "Administrator" group is found or pages are exhausted. Introduces a recursive hasAdministratorGroupOnPage that requests pages, validates payload/pageInfo, checks for the admin group, and requests the next page when needed. Adds a unit test covering detection on later pages and a minor spec setup tweak (setting currentAuthenticatedUserId) to correctly exercise deletion behavior. * Fix Czech typo in delete warning Corrects a spelling mistake in src/assets/i18n/cs.json5 for key admin.access-control.epeople.delete.warning.submitter: changed 'repositáři' to 'repozitáři' to improve Czech translation accuracy. * Make disabled delete button unfocusable Add tabindex="-1" to the disabled delete button in the epeople registry template so it cannot receive keyboard focus. This ensures the parent span (which provides the tooltip) remains the sole focus target for the current-user case, improving accessibility and preventing duplicate focusable elements. * Make disabled self-delete button unfocusable Add tabindex="-1" to the disabled delete button in eperson-form.component.html so the button cannot receive keyboard focus when showing the current user. The tooltip remains on the parent span, improving keyboard navigation and accessibility for the self-delete warning. * Remove stray 'after' attribute from eperson template Remove an unintended "after" attribute from a in eperson-form.component.html. The change cleans up the template by leaving only the intended *ngIf binding for conditional rendering of the delete/impersonation UI, preventing potential template parsing or linting issues. * code cleanup - remove duplicities * cleanup * copilot comments * copilot's comment --------- Co-authored-by: Ondrej Kosarko (cherry picked from commit d0b5ecf7b70ef4d40fbc4d8a968fc7c1eee273dd) * fix(access-control): quote submitter UUID in archived item search query --------- Co-authored-by: Amad Ul Hassan (cherry picked from commit 07957d83b13f1a202e065d9022628c1253276301) --- .../access-control/access-control.module.ts | 2 + .../epeople-registry.component.html | 25 ++- .../epeople-registry.component.spec.ts | 176 ++++++++++++++++-- .../epeople-registry.component.ts | 63 +++++-- .../eperson-delete-guard.service.spec.ts | 147 +++++++++++++++ .../eperson-delete-guard.service.ts | 145 +++++++++++++++ .../eperson-form/eperson-form.component.html | 17 +- .../eperson-form.component.spec.ts | 151 ++++++++++++++- .../eperson-form/eperson-form.component.ts | 92 ++++++--- .../confirmation-modal.component.html | 1 + .../confirmation-modal.component.spec.ts | 13 ++ .../confirmation-modal.component.ts | 1 + src/assets/i18n/cs.json5 | 12 ++ src/assets/i18n/en.json5 | 8 + 14 files changed, 787 insertions(+), 66 deletions(-) create mode 100644 src/app/access-control/epeople-registry/eperson-delete-guard.service.spec.ts create mode 100644 src/app/access-control/epeople-registry/eperson-delete-guard.service.ts diff --git a/src/app/access-control/access-control.module.ts b/src/app/access-control/access-control.module.ts index 3dc4b6cedc7..fa9c57b2b70 100644 --- a/src/app/access-control/access-control.module.ts +++ b/src/app/access-control/access-control.module.ts @@ -5,6 +5,7 @@ import { SharedModule } from '../shared/shared.module'; import { AccessControlRoutingModule } from './access-control-routing.module'; import { EPeopleRegistryComponent } from './epeople-registry/epeople-registry.component'; import { EPersonFormComponent } from './epeople-registry/eperson-form/eperson-form.component'; +import { EPersonDeleteGuardService } from './epeople-registry/eperson-delete-guard.service'; import { GroupFormComponent } from './group-registry/group-form/group-form.component'; import { MembersListComponent } from './group-registry/group-form/members-list/members-list.component'; import { SubgroupsListComponent } from './group-registry/group-form/subgroup-list/subgroups-list.component'; @@ -57,6 +58,7 @@ export const ValidateEmailErrorStateMatcher: DynamicErrorMessagesMatcher = provide: DYNAMIC_ERROR_MESSAGES_MATCHER, useValue: ValidateEmailErrorStateMatcher }, + EPersonDeleteGuardService, ] }) /** diff --git a/src/app/access-control/epeople-registry/epeople-registry.component.html b/src/app/access-control/epeople-registry/epeople-registry.component.html index 540f57032bf..d03b25418e5 100644 --- a/src/app/access-control/epeople-registry/epeople-registry.component.html +++ b/src/app/access-control/epeople-registry/epeople-registry.component.html @@ -72,11 +72,26 @@ + [ngbTooltip]="selfDeleteWarningLabel | translate" + container="body"> From 826d7ed82ea1bfbf429537a4d462aa31a334b2d5 Mon Sep 17 00:00:00 2001 From: Matus Kasak Date: Fri, 14 Aug 2026 11:06:24 +0200 Subject: [PATCH 4/4] Reword the Czech self-delete / delete-warning messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrites the four Czech strings for the self-delete guard so they read naturally rather than as literal translations, keeping the repository's established Czech terminology (uživatel / správce / záznamy / smazat) and active phrasing ("Jeho smazáním odeberete…" instead of the nominal "Smazání tohoto uživatele odebere…"). Wording is identical across all customer branches. Raised in review on PR #1447. Refs dataquest-dev/dspace-customers#855 --- src/assets/i18n/cs.json5 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/assets/i18n/cs.json5 b/src/assets/i18n/cs.json5 index 206f6d63dfe..0fdfc18a3f9 100644 --- a/src/assets/i18n/cs.json5 +++ b/src/assets/i18n/cs.json5 @@ -537,16 +537,16 @@ "admin.access-control.epeople.notification.deleted.success": "Úspěšně odstraněn uživatel: \"{{name}}\"", // "admin.access-control.epeople.notification.deleted.forbidden.self": "You cannot delete your own EPerson account.", - "admin.access-control.epeople.notification.deleted.forbidden.self": "Nemůžete smazat svůj vlastní účet uživatele.", + "admin.access-control.epeople.notification.deleted.forbidden.self": "Nemůžete smazat svůj vlastní uživatelský účet.", // "admin.access-control.epeople.delete.warning.submitter": "Warning: this user has submitted items. Deleting this EPerson may affect submission ownership and related repository records.", - "admin.access-control.epeople.delete.warning.submitter": "Upozornění: Tento uživatel odeslal položky. Smazání tohoto uživatele může ovlivnit vlastnictví příspěvků a související záznamy v repozitáři.", + "admin.access-control.epeople.delete.warning.submitter": "Upozornění: Tento uživatel vložil do repozitáře záznamy. Jeho smazáním můžete ovlivnit vlastnictví těchto záznamů i souvisejících dat v repozitáři.", // "admin.access-control.epeople.delete.warning.admin": "Warning: this user has administrator privileges. Deleting this EPerson will remove an administrator account.", - "admin.access-control.epeople.delete.warning.admin": "Upozornění: Tento uživatel má oprávnění správce. Smazání tohoto uživatele odebere účet správce.", + "admin.access-control.epeople.delete.warning.admin": "Upozornění: Tento uživatel má práva správce. Jeho smazáním odeberete účet správce.", // "admin.access-control.epeople.delete.warning.submitterAndAdmin": "Warning: this user has submitted items and has administrator privileges. Deleting this EPerson may affect submission ownership and remove an administrator account.", - "admin.access-control.epeople.delete.warning.submitterAndAdmin": "Upozornění: Tento uživatel odeslal položky a má oprávnění správce. Smazání tohoto uživatele může ovlivnit vlastnictví příspěvků a odebrat účet správce.", + "admin.access-control.epeople.delete.warning.submitterAndAdmin": "Upozornění: Tento uživatel vložil do repozitáře záznamy a má práva správce. Jeho smazáním můžete ovlivnit vlastnictví záznamů a zároveň odeberete účet správce.", // "admin.access-control.groups.title": "Groups", "admin.access-control.groups.title": "Skupiny",