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.>
Here is what I have come up with — this code will check, does current user has given privilege on current record:
// 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)
{
...
...
...
}
The code inside if statement will be executed if user has WriteAccess to current record.