-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrivilegesLookupQuery.sql
193 lines (180 loc) · 5.84 KB
/
PrivilegesLookupQuery.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
USE [BPS_Content];
-- Go to the bottom, and filter out what you need.
WITH
Users (COS_ID, COS_DisplayName, COS_BpsID) AS (
SELECT
COS_ID,
COS_DisplayName,
COS_BpsID
FROM
CacheOrganizationStructure
WHERE
COS_AccountType IN (
1 -- AAD User
)
),
Groups (COS_ID, COS_DisplayName, COS_BpsID) AS (
SELECT
COS_ID,
COS_DisplayName,
COS_BpsID
FROM
CacheOrganizationStructure
WHERE
COS_AccountType IN (
4, -- BPS Group
2 -- AAD Group
)
),
UsersAndUsersInGroups (COS_UserBpsID, COS_GroupBpsID, UserName, GroupName) AS (
SELECT
u.COS_BpsID,
g.COS_BpsID,
u.COS_DisplayName,
g.COS_DisplayName
FROM
Users u JOIN
CacheOrganizationStructureGroupRelations c ON u.COS_ID = c.COSGR_UserID JOIN
Groups g ON g.COS_ID = c.COSGR_GroupID
UNION ALL
SELECT
COS_BpsID,
NULL,
COS_DisplayName,
NULL
FROM
Users
),
UserApplications (Scope, Level, ID, UserID, UserName, GroupID, GroupName, APP_Name, DEF_Name, WF_Name, DTYPE_Name, COM_Name) AS (
SELECT
'Application' As Scope,
d.Name,
APP_ID,
u.COS_UserBpsID,
u.UserName,
u.COS_GroupBpsID,
u.GroupName,
APP_name,
NULL,
NULL,
NULL,
NULL
FROM
WFApplications JOIN
WFConfigurationSecurities c ON APP_ID = CSC_APPID JOIN
UsersAndUsersInGroups u ON (u.COS_UserBpsID = CSC_USERGUID AND u.COS_GroupBpsID IS NULL) OR u.COS_GroupBpsID = CSC_USERGUID JOIN
DicConfigurationSecurityLevels d ON CSC_LevelID = d.TypeID
),
UserProcesses (Scope, Level, ID, UserID, UserName, GroupID, GroupName, APP_Name, DEF_Name, WF_Name, DTYPE_Name, COM_Name) AS (
SELECT
'Process' As Scope,
d.Name,
DEF_ID,
u.COS_UserBpsID,
u.UserName,
u.COS_GroupBpsID,
u.GroupName,
APP_Name,
DEF_Name,
NULL As WF_Name,
NULL As DTYPE_Name,
IIF(COM_Name IS NULL, 'General', COM_Name) AS COM_Name
FROM
WFDefinitions JOIN
WFSecurities c ON DEF_ID = SEC_DEFID JOIN
UsersAndUsersInGroups u ON (u.COS_UserBpsID = SEC_USERGUID AND u.COS_GroupBpsID IS NULL) OR u.COS_GroupBpsID = SEC_USERGUID JOIN
DicSecurityLevels d ON SEC_LevelID = d.TypeID JOIN
WFApplications ON DEF_APPID = APP_ID LEFT OUTER JOIN
Companies ON COM_ID = SEC_COMID
),
UserWorkflowsForms (Scope, Level, ID, UserID, UserName, GroupID, GroupName, APP_Name, DEF_Name, WF_Name, DTYPE_Name, COM_Name) AS (
SELECT
'Workflow -> Form' As Scope,
d.Name,
ASS_ID,
u.COS_UserBpsID,
u.UserName,
u.COS_GroupBpsID,
u.GroupName,
APP_Name,
DEF_Name,
WF_Name,
DTYPE_Name,
IIF(COM_Name IS NULL, 'General', COM_Name) AS COM_Name
FROM
WorkFlows JOIN
DocTypeAssocciations ON WF_ID = ASS_WFID JOIN
WFDocTypes ON DTYPE_ID = ASS_DTYPEID JOIN
WFSecurities c ON ASS_ID = SEC_DEFID JOIN
UsersAndUsersInGroups u ON (u.COS_UserBpsID = SEC_USERGUID AND u.COS_GroupBpsID IS NULL) OR u.COS_GroupBpsID = SEC_USERGUID JOIN
DicSecurityLevels d ON SEC_LevelID = d.TypeID JOIN
WFDefinitions ON DEF_ID = WF_WFDEFID JOIN
WFApplications ON APP_ID = DEF_APPID LEFT OUTER JOIN
Companies ON SEC_COMID = COM_ID
),
GlobalPrivileges (Scope, Level, ID, UserID, UserName, GroupID, GroupName, APP_Name, DEF_Name, WF_Name, DTYPE_Name, COM_Name) AS (
SELECT
'Global' As Scope,
d.Name,
NULL,
u.COS_UserBpsID,
u.UserName,
u.COS_GroupBpsID,
u.GroupName,
NULL As APP_Name,
NULL As DEF_Name,
NULL As WF_Name,
NULL As DTYPE_Name,
NULL As COM_Name
FROM
WFConfigurationSecurities JOIN
UsersAndUsersInGroups u ON (u.COS_UserBpsID = CSC_USERGUID AND u.COS_GroupBpsID IS NULL) OR u.COS_GroupBpsID = CSC_USERGUID JOIN
DicConfigurationSecurityLevels d ON CSC_LevelID = d.TypeID
WHERE
CSC_IsGlobal = 1
UNION ALL
SELECT
'Global' As Scope,
d.Name,
NULL,
u.COS_UserBpsID,
u.UserName,
u.COS_GroupBpsID,
u.GroupName,
NULL As APP_Name,
NULL As DEF_Name,
NULL As WF_Name,
NULL As DTYPE_Name,
NULL As COM_Name
FROM
WFSecurities JOIN
UsersAndUsersInGroups u ON (u.COS_UserBpsID = SEC_USERGUID AND u.COS_GroupBpsID IS NULL) OR u.COS_GroupBpsID = SEC_USERGUID JOIN
DicSecurityLevels d ON SEC_LevelID = d.TypeID
WHERE
SEC_IsGlobal = 1
),
AllSecurities AS (
SELECT * FROM UserWorkflowsForms
UNION ALL
SELECT * FROM UserProcesses
UNION ALL
SELECT * FROM UserApplications
UNION ALL
SELECT * FROM GlobalPrivileges
)
SELECT
*
FROM
AllSecurities
WHERE
UserID LIKE '%' OR
GroupID LIKE '' OR
GroupName LIKE '' OR
UserName LIKE '' OR
APP_NAME LIKE '' OR
DEF_Name LIKE '' OR
WF_Name LIKE '' OR
DTYPE_Name LIKE '' OR
COM_Name LIKE '' OR
Level LIKE '' OR
Scope LIKE ''