Search code examples
.netdynamics-crmdynamics-crm-4

Microsoft Dynamics 4.0 SDK Check If User Has Privilege


We were previously using an unsupported dll (Microsoft.Crm.Application.Components.Core) to check if the current user in Dynamics has read privileges on a specific entity:

Microsoft.Crm.Security.User.HasPrivilege(Microsoft.Crm.Security.User.Current,   
 "myentityname, AccessRights.ReadAccess);

I need to do the same thing using only the supported SDK (and the CrmService).

Can someone advise on how to accomplish this using the SDK?


Solution

  • You can probably design a Fetch or QueryExpression like so:

    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"

    Just be careful on the results, because you may get different privilege depths from different roles, but if you don't care about the depth then I think that'll do it.