Dynamics CRM 365 SQL查询安全角色具体权限明细[通俗易懂]

Dynamics CRM 365 SQL查询安全角色具体权限明细[通俗易懂]1、查询用户所拥有的安全角色: select su.FullName,r.Name,bu.name bussinessname from SystemUserRoles sur left join S

Dynamics CRM 365 SQL查询安全角色具体权限明细

1、查询用户所拥有的安全角色:

select su.FullName,r.Name,bu.name bussinessname from SystemUserRoles sur
left join SystemUserBase su on su.SystemUserId = sur.SystemUserId
left join BusinessUnitBase bu on bu.BusinessUnitId=su.BusinessUnitId
left join Role r on r.RoleId=sur.RoleId
where su.IsDisabled=0

2、安全角色的具体权限明细:

SELECT DISTINCT
r.Name 安全角色名称
,COALESCE(e.OriginalLocalizedName, e.Name) AS [EntityName]
,CASE p.AccessRight
WHEN 32 THEN “Create-创建”
WHEN 1 THEN “Read-读”
WHEN 2 THEN “Write-写”
WHEN 65536 THEN “Delete-删除”
WHEN 4 THEN “Append-追加”
WHEN 16 THEN “AppendTo-追加到”
WHEN 524288 THEN “Assign-分派”
WHEN 262144 THEN “Share-共享”
ELSE “None”
END AS [Privilege]
,CASE (rp.PrivilegeDepthMask % 0x0F)
WHEN 1 THEN “User (Basic)-个人”
WHEN 2 THEN “Business Unit (Local)-业务部门”
WHEN 4 THEN “Parental (Deep)-上下级”
WHEN 8 THEN “Organization (Global)-组织”
ELSE “Unknown”
END AS [PrivilegeLevel]
,(rp.PrivilegeDepthMask % 0x0F) as [PrivilegeDepthMask]
,CASE WHEN e.IsCustomEntity = 1 THEN “Yes” ELSE “No” END AS [IsCustomEntity]
FROM Role AS r
INNER JOIN RolePrivileges AS rp
ON r.RoleId = rp.RoleId
INNER JOIN Privilege AS p
ON rp.PrivilegeId = p.PrivilegeId
INNER JOIN PrivilegeObjectTypeCodes AS potc
ON potc.PrivilegeId = p.PrivilegeId
INNER JOIN MetadataSchema.Entity AS e
ON e.ObjectTypeCode = potc.ObjectTypeCode
ORDER BY r.Name, [EntityName]

3、用户有用的实际权限总和(比如A用户有三个角色,那么这里就是取这三个角色的并集,并且取最高权限)

select su.FullName 用户名,t.EntityName 实体,t.Privilege 权限名称, CASE (max(t.PrivilegeLevel))
WHEN 1 THEN “User (Basic)-个人”
WHEN 2 THEN “Business Unit (Local)-业务部门”
WHEN 4 THEN “Parental (Deep)-上下级”
WHEN 8 THEN “Organization (Global)-组织”
ELSE “Unknown”
END 权限大小 from SystemUserRoles sur
left join SystemUserBase su on su.SystemUserId = sur.SystemUserId
left join BusinessUnitBase bu on bu.BusinessUnitId=su.BusinessUnitId
left join Role r on r.RoleId=sur.RoleId
left join (SELECT DISTINCT
r.Name 安全角色名称
,COALESCE(e.OriginalLocalizedName, e.Name) AS [EntityName]
,CASE p.AccessRight
WHEN 32 THEN “Create-创建”
WHEN 1 THEN “Read-读”
WHEN 2 THEN “Write-写”
WHEN 65536 THEN “Delete-删除”
WHEN 4 THEN “Append-追加”
WHEN 16 THEN “AppendTo-追加到”
WHEN 524288 THEN “Assign-分派”
WHEN 262144 THEN “Share-共享”
ELSE “None”
END AS [Privilege]
,rp.PrivilegeDepthMask % 0x0F
AS [PrivilegeLevel]
,(rp.PrivilegeDepthMask % 0x0F) as [PrivilegeDepthMask]
,CASE WHEN e.IsCustomEntity = 1 THEN “Yes” ELSE “No” END AS [IsCustomEntity]
FROM Role AS r
INNER JOIN RolePrivileges AS rp
ON r.RoleId = rp.RoleId
INNER JOIN Privilege AS p
ON rp.PrivilegeId = p.PrivilegeId
INNER JOIN PrivilegeObjectTypeCodes AS potc
ON potc.PrivilegeId = p.PrivilegeId
INNER JOIN MetadataSchema.Entity AS e
ON e.ObjectTypeCode = potc.ObjectTypeCode) as t on r.Name=t.安全角色名称
where su.IsDisabled=0

