Files
server/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
1.1 KiB
MySQL
Raw Normal View History

2017-04-27 09:19:30 -04:00
CREATE PROCEDURE [dbo].[CollectionCipher_ReadByUserIdCipherId]
2017-04-04 17:22:47 -04:00
@UserId UNIQUEIDENTIFIER,
@CipherId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
CC.*
2017-04-04 17:22:47 -04:00
FROM
[dbo].[CollectionCipher] CC
2017-04-04 17:22:47 -04:00
INNER JOIN
[dbo].[Collection] S ON S.[Id] = CC.[CollectionId]
2017-04-04 17:22:47 -04:00
INNER JOIN
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] AND OU.[UserId] = @UserId
LEFT JOIN
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[CollectionId] = S.[Id] 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]
2017-04-04 17:22:47 -04:00
WHERE
CC.[CipherId] = @CipherId
2017-04-04 17:22:47 -04:00
AND OU.[Status] = 2 -- Confirmed
AND (
OU.[AccessAll] = 1
OR CU.[CollectionId] IS NOT NULL
OR G.[AccessAll] = 1
OR CG.[CollectionId] IS NOT NULL
)
2017-04-04 17:22:47 -04:00
END