Skip to content

Commit

Permalink
update sproc and migration file for collectionCipher_updateCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingo88 committed Dec 11, 2024
1 parent 7de47e4 commit ced2997
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ BEGIN
WHERE
[Id] = @CipherId
)

-- Common CTE for available collections
;WITH [AvailableCollectionsCTE] AS(
SELECT
SELECT
C.[Id]
INTO #TempAvailableCollections
FROM
[dbo].[Collection] C
INNER JOIN
Expand All @@ -44,7 +42,6 @@ BEGIN
CU.[HidePasswords] = 0
OR CG.[HidePasswords] = 0
)
)
-- Insert new collection assignments
INSERT INTO [dbo].[CollectionCipher] (
[CollectionId],
Expand All @@ -54,7 +51,7 @@ BEGIN
[Id],
@CipherId
FROM @CollectionIds
WHERE [Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
WHERE [Id] IN (SELECT [Id] FROM [#TempAvailableCollections])
AND NOT EXISTS (
SELECT 1
FROM [dbo].[CollectionCipher]
Expand All @@ -66,11 +63,12 @@ BEGIN
DELETE CC
FROM [dbo].[CollectionCipher] CC
WHERE CC.[CipherId] = @CipherId
AND CC.[CollectionId] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
AND CC.[CollectionId] IN (SELECT [Id] FROM [#TempAvailableCollections])
AND CC.[CollectionId] NOT IN (SELECT [Id] FROM @CollectionIds);

IF @OrgId IS NOT NULL
BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId
END
DROP TABLE #TempAvailableCollections;
END
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ BEGIN
WHERE
[Id] = @CipherId
)

-- Common CTE for available collections
;WITH [AvailableCollectionsCTE] AS(
SELECT
SELECT
C.[Id]
INTO #TempAvailableCollections
FROM
[dbo].[Collection] C
INNER JOIN
Expand All @@ -90,7 +88,6 @@ BEGIN
CU.[HidePasswords] = 0
OR CG.[HidePasswords] = 0
)
)
-- Insert new collection assignments
INSERT INTO [dbo].[CollectionCipher] (
[CollectionId],
Expand All @@ -100,7 +97,7 @@ BEGIN
[Id],
@CipherId
FROM @CollectionIds
WHERE [Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
WHERE [Id] IN (SELECT [Id] FROM [#TempAvailableCollections])
AND NOT EXISTS (
SELECT 1
FROM [dbo].[CollectionCipher]
Expand All @@ -112,12 +109,13 @@ BEGIN
DELETE CC
FROM [dbo].[CollectionCipher] CC
WHERE CC.[CipherId] = @CipherId
AND CC.[CollectionId] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
AND CC.[CollectionId] IN (SELECT [Id] FROM [#TempAvailableCollections])
AND CC.[CollectionId] NOT IN (SELECT [Id] FROM @CollectionIds);

IF @OrgId IS NOT NULL
BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId
END
DROP TABLE #TempAvailableCollections;
END
GO

0 comments on commit ced2997

Please sign in to comment.