group by su.FullName,t.EntityName,t.Privilege

–行转列
select *
from (select su.FullName 用户名,t.EntityName 实体,t.Privilege 权限名称, CASE (max(t.PrivilegeLevel))
WHEN 1 THEN “User (Basic)-个人”
WHEN 2 THEN “Business Unit (Local)-业务部门”
WHEN 4 THEN “Parental (Deep)-上下级”
WHEN 8 THEN “Organization (Global)-组织”
ELSE “Unknown”
END 权限大小 from SystemUserRoles sur
left join SystemUserBase su on su.SystemUserId = sur.SystemUserId

left join BusinessUnitBase bu on bu.BusinessUnitId=su.BusinessUnitId
left join Role r on r.RoleId=sur.RoleId
left join (SELECT DISTINCT
r.Name 安全角色名称
,COALESCE(e.OriginalLocalizedName, e.Name) AS [EntityName]
,CASE p.AccessRight
WHEN 32 THEN “Create-创建”
WHEN 1 THEN “Read-读”
WHEN 2 THEN “Write-写”
WHEN 65536 THEN “Delete-删除”
WHEN 4 THEN “Append-追加”
WHEN 16 THEN “AppendTo-追加到”
WHEN 524288 THEN “Assign-分派”
WHEN 262144 THEN “Share-共享”
ELSE “None”
END AS [Privilege]
,rp.PrivilegeDepthMask % 0x0F
AS [PrivilegeLevel]
,(rp.PrivilegeDepthMask % 0x0F) as [PrivilegeDepthMask]
,CASE WHEN e.IsCustomEntity = 1 THEN “Yes” ELSE “No” END AS [IsCustomEntity]
FROM Role AS r
INNER JOIN RolePrivileges AS rp
ON r.RoleId = rp.RoleId
INNER JOIN Privilege AS p
ON rp.PrivilegeId = p.PrivilegeId
INNER JOIN PrivilegeObjectTypeCodes AS potc
ON potc.PrivilegeId = p.PrivilegeId
INNER JOIN MetadataSchema.Entity AS e
ON e.ObjectTypeCode = potc.ObjectTypeCode) as t on r.Name=t.安全角色名称
where su.IsDisabled=0

group by su.FullName,t.EntityName,t.Privilege) as tt pivot(max(权限大小) for 权限名称 in([Create-创建],[Read-读]
,[Write-写],[Delete-删除],[Append-追加],[AppendTo-追加到],[Assign-分派],[Share-共享]
))t

 4、用户拥有的具体权限明细表(未合并,A用户有三个角色,三个角色的权限都会展示出来)

select su.FullName,r.Name,bu.name bussinessname,t.EntityName,t.Privilege,t.PrivilegeLevel from SystemUserRoles sur
left join SystemUserBase su on su.SystemUserId = sur.SystemUserId

left join BusinessUnitBase bu on bu.BusinessUnitId=su.BusinessUnitId
left join Role r on r.RoleId=sur.RoleId
left join (SELECT DISTINCT
r.Name 安全角色名称
,COALESCE(e.OriginalLocalizedName, e.Name) AS [EntityName]
,CASE p.AccessRight
WHEN 32 THEN “Create-创建”
WHEN 1 THEN “Read-读”
WHEN 2 THEN “Write-写”
WHEN 65536 THEN “Delete-删除”
WHEN 4 THEN “Append-追加”
WHEN 16 THEN “AppendTo-追加到”
WHEN 524288 THEN “Assign-分派”
WHEN 262144 THEN “Share-共享”
ELSE “None”
END AS [Privilege]
,CASE (rp.PrivilegeDepthMask % 0x0F)
WHEN 1 THEN “User (Basic)-个人”
WHEN 2 THEN “Business Unit (Local)-业务部门”
WHEN 4 THEN “Parental (Deep)-上下级”
WHEN 8 THEN “Organization (Global)-组织”
ELSE “Unknown”
END AS [PrivilegeLevel]
,(rp.PrivilegeDepthMask % 0x0F) as [PrivilegeDepthMask]
,CASE WHEN e.IsCustomEntity = 1 THEN “Yes” ELSE “No” END AS [IsCustomEntity]
FROM Role AS r
INNER JOIN RolePrivileges AS rp
ON r.RoleId = rp.RoleId
INNER JOIN Privilege AS p
ON rp.PrivilegeId = p.PrivilegeId
INNER JOIN PrivilegeObjectTypeCodes AS potc
ON potc.PrivilegeId = p.PrivilegeId
INNER JOIN MetadataSchema.Entity AS e
ON e.ObjectTypeCode = potc.ObjectTypeCode) as t on r.Name=t.安全角色名称
where su.IsDisabled=0

 

原文地址:https://www.cnblogs.com/billzhao2022/archive/2022/05/23/16291292.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/5215.html

(0)
上一篇 2023-05-18
下一篇 2023-05-18

相关推荐

  • Python中int的用法

    Python中int的用法int是一种Python中的数据类型,代表整数。在Python中,int类型的数据是不可变的,即无法更改它们的值。

    2024-08-04
    27
  • 在pycharm中配置Python环境

    在pycharm中配置Python环境Python是一种高级的解释性编程语言,广泛应用于数据科学、Web开发等领域。为了在PyCharm中进行Python编程,需要首先配置Python环境,使其与IDE相适配。Python环境配置的好处是可以自定义Python版本,方便切换不同项目所需的Python版本。

    2024-06-25
    46
  • Innodb表空间、段、区描述页分析与磁盘存储空间管理

    Innodb表空间、段、区描述页分析与磁盘存储空间管理###Innodb表空间、段、区描述页分析与磁盘存储空间管理 从一个整体方向结构上看,表空间大的结构图如下 表空间:表空间文件,存放数据库数据的载体,对于系统表空间通常是ibdata1,开启独立表空间

    2023-04-16
    159
  • Python界面长什么样子

    Python界面长什么样子Python作为一门广泛应用的编程语言,不同于其他编程语言,它具备强大的图形界面库。Python的图形界面主要采用的是Tkinter、PyQt、wxPython等库,让我们能够实现各种各样的用户界面。因此,本文将带您深入了解Python界面是如何制作的,以及它的外观是怎样的。

    2024-05-11
    71
  • 赴一场开源盛会丨10月29日 COSCon’22 开源年会杭州分会场,这里只差一个「你」!「建议收藏」

    赴一场开源盛会丨10月29日 COSCon’22 开源年会杭州分会场,这里只差一个「你」!「建议收藏」报名地址:https://www.bagevent.com/event/8322877 2022年,世界正在改变,开源创造价值。已经办到第七届的开源年会首次来到杭州与开发者们相聚。你眼中的开源是怎样的

    2023-06-12
    138
  • DIGIX数字生活节活动很精彩值得参加「终于解决」

    DIGIX数字生活节活动很精彩值得参加「终于解决」参加了西安站的DIGIX数字生活节,体验了诗词互动专区,获得上半句唐诗后,仅需答出下半句与华为终端云服务产品相关的诗句,就能获得体验卡。还有畅玩空间体验区,带上VR设备化身游戏玩家,有种置身于游戏场…

    2023-02-26
    152
  • CGI备份还原_全量同步和增量同步

    CGI备份还原_全量同步和增量同步问题描述:做scn恢复备库的测试,吭哧了几天,今天终于可以记录一下,遇到了很多坑,作为初学者可以更好地理解DG,主要先关闭备库,在主库做归档丢失备库无法同步,备库产生GAP,然后增量备份恢复备库,版本

    2022-12-26
    151
  • qt lamdba 表达式书写[通俗易懂]

    qt lamdba 表达式书写[通俗易懂]connect(ui->pushButton, &QPushButton::clicked, [=](){ //注意:若在lambda中访问类成员变量,[]号里面必须有=或&,否则编译不过,报错th…

    2023-04-01
    152

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注