• Dynamics CRM 365 如何判断用户是否有某个实体的查询权限


    1.C#代码

    // Requesting user's access rights to current record
    var principalAccessRequest = new RetrievePrincipalAccessRequest
    {
        Principal = new EntityReference("systemuser", localContext.PluginExecutionContext.UserId),
        Target = new EntityReference(localContext.PluginExecutionContext.PrimaryEntityName, localContext.PluginExecutionContext.PrimaryEntityId)
    };
    
    // Response will contain AccessRights mask, like AccessRights.WriteAccess | AccessRights.ReadAccess | ...
    var principalAccessResponse = (RetrievePrincipalAccessResponse)localContext.OrganizationService.Execute(principalAccessRequest);
    
    if ((principalAccessResponse.AccessRights & AccessRights.WriteAccess) != AccessRights.None)
    {
        ...
        ...
        ...
    }

    2.SQL

    检索实体特权

    加入实体角色特权,其中 privilege.privilegeid = roleprivilege.privilegeid

    加入实体 systemuserrole,其中 systemuserrole.roleid = roleprivileges.roleid 和 systemuserrole.systemuserid =(相关用户的 GUID)

    然后遍历权限或查找权限 where privilege.name = "prvReadMyEntityName"

    您只需要执行连接并添加您关心的 where 子句。这是等效的 SQL:

    SELECT Privilege.*
    FROM Privilege
    INNER JOIN RolePrivilege ON Privilege.PrivilegeId = RolePrivilege.PrivilegeId
    INNER JOIN SystemUserRole ON SystemUserRole.RoleId = RolePrivileges.RoleId AND SystemUserRole.SystemUserId = (user's GUID)
    -- WHERE Add whatever constraints on the Privilege entity that you need
  • 相关阅读:
    团队项目-选题报告
    第一次结对编程作业
    第一次个人编程作业
    软工作业1
    总结
    2013-2014 ACM ICPC Central European Regional Contest (CERC 13) K-Digraphs
    2018CCPC吉林赛区 F
    计蒜客-A1594 封印之门
    HDU-1599 find the mincost route
    POJ-2240 Arbitrage
  • 原文地址:https://www.cnblogs.com/parkerchen/p/16270566.html
Copyright © 2020-2023  润新知