1
0
mirror of https://github.com/bitwarden/server synced 2025-12-10 13:23:27 +00:00

updates to soft delete

This commit is contained in:
jaasen-livefront
2025-12-04 10:50:38 -08:00
parent b24edfac43
commit c7793499bd
4 changed files with 84 additions and 9 deletions

View File

@@ -718,13 +718,10 @@ public class CipherService : ICipherService
cipherDetails.DeletedDate = cipherDetails.RevisionDate = DateTime.UtcNow;
if (cipherDetails.ArchivedDate.HasValue)
{
// If the cipher was archived, clear the archived date when soft deleting
// If a user were to restore an archived cipher, it should go back to the vault not the archive vault
cipherDetails.ArchivedDate = null;
cipherDetails.Archives = null;
}
// Clear the archived date and archives when soft deleting
// If a user were to restore an archived cipher, it should go back to the vault not the archive vault
cipherDetails.ArchivedDate = null;
cipherDetails.Archives = null;
await _securityTaskRepository.MarkAsCompleteByCipherIds([cipherDetails.Id]);
await _cipherRepository.UpsertAsync(cipherDetails);

View File

@@ -879,6 +879,12 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
{
dbContext.Attach(cipher);
cipher.DeletedDate = action == CipherStateAction.Restore ? null : utcNow;
if (action == CipherStateAction.SoftDelete && (!string.IsNullOrWhiteSpace(cipher.Archives) || cipher.ArchivedDate != null))
{
// Clear out any per-user archive records on soft delete
cipher.Archives = null;
cipher.ArchivedDate = null;
}
cipher.RevisionDate = utcNow;
});
}

View File

@@ -30,7 +30,9 @@ BEGIN
[dbo].[Cipher]
SET
[DeletedDate] = @UtcNow,
[RevisionDate] = @UtcNow
[RevisionDate] = @UtcNow,
[ArchivedDate] = NULL,
[Archives] = NULL
WHERE
[Id] IN (SELECT [Id] FROM #Temp)

View File

@@ -643,3 +643,73 @@ BEGIN
END
END
GO
IF OBJECT_ID('[dbo].[Cipher_SoftDelete]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Cipher_SoftDelete];
END
GO
CREATE PROCEDURE [dbo].[Cipher_SoftDelete]
@Ids AS [dbo].[GuidIdArray] READONLY,
@UserId AS UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
CREATE TABLE #Temp
(
[Id] UNIQUEIDENTIFIER NOT NULL,
[UserId] UNIQUEIDENTIFIER NULL,
[OrganizationId] UNIQUEIDENTIFIER NULL
)
INSERT INTO #Temp
SELECT
[Id],
[UserId],
[OrganizationId]
FROM
[dbo].[UserCipherDetails](@UserId)
WHERE
[Edit] = 1
AND [DeletedDate] IS NULL
AND [Id] IN (SELECT * FROM @Ids)
-- Delete ciphers
DECLARE @UtcNow DATETIME2(7) = GETUTCDATE();
UPDATE
[dbo].[Cipher]
SET
[DeletedDate] = @UtcNow,
[RevisionDate] = @UtcNow,
[ArchivedDate] = NULL,
[Archives] = NULL
WHERE
[Id] IN (SELECT [Id] FROM #Temp)
-- Cleanup orgs
DECLARE @OrgId UNIQUEIDENTIFIER
DECLARE [OrgCursor] CURSOR FORWARD_ONLY FOR
SELECT
[OrganizationId]
FROM
#Temp
WHERE
[OrganizationId] IS NOT NULL
GROUP BY
[OrganizationId]
OPEN [OrgCursor]
FETCH NEXT FROM [OrgCursor] INTO @OrgId
WHILE @@FETCH_STATUS = 0 BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId
FETCH NEXT FROM [OrgCursor] INTO @OrgId
END
CLOSE [OrgCursor]
DEALLOCATE [OrgCursor]
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
DROP TABLE #Temp
END
GO