Skip to content

Instantly share code, notes, and snippets.

@martinrayenglish
Created October 16, 2020 17:15
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 martinrayenglish/d283805fbf25351f0675f433fc5fcb99 to your computer and use it in GitHub Desktop.
Save martinrayenglish/d283805fbf25351f0675f433fc5fcb99 to your computer and use it in GitHub Desktop.
/// <summary>
/// Gets the access control type for an item from its ancestors.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="account">The account.</param>
/// <param name="accessRight">The desired access right.</param>
/// <param name="propagationType">Type of propagation.</param>
/// <returns></returns>
protected virtual AccessResult GetAncestorAccess(
Item item,
Account account,
AccessRight accessRight,
PropagationType propagationType)
{
Assert.ArgumentNotNull((object) item, nameof (item));
Assert.ArgumentNotNull((object) account, nameof (account));
Assert.ArgumentNotNull((object) accessRight, nameof (accessRight));
if (propagationType == PropagationType.Entity && propagationType != PropagationType.Descendants)
propagationType = PropagationType.Descendants;
if (propagationType != PropagationType.Descendants)
return AccessResult.NotSet;
Item parent = ItemManager.GetParent(item, SecurityCheck.Disable);
if (parent == null)
return AccessResult.NotSet;
AccessResultCache accessResultCache = CacheManager.GetAccessResultCache();
AccessResultCacheRecord record = accessResultCache.GetRecord((ISecurable) item, account, accessRight, propagationType);
if (record != null)
return record.Value;
AccessResult itemAccess = this.GetItemAccess(parent, account, accessRight, propagationType);
accessResultCache.AddRecord((ISecurable) item, account, accessRight, propagationType, itemAccess);
return itemAccess;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment