2

Creating an external MVC website using CRM 2011/2013 web services. Must hide/show parts of the application based on write access to a certain custom entity. Found solutions like

http://mileyja.blogspot.de/2011/05/using-retrieveuserprivileges-requests.html

Here the RetrieveUserPrivilegesRequest requires the systemuser id and the entity record id as parameters. Workarounds on the subject use .First() to get a record and retrieve the privileges. The solution is not convincing because of the possibility of the absence of records.

The other solutions as RetrieveUserPrivilegesRequest returns Guid-s of privileges. These can change from CRM instance to instance. Also roles get things complicated. Does anyone knowif there exists a straight forward way to verify if the system user has write access to a certain entity?

Rohit Tidke
  • 150
  • 1
  • 10
  • I think this is what you are looking for: http://stackoverflow.com/questions/16038346/how-to-get-current-user-privileges-in-ms-dynamics-crm-on-server-side – Piyush Sep 26 '14 at 08:31
  • Thanks, but I have been through the link. It doesn't really help. As mentioned it returns Guid-s and these change system to system. I am searching for a more generic way. – Rohit Tidke Sep 26 '14 at 09:39
  • The set of privileges a user has is cached on the web server and you should be able to get at that with a single message without then needing to go query anything else to match them up. This caching is why you should use privileges to test for a user's access, rather than membership of security roles (not cached), so your approach is the right one. Note that the result set should give the 'deepest' privilege the user has as a sum of all roles on the user and their teams. This is sufficient for checking for yor purposes. Unfortunately I don't know the right bits of code you need to use. – AdamV Sep 26 '14 at 14:46
  • Received an answer from the CRM dynamics community website by Scott Durow and Guido Preite. Here is the link to the conversation: https://community.dynamics.com/crm/f/117/p/141175/307247.aspx#307247 – Rohit Tidke Sep 29 '14 at 12:25

1 Answers1

2

This requirement can be fulfilled by a combination of a QueryExpression and a RetrieveUserPrivilegesRequest or by a single QueryExpression.

Check if a User has a specific Privilege

Guido Preite
  • 14,905
  • 4
  • 36
  • 65