1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-15 20:41:35 +01:00

[PM-14378] Introduce GetCipherPermissionsForOrganization query for Dapper CipherRepository

This commit is contained in:
Shane Melton 2024-12-05 16:55:29 -08:00 committed by gbubemismith
parent a3ffb5fe96
commit a99afb6db5
No known key found for this signature in database

View File

@ -0,0 +1,67 @@
CREATE OR ALTER PROCEDURE [dbo].[CipherOrganizationPermissions_GetManyByOrganizationId]
@OrganizationId UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
C.[Id],
C.[OrganizationId],
MAX(CASE
WHEN
CU.[CollectionId] IS NULL AND CG.[CollectionId] IS NULL
THEN 0
ELSE 1
END) [Read],
MAX(CASE
WHEN COALESCE(CU.[HidePasswords], CG.[HidePasswords], 1) = 0
THEN 1
ELSE 0
END) [ViewPassword],
MAX(CASE
WHEN COALESCE(CU.[ReadOnly], CG.[ReadOnly], 1) = 0
THEN 1
ELSE 0
END) [Edit],
MAX(COALESCE(CU.[Manage], CG.[Manage], 0)) [Manage],
CASE
WHEN COUNT(CC.[CollectionId]) > 0 THEN 0
ELSE 1
END [Unassigned]
FROM
[dbo].[CipherDetails](@UserId) C
INNER JOIN
[OrganizationUser] OU ON
C.[UserId] IS NULL
AND C.[OrganizationId] = @OrganizationId
AND OU.[UserId] = @UserId
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]
GROUP BY
C.[Id],
C.[OrganizationId]
END
GO