2013-04-16 11 views

risposta

9

Ecco quello che ho messo a punto - questo codice controllerà, non utente corrente ha dato il privilegio sul record corrente:

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

il codice all'interno if dichiarazione sarà eseguita se l'utente ha WriteAccess al record corrente .

-1

Controllare this out.

L'essenza di esso è:

//Check if user is connected for on-prem or hosted 

Guid userGuid; 
if(Request.LogonUserIdentity.IsAuthenticated == true) 
{ 
    WhoAmIRequest userRequest = new Microsoft.Crm.SdkTypeProxy.WhoAmIRequest(); 
    WhoAmIResponse user = (Microsoft.Crm.SdkTypeProxy.WhoAmIResponse)objCrmService.Execute (userRequest); 
    userGuid = user.UserId; 
} 
else //ifd 
{ 
    userGuid = new Guid(Context.User.Identity.Name); 
} 
+3

Restituisce le informazioni utente di base, non i loro privilegi – Daryl

+0

Buon punto @Daryl – Bvrce

1

Secondo la risposta di Matt:

  1. Recuperare sul privilegio entità
  2. registrazione su entità roleprivilege dove privilege.privilegeid = roleprivilege.privilegeid
  3. Partecipa all'entità systemuserrole dove systemuserrole.roleid = roleprivileges.roleid e systemuserrole.systemuserid = (GUID dell'utente in questione)
  4. Allora o scorrere i privilegi o cercare privilegio in cui privilege.name = "prvReadMyEntityName"

Avete appena necessario eseguire i join e aggiungere la clausola where a cui tieni. Ecco lo SQL Equivalente:

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 

È possibile eseguire questa operazione utilizzando Fetch XML, o LINQ to CRM, o espressioni di query, o addirittura OData.

+0

Ho trovato un modo più elegante: http://stackoverflow.com/a/16042098/1047741 – shytikov

Problemi correlati