diff --git a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId_V2.sql b/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId_V2.sql deleted file mode 100644 index de8cb6e8fb..0000000000 --- a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId_V2.sql +++ /dev/null @@ -1,31 +0,0 @@ -CREATE PROCEDURE [dbo].[CollectionCipher_ReadByUserIdCipherId_V2] - @UserId UNIQUEIDENTIFIER, - @CipherId UNIQUEIDENTIFIER -AS -BEGIN - SET NOCOUNT ON - - SELECT - CC.* - FROM - [dbo].[CollectionCipher] CC - INNER JOIN - [dbo].[Collection] S ON S.[Id] = CC.[CollectionId] - INNER JOIN - [dbo].[OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] AND OU.[UserId] = @UserId - LEFT JOIN - [dbo].[CollectionUser] CU ON CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[Group] G ON G.[Id] = GU.[GroupId] - LEFT JOIN - [dbo].[CollectionGroup] CG ON CG.[CollectionId] = CC.[CollectionId] AND CG.[GroupId] = GU.[GroupId] - WHERE - CC.[CipherId] = @CipherId - AND OU.[Status] = 2 -- Confirmed - AND ( - CU.[CollectionId] IS NOT NULL - OR CG.[CollectionId] IS NOT NULL - ) -END diff --git a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserId_V2.sql b/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserId_V2.sql deleted file mode 100644 index 6a0b444c3f..0000000000 --- a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserId_V2.sql +++ /dev/null @@ -1,29 +0,0 @@ -CREATE PROCEDURE [dbo].[CollectionCipher_ReadByUserId_V2] - @UserId UNIQUEIDENTIFIER -AS -BEGIN - SET NOCOUNT ON - - SELECT - CC.* - FROM - [dbo].[CollectionCipher] CC - INNER JOIN - [dbo].[Collection] S ON S.[Id] = CC.[CollectionId] - INNER JOIN - [dbo].[OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] AND OU.[UserId] = @UserId - LEFT JOIN - [dbo].[CollectionUser] CU ON CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[Group] G ON G.[Id] = GU.[GroupId] - LEFT JOIN - [dbo].[CollectionGroup] CG ON CG.[CollectionId] = CC.[CollectionId] AND CG.[GroupId] = GU.[GroupId] - WHERE - OU.[Status] = 2 -- Confirmed - AND ( - CU.[CollectionId] IS NOT NULL - OR CG.[CollectionId] IS NOT NULL - ) -END diff --git a/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollectionsForCiphers_V2.sql b/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollectionsForCiphers_V2.sql deleted file mode 100644 index ab06d65e4f..0000000000 --- a/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollectionsForCiphers_V2.sql +++ /dev/null @@ -1,62 +0,0 @@ -CREATE PROCEDURE [dbo].[CollectionCipher_UpdateCollectionsForCiphers_V2] - @CipherIds AS [dbo].[GuidIdArray] READONLY, - @OrganizationId UNIQUEIDENTIFIER, - @UserId UNIQUEIDENTIFIER, - @CollectionIds AS [dbo].[GuidIdArray] READONLY -AS -BEGIN - SET NOCOUNT ON - - CREATE TABLE #AvailableCollections ( - [Id] UNIQUEIDENTIFIER - ) - - INSERT INTO #AvailableCollections - SELECT - C.[Id] - FROM - [dbo].[Collection] C - INNER JOIN - [Organization] O ON O.[Id] = C.[OrganizationId] - INNER JOIN - [dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId - LEFT JOIN - [dbo].[CollectionUser] CU ON CU.[CollectionId] = C.[Id] AND CU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[Group] G ON G.[Id] = GU.[GroupId] - LEFT JOIN - [dbo].[CollectionGroup] CG ON CG.[CollectionId] = C.[Id] AND CG.[GroupId] = GU.[GroupId] - WHERE - O.[Id] = @OrganizationId - AND O.[Enabled] = 1 - AND OU.[Status] = 2 -- Confirmed - AND ( - CU.[ReadOnly] = 0 - OR CG.[ReadOnly] = 0 - ) - - IF (SELECT COUNT(1) FROM #AvailableCollections) < 1 - BEGIN - -- No writable collections available to share with in this organization. - RETURN - END - - INSERT INTO [dbo].[CollectionCipher] - ( - [CollectionId], - [CipherId] - ) - SELECT - [Collection].[Id], - [Cipher].[Id] - FROM - @CollectionIds [Collection] - INNER JOIN - @CipherIds [Cipher] ON 1 = 1 - WHERE - [Collection].[Id] IN (SELECT [Id] FROM #AvailableCollections) - - EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId -END diff --git a/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollections_V2.sql b/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollections_V2.sql deleted file mode 100644 index c540c17378..0000000000 --- a/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollections_V2.sql +++ /dev/null @@ -1,77 +0,0 @@ -CREATE PROCEDURE [dbo].[CollectionCipher_UpdateCollections_V2] - @CipherId UNIQUEIDENTIFIER, - @UserId UNIQUEIDENTIFIER, - @CollectionIds AS [dbo].[GuidIdArray] READONLY -AS -BEGIN - SET NOCOUNT ON - - DECLARE @OrgId UNIQUEIDENTIFIER = ( - SELECT TOP 1 - [OrganizationId] - FROM - [dbo].[Cipher] - WHERE - [Id] = @CipherId - ) - - ;WITH [AvailableCollectionsCTE] AS( - SELECT - C.[Id] - FROM - [dbo].[Collection] C - INNER JOIN - [Organization] O ON O.[Id] = C.[OrganizationId] - INNER JOIN - [dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId - LEFT JOIN - [dbo].[CollectionUser] CU ON CU.[CollectionId] = C.[Id] AND CU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[Group] G ON G.[Id] = GU.[GroupId] - LEFT JOIN - [dbo].[CollectionGroup] CG ON CG.[CollectionId] = C.[Id] AND CG.[GroupId] = GU.[GroupId] - WHERE - O.[Id] = @OrgId - AND O.[Enabled] = 1 - AND OU.[Status] = 2 -- Confirmed - AND ( - CU.[ReadOnly] = 0 - OR CG.[ReadOnly] = 0 - ) - ), - [CollectionCiphersCTE] AS( - SELECT - [CollectionId], - [CipherId] - FROM - [dbo].[CollectionCipher] - WHERE - [CipherId] = @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 - AND [Target].[CollectionId] IN (SELECT [Id] FROM [AvailableCollectionsCTE]) THEN - DELETE - ; - - IF @OrgId IS NOT NULL - BEGIN - EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId - END -END diff --git a/util/Migrator/DbScripts/2024-07-16_02_DropCollectionCipherSprocs.sql b/util/Migrator/DbScripts/2024-07-16_02_DropCollectionCipherSprocs.sql new file mode 100644 index 0000000000..d2168354a1 --- /dev/null +++ b/util/Migrator/DbScripts/2024-07-16_02_DropCollectionCipherSprocs.sql @@ -0,0 +1,26 @@ +-- Clean up chore: delete v2 CollectionCipher sprocs +-- These were already copied back to v0 in 2024-07-09_00_CollectionCipherRemoveAccessAll + +IF OBJECT_ID('[dbo].[CollectionCipher_ReadByUserId_V2]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[CollectionCipher_ReadByUserId_V2] +END +GO + +IF OBJECT_ID('[dbo].[CollectionCipher_ReadByUserIdCipherId_V2]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[CollectionCipher_ReadByUserIdCipherId_V2] +END +GO + +IF OBJECT_ID('[dbo].[CollectionCipher_UpdateCollections_V2]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[CollectionCipher_UpdateCollections_V2] +END +GO + +IF OBJECT_ID('[dbo].[CollectionCipher_UpdateCollectionsForCiphers_V2]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[CollectionCipher_UpdateCollectionsForCiphers_V2] +END +GO