如果用户使用C#对所有帐户具有读取访问权限,则检索这些帐户

本文关键字:权限 访问权 检索 访问 读取 用户 所有帐户 如果 | 更新日期: 2023-09-27 18:26:02

我在Dynamics CRM 2011的预处理环境中,我想登记用户有读取权限的所有帐户。到目前为止,我只是联系了以下内容,但只是通过检查用户是否有ReadAcces。但我想查询一次并填充用户有读取权限的所有帐户。

private static bool retrieveReadAccess(IOrganizationService service, Guid userId, Guid avcId)
    {
        //retrieve user ReadAccess to account
        RetrievePrincipalAccessRequest principalAccessReq = new RetrievePrincipalAccessRequest
        {
            Principal = new EntityReference("systemuser", userId),
            Target = new EntityReference("account", avcId)
        };
        RetrievePrincipalAccessResponse principalAccessRes = (RetrievePrincipalAccessResponse)service.Execute(principalAccessReq);
        if (principalAccessRes.AccessRights.HasFlag(AccessRights.ReadAccess))
        {
            return true;
        }
        return false;
    }

如果用户使用C#对所有帐户具有读取访问权限,则检索这些帐户

如果您只想要某个用户可以读取的帐户列表,请在调用SDK时使用CallerId参数:

https://msdn.microsoft.com/en-us/library/gg309629.aspx

这将执行API调用,就好像它来自该用户一样,并且只返回允许用户查看的记录。

// Retrieve the system user ID of the user to impersonate.
OrganizationServiceContext orgContext = new OrganizationServiceContext(_serviceProxy);
_userId = (from user in orgContext.CreateQuery<SystemUser>()
          where user.FullName == "Kevin Cook"
          select user.SystemUserId.Value).FirstOrDefault();
// To impersonate another user, set the OrganizationServiceProxy.CallerId
// property to the ID of the other user.
_serviceProxy.CallerId = _userId;
// Use serviceProxy for any API calls and it will run as the above user