mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00

* feat(innovation-archive): Controller Work - Added bulk endpoints for archive and feature flagged them. * feat(innovation-archive): Controller Work - Added in archive unarchive stored procedure. * test(innovation-archive): Controller Work - Got test logic working. --------- Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
137 lines
2.6 KiB
Transact-SQL
137 lines
2.6 KiB
Transact-SQL
-- Cipher Archive
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[Cipher_Archive]
|
|
@Ids AS [dbo].[GuidIdArray] READONLY,
|
|
@UserId AS UNIQUEIDENTIFIER
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
CREATE TABLE #Temp
|
|
(
|
|
[Id] UNIQUEIDENTIFIER NOT NULL,
|
|
[UserId] UNIQUEIDENTIFIER NULL
|
|
)
|
|
|
|
INSERT INTO #Temp
|
|
SELECT
|
|
[Id],
|
|
[UserId]
|
|
FROM
|
|
[dbo].[UserCipherDetails](@UserId)
|
|
WHERE
|
|
[Edit] = 1
|
|
AND [ArchivedDate] IS NULL
|
|
AND [Id] IN (SELECT * FROM @Ids)
|
|
|
|
DECLARE @UtcNow DATETIME2(7) = GETUTCDATE();
|
|
UPDATE
|
|
[dbo].[Cipher]
|
|
SET
|
|
[ArchivedDate] = @UtcNow,
|
|
[RevisionDate] = @UtcNow
|
|
WHERE
|
|
[Id] IN (SELECT [Id] FROM #Temp)
|
|
|
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
|
|
|
DROP TABLE #Temp
|
|
|
|
SELECT @UtcNow
|
|
END
|
|
GO
|
|
|
|
-- Unarchive Cipher
|
|
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[Cipher_Unarchive]
|
|
@Ids AS [dbo].[GuidIdArray] READONLY,
|
|
@UserId AS UNIQUEIDENTIFIER
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
CREATE TABLE #Temp
|
|
(
|
|
[Id] UNIQUEIDENTIFIER NOT NULL,
|
|
[UserId] UNIQUEIDENTIFIER NULL
|
|
)
|
|
|
|
INSERT INTO #Temp
|
|
SELECT
|
|
[Id],
|
|
[UserId]
|
|
FROM
|
|
[dbo].[UserCipherDetails](@UserId)
|
|
WHERE
|
|
[Edit] = 1
|
|
AND [ArchivedDate] IS NOT NULL
|
|
AND [Id] IN (SELECT * FROM @Ids)
|
|
|
|
DECLARE @UtcNow DATETIME2(7) = GETUTCDATE();
|
|
UPDATE
|
|
[dbo].[Cipher]
|
|
SET
|
|
[ArchivedDate] = NULL,
|
|
[RevisionDate] = @UtcNow
|
|
WHERE
|
|
[Id] IN (SELECT [Id] FROM #Temp)
|
|
|
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
|
|
|
DROP TABLE #Temp
|
|
|
|
SELECT @UtcNow
|
|
END
|
|
GO
|
|
|
|
-- Update User Cipher Details With Archive
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[CipherDetails_ReadByIdUserId]
|
|
@Id UNIQUEIDENTIFIER,
|
|
@UserId UNIQUEIDENTIFIER
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
SELECT
|
|
[Id],
|
|
[UserId],
|
|
[OrganizationId],
|
|
[Type],
|
|
[Data],
|
|
[Attachments],
|
|
[CreationDate],
|
|
[RevisionDate],
|
|
[Favorite],
|
|
[FolderId],
|
|
[DeletedDate],
|
|
[Reprompt],
|
|
[Key],
|
|
[OrganizationUseTotp],
|
|
[ArchivedDate],
|
|
MAX ([Edit]) AS [Edit],
|
|
MAX ([ViewPassword]) AS [ViewPassword],
|
|
MAX ([Manage]) AS [Manage]
|
|
FROM
|
|
[dbo].[UserCipherDetails](@UserId)
|
|
WHERE
|
|
[Id] = @Id
|
|
GROUP BY
|
|
[Id],
|
|
[UserId],
|
|
[OrganizationId],
|
|
[Type],
|
|
[Data],
|
|
[Attachments],
|
|
[CreationDate],
|
|
[RevisionDate],
|
|
[Favorite],
|
|
[FolderId],
|
|
[DeletedDate],
|
|
[Reprompt],
|
|
[Key],
|
|
[OrganizationUseTotp],
|
|
[ArchivedDate]
|
|
END
|