From 4bde147fc7701f8bdefcbe6125539e46fcb6f59f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 8 Mar 2019 07:56:25 -0500 Subject: [PATCH] re-create UserCollectionDetails function --- util/Setup/DbScripts/2019-03-01_00_OrgApi.sql | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/util/Setup/DbScripts/2019-03-01_00_OrgApi.sql b/util/Setup/DbScripts/2019-03-01_00_OrgApi.sql index 5e7c93eae..83d41b3e4 100644 --- a/util/Setup/DbScripts/2019-03-01_00_OrgApi.sql +++ b/util/Setup/DbScripts/2019-03-01_00_OrgApi.sql @@ -580,3 +580,49 @@ SELECT FROM [dbo].[Collection] GO + +IF OBJECT_ID('[dbo].[UserCollectionDetails]') IS NOT NULL +BEGIN + DROP FUNCTION [dbo].[UserCollectionDetails] +END +GO + +CREATE FUNCTION [dbo].[UserCollectionDetails](@UserId UNIQUEIDENTIFIER) +RETURNS TABLE +AS RETURN +SELECT + C.*, + CASE + WHEN + OU.[AccessAll] = 1 + OR G.[AccessAll] = 1 + OR CU.[ReadOnly] = 0 + OR CG.[ReadOnly] = 0 + THEN 0 + ELSE 1 + END [ReadOnly] +FROM + [dbo].[CollectionView] C +INNER JOIN + [dbo].[OrganizationUser] OU ON C.[OrganizationId] = OU.[OrganizationId] +INNER JOIN + [dbo].[Organization] O ON O.[Id] = C.[OrganizationId] +LEFT JOIN + [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[CollectionId] = C.[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] = C.[Id] AND CG.[GroupId] = GU.[GroupId] +WHERE + OU.[UserId] = @UserId + AND OU.[Status] = 2 -- 2 = Confirmed + AND O.[Enabled] = 1 + AND ( + OU.[AccessAll] = 1 + OR CU.[CollectionId] IS NOT NULL + OR G.[AccessAll] = 1 + OR CG.[CollectionId] IS NOT NULL + ) +GO