From 58a314d9f45501e4faff53dd49d080e331622393 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Fri, 9 Aug 2024 07:33:45 +1000 Subject: [PATCH] [PM-10360] Drop user cipher and collection details v2 functions (#4588) --- .../dbo/Functions/UserCipherDetails_V2.sql | 61 ------------------- .../Cipher/CipherDetails_ReadByUserId_V2.sql | 11 ---- .../Functions/UserCollectionDetails_V2.sql | 45 -------------- .../Collection_ReadByUserId_V2.sql | 26 -------- ..._00_DropCipherAndCollectionV2Functions.sql | 25 ++++++++ 5 files changed, 25 insertions(+), 143 deletions(-) delete mode 100644 src/Sql/Vault/dbo/Functions/UserCipherDetails_V2.sql delete mode 100644 src/Sql/Vault/dbo/Stored Procedures/Cipher/CipherDetails_ReadByUserId_V2.sql delete mode 100644 src/Sql/dbo/Functions/UserCollectionDetails_V2.sql delete mode 100644 src/Sql/dbo/Stored Procedures/Collection_ReadByUserId_V2.sql create mode 100644 util/Migrator/DbScripts/2024-08-08_00_DropCipherAndCollectionV2Functions.sql diff --git a/src/Sql/Vault/dbo/Functions/UserCipherDetails_V2.sql b/src/Sql/Vault/dbo/Functions/UserCipherDetails_V2.sql deleted file mode 100644 index 203d360d3..000000000 --- a/src/Sql/Vault/dbo/Functions/UserCipherDetails_V2.sql +++ /dev/null @@ -1,61 +0,0 @@ -CREATE FUNCTION [dbo].[UserCipherDetails_V2](@UserId UNIQUEIDENTIFIER) -RETURNS TABLE -AS RETURN -WITH [CTE] AS ( - SELECT - [Id], - [OrganizationId] - FROM - [OrganizationUser] - WHERE - [UserId] = @UserId - AND [Status] = 2 -- Confirmed -) -SELECT - C.*, - CASE - WHEN COALESCE(CU.[ReadOnly], CG.[ReadOnly], 0) = 0 - THEN 1 - ELSE 0 - END [Edit], - CASE - WHEN COALESCE(CU.[HidePasswords], CG.[HidePasswords], 0) = 0 - THEN 1 - ELSE 0 - END [ViewPassword], - CASE - WHEN O.[UseTotp] = 1 - THEN 1 - ELSE 0 - END [OrganizationUseTotp] -FROM - [dbo].[CipherDetails](@UserId) C -INNER JOIN - [CTE] OU ON C.[UserId] IS NULL AND C.[OrganizationId] IN (SELECT [OrganizationId] FROM [CTE]) -INNER JOIN - [dbo].[Organization] O ON O.[Id] = OU.[OrganizationId] AND O.[Id] = C.[OrganizationId] AND O.[Enabled] = 1 -LEFT JOIN - [dbo].[CollectionCipher] CC ON CC.[CipherId] = C.[Id] -LEFT JOIN - [dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] 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 - CU.[CollectionId] IS NOT NULL - OR CG.[CollectionId] IS NOT NULL - -UNION ALL - -SELECT - *, - 1 [Edit], - 1 [ViewPassword], - 0 [OrganizationUseTotp] -FROM - [dbo].[CipherDetails](@UserId) -WHERE - [UserId] = @UserId diff --git a/src/Sql/Vault/dbo/Stored Procedures/Cipher/CipherDetails_ReadByUserId_V2.sql b/src/Sql/Vault/dbo/Stored Procedures/Cipher/CipherDetails_ReadByUserId_V2.sql deleted file mode 100644 index ab021a4f6..000000000 --- a/src/Sql/Vault/dbo/Stored Procedures/Cipher/CipherDetails_ReadByUserId_V2.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE PROCEDURE [dbo].[CipherDetails_ReadByUserId_V2] - @UserId UNIQUEIDENTIFIER -AS -BEGIN - SET NOCOUNT ON - - SELECT - * - FROM - [dbo].[UserCipherDetails_V2](@UserId) -END diff --git a/src/Sql/dbo/Functions/UserCollectionDetails_V2.sql b/src/Sql/dbo/Functions/UserCollectionDetails_V2.sql deleted file mode 100644 index f3e6a0f39..000000000 --- a/src/Sql/dbo/Functions/UserCollectionDetails_V2.sql +++ /dev/null @@ -1,45 +0,0 @@ -CREATE FUNCTION [dbo].[UserCollectionDetails_V2](@UserId UNIQUEIDENTIFIER) -RETURNS TABLE -AS RETURN -SELECT - C.*, - CASE - WHEN - COALESCE(CU.[ReadOnly], CG.[ReadOnly], 0) = 0 - THEN 0 - ELSE 1 - END [ReadOnly], - CASE - WHEN - COALESCE(CU.[HidePasswords], CG.[HidePasswords], 0) = 0 - THEN 0 - ELSE 1 - END [HidePasswords], - CASE - WHEN - COALESCE(CU.[Manage], CG.[Manage], 0) = 0 - THEN 0 - ELSE 1 - END [Manage] -FROM - [dbo].[CollectionView] C -INNER JOIN - [dbo].[OrganizationUser] OU ON C.[OrganizationId] = OU.[OrganizationId] -INNER JOIN - [dbo].[Organization] O ON O.[Id] = C.[OrganizationId] -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 - OU.[UserId] = @UserId - AND OU.[Status] = 2 -- 2 = Confirmed - AND O.[Enabled] = 1 - AND ( - CU.[CollectionId] IS NOT NULL - OR CG.[CollectionId] IS NOT NULL - ) diff --git a/src/Sql/dbo/Stored Procedures/Collection_ReadByUserId_V2.sql b/src/Sql/dbo/Stored Procedures/Collection_ReadByUserId_V2.sql deleted file mode 100644 index 4538dc8da..000000000 --- a/src/Sql/dbo/Stored Procedures/Collection_ReadByUserId_V2.sql +++ /dev/null @@ -1,26 +0,0 @@ -CREATE PROCEDURE [dbo].[Collection_ReadByUserId_V2] - @UserId UNIQUEIDENTIFIER -AS -BEGIN - SET NOCOUNT ON - - SELECT - Id, - OrganizationId, - [Name], - CreationDate, - RevisionDate, - ExternalId, - MIN([ReadOnly]) AS [ReadOnly], - MIN([HidePasswords]) AS [HidePasswords], - MAX([Manage]) AS [Manage] - FROM - [dbo].[UserCollectionDetails_V2](@UserId) - GROUP BY - Id, - OrganizationId, - [Name], - CreationDate, - RevisionDate, - ExternalId -END diff --git a/util/Migrator/DbScripts/2024-08-08_00_DropCipherAndCollectionV2Functions.sql b/util/Migrator/DbScripts/2024-08-08_00_DropCipherAndCollectionV2Functions.sql new file mode 100644 index 000000000..26a83fdd9 --- /dev/null +++ b/util/Migrator/DbScripts/2024-08-08_00_DropCipherAndCollectionV2Functions.sql @@ -0,0 +1,25 @@ +-- chore: drop v2 sprocs and functions that are no longer in use + +IF OBJECT_ID('[dbo].[Collection_ReadByUserId_V2]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[Collection_ReadByUserId_V2] +END +GO + +IF OBJECT_ID('[dbo].[UserCollectionDetails_V2]') IS NOT NULL +BEGIN + DROP FUNCTION [dbo].[UserCollectionDetails_V2] +END +GO + +IF OBJECT_ID('[dbo].[CipherDetails_ReadByUserId_V2]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[CipherDetails_ReadByUserId_V2] +END +GO + +IF OBJECT_ID('[dbo].[UserCipherDetails_V2]') IS NOT NULL +BEGIN + DROP FUNCTION [dbo].[UserCipherDetails_V2] +END +GO