5

我正在开发 MS CRM 插件,它应该能够确定当前用户是否具有对当前实体的写入权限。我不知道如何处理这项任务。

似乎目前不支持完成此任务的最用户友好的方式。

除了编写 FetchXML 查询并解析其输出之外,MS CRM 2011 SDK 中还有其他选择吗?

4

2 回答 2

10

这是我想出的——这段代码将检查当前用户是否已授予当前记录的权限:

// 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)
{
    ...
    ...
    ...
}

如果用户必须当前记录,if则将执行语句内部的代码。WriteAccess

于 2013-04-16T16:18:04.773 回答
1

According to Matt's Answer:

  1. Retrieve on the entity privilege
  2. Join on entity roleprivilege where privilege.privilegeid = roleprivilege.privilegeid
  3. Join on entity systemuserrole where systemuserrole.roleid = roleprivileges.roleid and systemuserrole.systemuserid = (GUID of the user in question)
  4. Then either iterate through the privileges or look for privilege where privilege.name = "prvReadMyEntityName"

You have just have to perform the joins and add the where clause you care about. Here is the Equivalent 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.

于 2013-04-16T14:15:52.500 回答