mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
device index and updated folder delete sproc
This commit is contained in:
parent
24aa0dc026
commit
94c7fdebf5
@ -33,7 +33,7 @@ FROM
|
||||
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
|
||||
[dbo].[Organization] O ON O.[Id] = OU.[OrganizationId] AND O.[Id] = C.[OrganizationId] AND O.[Enabled] = 1
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] CC ON OU.[AccessAll] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
|
@ -7,30 +7,56 @@ BEGIN
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM [dbo].[Folder] WHERE [Id] = @Id)
|
||||
DECLARE @UserIdPath VARCHAR(50) = CONCAT('$."', @UserId, '"')
|
||||
|
||||
;WITH [CTE] AS (
|
||||
SELECT
|
||||
[Id],
|
||||
[OrganizationId],
|
||||
[AccessAll]
|
||||
FROM
|
||||
[OrganizationUser]
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
AND [Status] = 2 -- Confirmed
|
||||
)
|
||||
UPDATE
|
||||
C
|
||||
SET
|
||||
C.[Folders] = JSON_MODIFY(C.[Folders], @UserIdPath, NULL)
|
||||
FROM
|
||||
[dbo].[Cipher] 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].[Organization] O ON C.[UserId] IS NULL AND O.[Id] = C.[OrganizationId]
|
||||
LEFT JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAll] = 0 AND CC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON OU.[AccessAll] = 0 AND 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 OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[CollectionId] = CC.[CollectionId] AND CG.[GroupId] = GU.[GroupId]
|
||||
WHERE
|
||||
(
|
||||
C.[UserId] = @UserId
|
||||
OR (
|
||||
C.[UserId] IS NULL
|
||||
AND (OU.[AccessAll] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
)
|
||||
OU.[AccessAll] = 1
|
||||
OR CU.[CollectionId] IS NOT NULL
|
||||
OR G.[AccessAll] = 1
|
||||
OR CG.[CollectionId] IS NOT NULL
|
||||
)
|
||||
AND JSON_VALUE(C.[Folders], @UserIdPath) = @Id
|
||||
|
||||
UPDATE
|
||||
C
|
||||
SET
|
||||
C.[Folders] = JSON_MODIFY(C.[Folders], @UserIdPath, NULL)
|
||||
FROM
|
||||
[dbo].[Cipher] C
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
AND JSON_VALUE([Folders], @UserIdPath) = @Id
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Folder]
|
||||
|
@ -16,3 +16,8 @@ GO
|
||||
CREATE UNIQUE NONCLUSTERED INDEX [UX_Device_UserId_Identifier]
|
||||
ON [dbo].[Device]([UserId] ASC, [Identifier] ASC);
|
||||
|
||||
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_Device_Identifier]
|
||||
ON [dbo].[Device]([Identifier] ASC);
|
||||
|
||||
|
@ -47,6 +47,16 @@ BEGIN
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM sys.indexes WHERE [Name]='IX_Device_Identifier'
|
||||
AND object_id = OBJECT_ID('[dbo].[Device]')
|
||||
)
|
||||
BEGIN
|
||||
CREATE NONCLUSTERED INDEX [IX_Device_Identifier]
|
||||
ON [dbo].[Device]([Identifier] ASC)
|
||||
END
|
||||
GO
|
||||
|
||||
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'UserView')
|
||||
BEGIN
|
||||
DROP VIEW [dbo].[UserView]
|
||||
@ -580,3 +590,78 @@ BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[Folder_DeleteById]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Folder_DeleteById]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Folder_DeleteById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM [dbo].[Folder] WHERE [Id] = @Id)
|
||||
DECLARE @UserIdPath VARCHAR(50) = CONCAT('$."', @UserId, '"')
|
||||
|
||||
;WITH [CTE] AS (
|
||||
SELECT
|
||||
[Id],
|
||||
[OrganizationId],
|
||||
[AccessAll]
|
||||
FROM
|
||||
[OrganizationUser]
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
AND [Status] = 2 -- Confirmed
|
||||
)
|
||||
UPDATE
|
||||
C
|
||||
SET
|
||||
C.[Folders] = JSON_MODIFY(C.[Folders], @UserIdPath, NULL)
|
||||
FROM
|
||||
[dbo].[Cipher] 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 OU.[AccessAll] = 0 AND 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 OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[CollectionId] = CC.[CollectionId] AND CG.[GroupId] = GU.[GroupId]
|
||||
WHERE
|
||||
(
|
||||
OU.[AccessAll] = 1
|
||||
OR CU.[CollectionId] IS NOT NULL
|
||||
OR G.[AccessAll] = 1
|
||||
OR CG.[CollectionId] IS NOT NULL
|
||||
)
|
||||
AND JSON_VALUE(C.[Folders], @UserIdPath) = @Id
|
||||
|
||||
UPDATE
|
||||
C
|
||||
SET
|
||||
C.[Folders] = JSON_MODIFY(C.[Folders], @UserIdPath, NULL)
|
||||
FROM
|
||||
[dbo].[Cipher] C
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
AND JSON_VALUE([Folders], @UserIdPath) = @Id
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Folder]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
GO
|
||||
|
Loading…
Reference in New Issue
Block a user