Files
server/src/Sql/dbo/Views/CollectionUserUserDetailsView.sql

28 lines
879 B
MySQL
Raw Normal View History

2017-04-27 09:19:30 -04:00
CREATE VIEW [dbo].[CollectionUserUserDetailsView]
2017-04-03 12:27:02 -04:00
AS
SELECT
OU.[Id] AS [OrganizationUserId],
OU.[OrganizationId],
OU.[AccessAll],
CU.[Id],
CU.[CollectionId],
2017-04-03 12:27:02 -04:00
U.[Name],
ISNULL(U.[Email], OU.[Email]) Email,
OU.[Status],
OU.[Type],
CASE
WHEN OU.[AccessAll] = 0 AND CU.[ReadOnly] = 1 AND G.[AccessAll] = 0 AND CG.[ReadOnly] = 1 THEN 1
ELSE 0
END [ReadOnly]
2017-04-03 12:27:02 -04:00
FROM
[dbo].[OrganizationUser] OU
LEFT JOIN
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id]
2017-04-03 12:27:02 -04:00
LEFT JOIN
[dbo].[User] U ON U.[Id] = OU.[UserId]
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]