mirror of
https://github.com/bitwarden/server.git
synced 2025-01-11 20:10:38 +01:00
improvements to collection user sproc
This commit is contained in:
parent
94c7fdebf5
commit
545fb43dac
@ -21,8 +21,6 @@ BEGIN
|
|||||||
END [ReadOnly]
|
END [ReadOnly]
|
||||||
FROM
|
FROM
|
||||||
[dbo].[OrganizationUser] OU
|
[dbo].[OrganizationUser] OU
|
||||||
LEFT JOIN
|
|
||||||
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
|
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
@ -31,6 +29,8 @@ BEGIN
|
|||||||
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
|
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
||||||
WHERE
|
WHERE
|
||||||
CU.[CollectionId] IS NOT NULL
|
CU.[CollectionId] IS NOT NULL
|
||||||
OR CG.[CollectionId] IS NOT NULL
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
|
@ -665,3 +665,55 @@ BEGIN
|
|||||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[CollectionUserDetails_ReadByCollectionId]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[CollectionUserDetails_ReadByCollectionId]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[CollectionUserDetails_ReadByCollectionId]
|
||||||
|
@CollectionId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
OU.[Id] AS [OrganizationUserId],
|
||||||
|
CASE
|
||||||
|
WHEN OU.[AccessAll] = 1 OR G.[AccessAll] = 1 THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END [AccessAll],
|
||||||
|
U.[Name],
|
||||||
|
ISNULL(U.[Email], OU.[Email]) Email,
|
||||||
|
OU.[Status],
|
||||||
|
OU.[Type],
|
||||||
|
CASE
|
||||||
|
WHEN OU.[AccessAll] = 1 OR CU.[ReadOnly] = 0 OR G.[AccessAll] = 1 OR CG.[ReadOnly] = 0 THEN 0
|
||||||
|
ELSE 1
|
||||||
|
END [ReadOnly]
|
||||||
|
FROM
|
||||||
|
[dbo].[OrganizationUser] OU
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
|
||||||
|
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.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
||||||
|
WHERE
|
||||||
|
CU.[CollectionId] IS NOT NULL
|
||||||
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
|
OR (
|
||||||
|
OU.[OrganizationId] = @OrganizationId
|
||||||
|
AND (
|
||||||
|
OU.[AccessAll] = 1
|
||||||
|
OR G.[AccessAll] = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
Loading…
Reference in New Issue
Block a user