mirror of
https://github.com/bitwarden/server
synced 2025-12-10 05:13:48 +00:00
updates to soft delete
This commit is contained in:
@@ -718,13 +718,10 @@ public class CipherService : ICipherService
|
|||||||
|
|
||||||
cipherDetails.DeletedDate = cipherDetails.RevisionDate = DateTime.UtcNow;
|
cipherDetails.DeletedDate = cipherDetails.RevisionDate = DateTime.UtcNow;
|
||||||
|
|
||||||
if (cipherDetails.ArchivedDate.HasValue)
|
// 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
|
||||||
// If the cipher was archived, clear the archived date when soft deleting
|
cipherDetails.ArchivedDate = null;
|
||||||
// If a user were to restore an archived cipher, it should go back to the vault not the archive vault
|
cipherDetails.Archives = null;
|
||||||
cipherDetails.ArchivedDate = null;
|
|
||||||
cipherDetails.Archives = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
await _securityTaskRepository.MarkAsCompleteByCipherIds([cipherDetails.Id]);
|
await _securityTaskRepository.MarkAsCompleteByCipherIds([cipherDetails.Id]);
|
||||||
await _cipherRepository.UpsertAsync(cipherDetails);
|
await _cipherRepository.UpsertAsync(cipherDetails);
|
||||||
|
|||||||
@@ -879,6 +879,12 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
|
|||||||
{
|
{
|
||||||
dbContext.Attach(cipher);
|
dbContext.Attach(cipher);
|
||||||
cipher.DeletedDate = action == CipherStateAction.Restore ? null : utcNow;
|
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;
|
cipher.RevisionDate = utcNow;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ BEGIN
|
|||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
|
|
||||||
CREATE TABLE #Temp
|
CREATE TABLE #Temp
|
||||||
(
|
(
|
||||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||||
[UserId] UNIQUEIDENTIFIER NULL,
|
[UserId] UNIQUEIDENTIFIER NULL,
|
||||||
[OrganizationId] UNIQUEIDENTIFIER NULL
|
[OrganizationId] UNIQUEIDENTIFIER NULL
|
||||||
@@ -30,7 +30,9 @@ BEGIN
|
|||||||
[dbo].[Cipher]
|
[dbo].[Cipher]
|
||||||
SET
|
SET
|
||||||
[DeletedDate] = @UtcNow,
|
[DeletedDate] = @UtcNow,
|
||||||
[RevisionDate] = @UtcNow
|
[RevisionDate] = @UtcNow,
|
||||||
|
[ArchivedDate] = NULL,
|
||||||
|
[Archives] = NULL
|
||||||
WHERE
|
WHERE
|
||||||
[Id] IN (SELECT [Id] FROM #Temp)
|
[Id] IN (SELECT [Id] FROM #Temp)
|
||||||
|
|
||||||
|
|||||||
@@ -643,3 +643,73 @@ BEGIN
|
|||||||
END
|
END
|
||||||
END
|
END
|
||||||
GO
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user