[英]How to detect a user is has administrator role in MS Dynamics CRM via SDK?
I have a small issue with detecting whether the user in a company is an admin or not. 我有一个小问题,检测公司中的用户是否是管理员。 A suggested way to do that by MS is to query for a role name "administrator" etc. MS建议的方法是查询角色名称 “administrator”等。
BUT the thing is that it is for some reason the role names seem to be translated , so it makes it a bit difficult to query for it in different languages, ie what was "administrator" could now be an "администратор". 但问题在于,由于某种原因,角色名称似乎被翻译 ,因此使用不同语言查询它有点困难,即“管理员”现在可能是“администратор”。
*Using the role id does not seem to work either, on different version of CRM at least. *使用角色ID似乎也不起作用,至少在不同版本的CRM上。
Have anybody ever struggled with such a thing? 有没有人在这样的事情上挣扎过? Gladly appreciate your help! 非常感谢你的帮助!
The system administrator role can be identified using the ID of a role template. 可以使用角色模板的ID来标识系统管理员角色。 For built-in security roles Dynamics CRM systems all share the same Guid
s, so you can simply hard code your language-agnostic query. 对于内置安全角色,Dynamics CRM系统都共享相同的Guid
,因此您可以简单地对与语言无关的查询进行硬编码。
Here a code sample. 这是一个代码示例。 (In this example _service should be an object implementing the IOrganizationService
interface.) (在此示例中,_service应该是实现IOrganizationService
接口的对象。)
private static readonly Guid AdminRoleTemplateId = new Guid("627090FF-40A3-4053-8790-584EDC5BE201");
public bool HavingAdminRole(Guid systemUserId)
{
var query = new QueryExpression("role");
query.Criteria.AddCondition("roletemplateid", ConditionOperator.Equal, AdminRoleTemplateId);
var link = query.AddLink("systemuserroles", "roleid", "roleid");
link.LinkCriteria.AddCondition("systemuserid", ConditionOperator.Equal, systemUserId);
return _service.RetrieveMultiple(query).Entities.Count > 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.