mirror of
https://github.com/bitwarden/server
synced 2025-12-10 21:33:41 +00:00
* migrate default collection to a shared collection when users are removed * remove redundant logic * fix test * fix tests * fix test * clean up * add migrations * run dotnet format * clean up, refactor duplicate logic to sproc, wip integration test * fix sql * add migration for new sproc * integration test wip * integration test wip * integration test wip * integration test wip * fix integration test LINQ expression * fix using wrong Id * wip integration test for DeleteManyAsync * fix LINQ * only set DefaultUserEmail when it is null in sproc * check for null * spelling, separate create and update request models * fix test * fix child class * refactor sproc * clean up * more cleanup * fix tests * fix user email * remove unneccesary test * add DefaultUserCollectionEmail to EF query * fix test * fix EF logic to match sprocs * clean up logic * cleanup
23 lines
749 B
Transact-SQL
23 lines
749 B
Transact-SQL
CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_MigrateDefaultCollection]
|
|
@Ids [dbo].[GuidIdArray] READONLY
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
DECLARE @UtcNow DATETIME2(7) = GETUTCDATE();
|
|
|
|
UPDATE c
|
|
SET
|
|
[DefaultUserCollectionEmail] = CASE WHEN c.[DefaultUserCollectionEmail] IS NULL THEN u.[Email] ELSE c.[DefaultUserCollectionEmail] END,
|
|
[RevisionDate] = @UtcNow,
|
|
[Type] = 0
|
|
FROM
|
|
[dbo].[Collection] c
|
|
INNER JOIN [dbo].[CollectionUser] cu ON c.[Id] = cu.[CollectionId]
|
|
INNER JOIN [dbo].[OrganizationUser] ou ON cu.[OrganizationUserId] = ou.[Id]
|
|
INNER JOIN [dbo].[User] u ON ou.[UserId] = u.[Id]
|
|
INNER JOIN @Ids i ON ou.[Id] = i.[Id]
|
|
WHERE
|
|
c.[Type] = 1
|
|
END
|
|
GO
|