add permission view

This commit is contained in:
2026-05-05 14:49:34 +02:00
parent f09f148aea
commit e5ee067db4
8 changed files with 154 additions and 33 deletions

View File

@@ -24,6 +24,7 @@ GO
-- DROP VIEW IF EXISTS dbo.vAuthentications;
-- DROP VIEW IF EXISTS dbo.vEventLog;
-- DROP VIEW IF EXISTS dbo.vNotifyTray;
-- DROP VIEW IF EXISTS dbo.vPermissionOverview;s
-- DROP TABLE IF EXISTS dbo.AuthenticationRoles;
-- DROP TABLE IF EXISTS dbo.AuthenticationGroups;
@@ -550,6 +551,55 @@ JOIN dbo.Permission p
GO
CREATE OR ALTER VIEW dbo.vPermissionOverview AS
SELECT
p.ID AS Permission_ID,
p.Scope,
p.Resource,
p.Action,
p.Scope + '.' + p.Resource + '.' + p.Action AS PermissionKey,
r.ID AS Role_ID,
-- 🔥 NEU: Anzahl Rollen pro Permission
COUNT(r.ID) OVER (PARTITION BY p.ID) AS RoleCount,
COUNT(gr.Group_ObjectGUID) AS GroupCount,
COUNT(ar.Authentication_ObjectGUID) AS DirectUserCount,
COUNT(ag.Authentication_ObjectGUID) AS GroupUserCount,
COUNT(
COALESCE(ar.Authentication_ObjectGUID, ag.Authentication_ObjectGUID)
) AS TotalUserCount
FROM dbo.Permission AS p
INNER JOIN dbo.RolePermissions AS rp
ON rp.Permission_ID = p.ID
INNER JOIN dbo.Role AS r
ON r.ID = rp.Role_ID
LEFT JOIN dbo.GroupRoles AS gr
ON gr.Role_ID = r.ID
LEFT JOIN dbo.AuthenticationRoles AS ar
ON ar.Role_ID = r.ID
LEFT JOIN dbo.AuthenticationGroups AS ag
ON ag.Group_ObjectGUID = gr.Group_ObjectGUID
GROUP BY
p.ID,
p.Scope,
p.Resource,
p.Action,
r.ID,
r.Name;
GO
-- ========================================================
-- 5. PERMISSION MATRIX (FAST LOOKUP)
-- ========================================================