Skip to content

Add soft delete for users with deleted users tab and E2E tests#815

Merged
tjementum merged 4 commits intomainfrom
pp-736-user-soft-delete
Jan 5, 2026
Merged

Add soft delete for users with deleted users tab and E2E tests#815
tjementum merged 4 commits intomainfrom
pp-736-user-soft-delete

Conversation

@tjementum
Copy link
Member

@tjementum tjementum commented Jan 4, 2026

Summary & Motivation

Add soft delete functionality for users, allowing Tenant Owners and Admins to delete users with the ability to restore them or permanently purge them. Previously, user deletion was immediate and irreversible. This feature provides a safety net for accidental deletions and compliance with data retention requirements.

  • Implement soft delete for User aggregate using the ISoftDeletable interface from the shared kernel
  • Add API endpoints for managing deleted users:
    • GET /api/users/deleted - list deleted users with pagination
    • POST /api/users/{id}/restore - restore a soft-deleted user
    • DELETE /api/users/{id}/purge - permanently delete a single user
    • POST /api/users/deleted/bulk-purge - permanently delete multiple users
    • POST /api/users/deleted/empty-recycle-bin - purge all deleted users
  • Create "Recycle bin" tab on the Users page with restore and purge functionality, accessible only to Owners and Admins
  • Add SmartDate component and useSmartDate hook for auto-updating relative time display ("Just now", "5 minutes ago", "2 hours ago"), used in the Users table for Created and Modified columns
  • Simplify formatDate utility to use fixed English month names for consistent formatting across browsers
  • Add comprehensive backend tests for soft delete, restore, single purge, bulk purge, and empty recycle bin operations
  • Add test verifying soft-deleted users cannot log in (returns fake login ID and sends unknown user email)
  • Add E2E tests covering the complete soft delete workflow including tab navigation, restore, and permanent deletion
  • Rename ForceHardDelete to ForcePurge and MarkForHardDelete to MarkForPurge in the ISoftDeletable interface for consistency
  • Improve E2E test reliability and fix back-office tests by dynamically reading internal email domain from platform-settings.jsonc

Checklist

  • I have added tests, or done manual regression tests
  • I have updated the documentation, if necessary

@tjementum tjementum self-assigned this Jan 4, 2026
@tjementum tjementum added the Enhancement New feature or request label Jan 4, 2026
@linear
Copy link

linear bot commented Jan 4, 2026

@tjementum tjementum moved this to 🏗 In Progress in Kanban board Jan 4, 2026
@tjementum tjementum force-pushed the pp-736-user-soft-delete branch 3 times, most recently from 8fb73b2 to 8e5f56c Compare January 5, 2026 02:08
@tjementum tjementum force-pushed the pp-736-user-soft-delete branch from 8e5f56c to ae342c9 Compare January 5, 2026 03:32
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2026

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

Approve Database Migration account-management database on stage

The following pending migration(s) will be applied to the database when approved:

  • AddUserSoftDeleteAndEmailConstraint (20260103000000_AddUserSoftDeleteAndEmailConstraint)

Migration Script

BEGIN TRANSACTION;
IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260103000000_AddUserSoftDeleteAndEmailConstraint'
)
BEGIN
    ALTER TABLE [Users] ADD [DeletedAt] datetimeoffset NULL;
END;

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260103000000_AddUserSoftDeleteAndEmailConstraint'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_Users_TenantId_Email] ON [Users] ([TenantId], [Email]) WHERE [DeletedAt] IS NULL');
END;

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20260103000000_AddUserSoftDeleteAndEmailConstraint'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20260103000000_AddUserSoftDeleteAndEmailConstraint', N'10.0.1');
END;

COMMIT;
GO

@tjementum tjementum merged commit 1367edf into main Jan 5, 2026
26 of 27 checks passed
@tjementum tjementum deleted the pp-736-user-soft-delete branch January 5, 2026 03:40
@github-project-automation github-project-automation bot moved this from 🏗 In Progress to ✅ Done in Kanban board Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant