2
votes

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?

1
I think this is what you are looking for: stackoverflow.com/questions/16038346/…Piyush
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
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
Received an answer from the CRM dynamics community website by Scott Durow and Guido Preite. Here is the link to the conversation: community.dynamics.com/crm/f/117/p/141175/307247.aspx#307247Rohit Tidke

1 Answers

2
votes

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