简体   繁体   English

如何在服务器端的MS Dynamics CRM中获得当前的用户特权

[英]How to get current user privileges in MS Dynamics CRM on server side

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. 我正在使用MS CRM插件,它应该能够确定当前用户是否具有对当前实体的写权限。 I don't know how to approach this task. 我不知道如何完成这项任务。

It seems that the most user-friendly way accomplish this task is currently unsupported . 似乎目前尚不支持以最用户友好的方式完成此任务。

Is there any alternative in MS CRM 2011 SDK, except composing a FetchXML query and parsing its output? 除了组成FetchXML查询并解析其输出之外,MS CRM 2011 SDK中还有其他选择吗?

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. 如果用户对当前记录具有WriteAccess ,则将执行if语句中的代码。

According to Matt's Answer: 根据马特的答案:

  1. Retrieve on the entity privilege 检索实体特权
  2. Join on entity roleprivilege where privilege.privilegeid = roleprivilege.privilegeid 加入实体roleprivilege,其中privilege.privilegeid = roleprivilege.privilegeid
  3. Join on entity systemuserrole where systemuserrole.roleid = roleprivileges.roleid and systemuserrole.systemuserid = (GUID of the user in question) 加入实体systemuserrole,其中systemuserrole.roleid = roleprivileges.roleid和systemuserrole.systemuserid =(相关用户的GUID)
  4. Then either iterate through the privileges or look for privilege where privilege.name = "prvReadMyEntityName" 然后要么遍历特权,要么寻找特权,其中privilege.name =“ prvReadMyEntityName”

You have just have to perform the joins and add the where clause you care about. 您只需要执行联接并添加您关心的where子句。 Here is the Equivalent SQL: 这是等效的SQL:

SELECT Privilege.*
FROM Privilege
INNER JOIN RolePrivilege ON Privilege.PrivilegeId = RolePrivilege.PrivilegeId
INNER JOIN SystemUserRole ON SystemUserRole.RoleId = RolePrivileges.RoleId AND SystemUserRole.SystemUserId = (user's GUID)
-- WHERE Add whatever constraints on the Privilege entity that you need

You can perform this using Fetch XML, or LINQ to CRM, or Query Expressions, or even OData. 您可以使用Fetch XML,LINQ to CRM,Query Expressions甚至OData来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在MS Dynamics CRM中通过QuoteDetail获取Opportunity产品? - How to get Opportunityproduct by QuoteDetail in MS Dynamics CRM? 获取当前登录到MS Dynamics CRM 2011 Online的用户的ID - Get Id of user currently logged into MS Dynamics CRM 2011 Online 如何在服务器端异步检索Dynamics CRM 365数据 - How to retrieve Dynamics CRM 365 data asynchronous on server side 在动态 crm 中获取用户的上下文 - Get the context of a user in dynamics crm 获取ms动态CRM中的关联记录 - get associated records in ms dynamics crm 如何通过SDK在MS Dynamics CRM中检测用户是否具有管理员角色? - How to detect a user is has administrator role in MS Dynamics CRM via SDK? 如何使用C#在MS Dynamics CRM中为案例的自定义字段设置/获取值 - how to set/get value to the custom field of a case in MS Dynamics CRM using C# 如何在MS Dynamics CRM中获取帐户的所有联系人并建立电子邮件列表? - How to get all contacts of an Account and build an email List in MS Dynamics CRM? 在将用户管理委派给Dynamics CRM 2011后端的前端外壳应用程序中处理用户特权 - Handling user privileges in a frontend shell application that delegates user management to a dynamics CRM 2011 backend 使用XRM SDK从ms dynamics crm获取相关数据 - get related data from ms dynamics crm using XRM SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM