Skip to content

Instantly share code, notes, and snippets.

@trnktms
Last active February 13, 2023 09:45
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 trnktms/cfec822ebe9b6e46a9725ebf74a4bb64 to your computer and use it in GitHub Desktop.
Save trnktms/cfec822ebe9b6e46a9725ebf74a4bb64 to your computer and use it in GitHub Desktop.
namespace Feature.Providers.ItemAccessibility
{
public class CustomItemAuthorizationHelper : ItemAuthorizationHelper
{
private static readonly List<Func<Item, Account, AccessResult, AccessResult>> GetItemAccessChecks = new List<Func<Item, Account, AccessResult, AccessResult>>
{
GetProductItemAccess,
GetProductFamilyItemAccess,
GetProductCategoryItemAccess
};
public CustomItemAuthorizationHelper(
BaseAccessRightManager accessRightManager,
BaseRolesInRolesManager rolesInRolesManager,
BaseItemManager itemManager) : base(accessRightManager, rolesInRolesManager, itemManager) {}
/// <summary>
/// It's only called if the AccessResult is not found yet in the AccessResultCache
/// </summary>
protected override AccessResult GetItemAccess(Item item, Account account, AccessRight accessRight, PropagationType propagationType)
{
var originalAccessResult = base.GetItemAccess(item, account, accessRight, propagationType);
var accessResult = originalAccessResult;
foreach (var check in GetItemAccessChecks)
{
accessResult = check.Invoke(item, account, accessResult);
}
return accessResult;
}
private static AccessResult GetProductItemAccess(Item item, Account account, AccessResult previousAccessResult)
{
// Insert custom logic here
return new AccessResult(AccessPermission.Allow, new AccessExplanation($"Use meaningful a explanation."));
}
private static AccessResult GetProductFamilyItemAccess(Item item, Account account, AccessResult previousAccessResult)
{
// Insert custom logic here
return new AccessResult(AccessPermission.Allow, new AccessExplanation($"Use meaningful a explanation."));;
}
private static AccessResult GetProductCategoryItemAccess(Item item, Account account, AccessResult previousAccessResult)
{
// Insert custom logic here
return new AccessResult(AccessPermission.Allow, new AccessExplanation($"Use meaningful a explanation."));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment