1
0
mirror of https://github.com/bitwarden/server synced 2026-01-04 17:43:53 +00:00

update collections admin proc and repo (#6374)

This commit is contained in:
Jordan Aasen
2025-09-26 10:05:56 -07:00
committed by GitHub
parent 80e7f4d85c
commit b9e8b11311
4 changed files with 109 additions and 43 deletions

View File

@@ -44,13 +44,13 @@ BEGIN
[CollectionId],
[CipherId]
)
SELECT
SELECT
[Id],
@CipherId
FROM @CollectionIds
WHERE [Id] IN (SELECT [Id] FROM [#TempAvailableCollections])
AND NOT EXISTS (
SELECT 1
SELECT 1
FROM [dbo].[CollectionCipher]
WHERE [CollectionId] = [@CollectionIds].[Id]
AND [CipherId] = @CipherId

View File

@@ -4,46 +4,52 @@
@CollectionIds AS [dbo].[GuidIdArray] READONLY
AS
BEGIN
SET NOCOUNT ON
SET NOCOUNT ON;
;WITH [AvailableCollectionsCTE] AS(
SELECT
Id
FROM
[dbo].[Collection]
WHERE
OrganizationId = @OrganizationId
),
[CollectionCiphersCTE] AS(
SELECT
[CollectionId],
[CipherId]
FROM
[dbo].[CollectionCipher]
WHERE
[CipherId] = @CipherId
-- Available collections for this org, excluding default collections
SELECT
C.[Id]
INTO #TempAvailableCollections
FROM [dbo].[Collection] AS C
WHERE
C.[OrganizationId] = @OrganizationId
AND C.[Type] <> 1; -- exclude DefaultUserCollection
-- Insert new collection assignments
INSERT INTO [dbo].[CollectionCipher] (
[CollectionId],
[CipherId]
)
MERGE
[CollectionCiphersCTE] AS [Target]
USING
@CollectionIds AS [Source]
ON
[Target].[CollectionId] = [Source].[Id]
AND [Target].[CipherId] = @CipherId
WHEN NOT MATCHED BY TARGET
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE]) THEN
INSERT VALUES
(
[Source].[Id],
@CipherId
)
WHEN NOT MATCHED BY SOURCE
AND [Target].[CipherId] = @CipherId THEN
DELETE
;
SELECT
S.[Id],
@CipherId
FROM @CollectionIds AS S
INNER JOIN #TempAvailableCollections AS A
ON A.[Id] = S.[Id]
WHERE NOT EXISTS (
SELECT 1
FROM [dbo].[CollectionCipher] AS CC
WHERE CC.[CollectionId] = S.[Id]
AND CC.[CipherId] = @CipherId
);
-- Delete removed collection assignments
DELETE CC
FROM [dbo].[CollectionCipher] AS CC
INNER JOIN #TempAvailableCollections AS A
ON A.[Id] = CC.[CollectionId]
WHERE CC.[CipherId] = @CipherId
AND NOT EXISTS (
SELECT 1
FROM @CollectionIds AS S
WHERE S.[Id] = CC.[CollectionId]
);
IF @OrganizationId IS NOT NULL
BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId;
END
END
DROP TABLE #TempAvailableCollections;
END
GO