How to get current user privileges in MS Dynamics CRM on server side

后端 未结 2 1252
时光取名叫无心
时光取名叫无心 2020-12-11 19:22

I\'m working on MS CRM plugin, and it should be able to determine whether the current user has write access to the current entity. I don\'t know how to approach this task.

2条回答
  •  情书的邮戳
    2020-12-11 20:28

    According to Matt's Answer:

    1. Retrieve on the entity privilege
    2. Join on entity roleprivilege where privilege.privilegeid = roleprivilege.privilegeid
    3. Join on entity systemuserrole where systemuserrole.roleid = roleprivileges.roleid and systemuserrole.systemuserid = (GUID of the user in question)
    4. Then either iterate through the privileges or look for privilege where privilege.name = "prvReadMyEntityName"

    You have just have to perform the joins and add the where clause you care about. Here is the Equivalent 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
    

    You can perform this using Fetch XML, or LINQ to CRM, or Query Expressions, or even OData.

提交回复
热议问题