Skip to content

Instantly share code, notes, and snippets.

@furkankaracan
Created September 21, 2022 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furkankaracan/86603090c85b4f0260b11461ad1a8a09 to your computer and use it in GitHub Desktop.
Save furkankaracan/86603090c85b4f0260b11461ad1a8a09 to your computer and use it in GitHub Desktop.
/// <summary>
/// Contains the data that is needed to grant a security principal (user or team) access to the specified record.
/// </summary>
/// <param name="orgService"></param>
/// <param name="sharedRecord">The entity that is the target of the request to grant access. Required.</param>
/// <param name="sharedUser">The team or user that is granted access to the target record.</param>
private void GrantAccess(IOrganizationService orgService, EntityReference sharedRecord, EntityReference sharedUser)
{
var grantAccessRequest = new GrantAccessRequest
{
PrincipalAccess = new PrincipalAccess
{
AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess | AccessRights.AppendToAccess,
Principal = sharedUser
},
Target = sharedRecord
};
orgService.Execute(grantAccessRequest);
}
/// <summary>
/// Contains the data that is needed to replace the access rights on the target record for the specified security principal (user or team).
/// </summary>
/// <param name="orgService"></param>
/// <param name="sharedRecord">Target record for which you want to revoke access. Required.</param>
/// <param name="sharedUser">A security principal (team or user) whose access you want to revoke. Required.</param>
private void RevokeAccess(IOrganizationService orgService, EntityReference sharedRecord, EntityReference sharedUser)
{
var revokeUserAccessReq = new RevokeAccessRequest
{
Revokee = sharedUser,
Target = sharedRecord
};
orgService.Execute(revokeUserAccessReq);
}
/// <summary>
/// Contains the data that is needed to retrieve all security principals (users or teams) that have access to, and access rights for, the specified record.
/// </summary>
/// <param name="orgService"></param>
/// <param name="sharedRecord">Records you want to retrieve security principals (users and teams) and their access rights</param>
private static void RetrieveSharedUsers(IOrganizationService orgService, EntityReference sharedRecord)
{
var accessRequest = new RetrieveSharedPrincipalsAndAccessRequest
{
Target = sharedRecord
};
var accessResponse = (RetrieveSharedPrincipalsAndAccessResponse)orgService.Execute(accessRequest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment