bitwarden-server/util
Rui Tomé 7cefca330b
[PM-26050] Migrate all DefaultUserCollection when claimed user is deleted (#6366)
* feat: migrate DefaultUserCollection to SharedCollection during user deletion

- Implemented migration of DefaultUserCollection to SharedCollection in EF UserRepository before deleting organization users.
- Updated stored procedures User_DeleteById and User_DeleteByIds to include migration logic.
- Added new migration script for updating stored procedures.

* Add unit test for user deletion and DefaultUserCollection migration

- Implemented a new test to verify the migration of DefaultUserCollection to SharedCollection during user deletion in UserRepository.
- The test ensures that the user is deleted and the associated collection is updated correctly.

* Refactor user deletion process in UserRepository

- Moved migrating DefaultUserCollection to SharedCollection to happen before the deletion of user-related entities.
- Updated the deletion logic to use ExecuteDeleteAsync for improved performance and clarity.
- Ensured that all related entities are removed in a single transaction to maintain data integrity.

* Add unit test for DeleteManyAsync in UserRepository

- Implemented a new test to verify the deletion of multiple users and the migration of their DefaultUserCollections to SharedCollections.
- Ensured that both users are deleted and their associated collections are updated correctly in a single transaction.

* Refactor UserRepositoryTests to use test user creation methods and streamline collection creation

* Ensure changes are saved after deleting users in bulk

* Refactor UserRepository to simplify migration queries and remove unnecessary loops for better performance

* Refactor UserRepository to encapsulate DefaultUserCollection migration logic in a separate method

* Refactor UserRepository to optimize deletion queries by using joins instead of subqueries for improved performance

* Refactor UserRepositoryTest DeleteManyAsync_Works to ensure GroupUser and CollectionUser deletion

---------

Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
2025-10-01 14:28:19 +01:00
..
Attachments Fix attachments container (#6165) 2025-08-06 14:44:01 -04:00
DbSeederUtility [PM-21075] Initial database seeder (#5703) 2025-05-09 15:00:26 +02:00
EfShared [PM-2633] Warnings cleanup (#3010) 2023-06-16 10:02:05 -04:00
Migrator [PM-26050] Migrate all DefaultUserCollection when claimed user is deleted (#6366) 2025-10-01 14:28:19 +01:00
MsSql feat: non-root self hosted images for standard deployment (#5701) 2025-05-30 10:29:47 -07:00
MsSqlMigratorUtility BRE-917 Update to Alpine base (#5976) 2025-07-28 10:56:20 -04:00
MySqlMigrations [SM-1489] machine account events (#6187) 2025-10-01 13:13:49 +00:00
Nginx Fixed Nginx entrypoint to cp with preserve owner (#6249) 2025-08-28 09:36:02 -04:00
PostgresMigrations [SM-1489] machine account events (#6187) 2025-10-01 13:13:49 +00:00
Seeder [PM-21075] Initial database seeder (#5703) 2025-05-09 15:00:26 +02:00
Server Add #nullable disable to platform code (#6057) 2025-07-08 10:25:59 -04:00
Setup Fix Dockerfiles that had BUILDPLATFORM specified for App Stages (#6162) 2025-08-05 17:36:04 -04:00
SqliteMigrations [SM-1489] machine account events (#6187) 2025-10-01 13:13:49 +00:00
SqlServerEFScaffold [deps] DbOps: Pin dependencies (#5715) 2025-04-28 22:04:00 -04:00