mirror of
https://github.com/bitwarden/server.git
synced 2025-02-21 02:41:21 +01:00
created sproc to get user manage rights by cipherId
This commit is contained in:
parent
2abd37d2d7
commit
0a5f2d0a49
@ -0,0 +1,58 @@
|
||||
CREATE PROCEDURE [dbo].[Cipher_ReadCanManageByIdUserId]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @CanManage BIT
|
||||
|
||||
;WITH [CTE] AS (
|
||||
SELECT
|
||||
CASE
|
||||
WHEN C.[UserId] IS NOT NULL OR CU.[Manage] = 1 OR CG.[Manage] = 1 THEN 1
|
||||
ELSE 0
|
||||
END [Manage]
|
||||
FROM
|
||||
[dbo].[Cipher] C
|
||||
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 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 C.[UserId] 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
|
||||
C.Id = @Id
|
||||
AND (
|
||||
C.[UserId] = @UserId
|
||||
OR (
|
||||
C.[UserId] IS NULL
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (
|
||||
CU.[CollectionId] IS NOT NULL
|
||||
OR CG.[CollectionId] IS NOT NULL
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
SELECT
|
||||
@CanManage = CASE
|
||||
WHEN COUNT(1) > 0 THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
FROM
|
||||
[CTE]
|
||||
WHERE
|
||||
[Manage] = 1
|
||||
|
||||
SELECT @CanManage
|
||||
END
|
Loading…
Reference in New Issue
Block a user