private Attempt <string?> AuthorizePath(IUser currentUser, IEnumerable <int>?startContentIds, IEnumerable <int>?startMediaIds) { if (startContentIds != null) { foreach (var contentId in startContentIds) { if (contentId == Constants.System.Root) { var hasAccess = ContentPermissions.HasPathAccess("-1", currentUser.CalculateContentStartNodeIds(_entityService, _appCaches), Constants.System.RecycleBinContent); if (hasAccess == false) { return(Attempt.Fail("The current user does not have access to the content root")); } } else { var content = _contentService.GetById(contentId); if (content == null) { continue; } var hasAccess = currentUser.HasPathAccess(content, _entityService, _appCaches); if (hasAccess == false) { return(Attempt.Fail("The current user does not have access to the content path " + content.Path)); } } } } if (startMediaIds != null) { foreach (var mediaId in startMediaIds) { if (mediaId == Constants.System.Root) { var hasAccess = ContentPermissions.HasPathAccess("-1", currentUser.CalculateMediaStartNodeIds(_entityService, _appCaches), Constants.System.RecycleBinMedia); if (hasAccess == false) { return(Attempt.Fail("The current user does not have access to the media root")); } } else { var media = _mediaService.GetById(mediaId); if (media == null) { continue; } var hasAccess = currentUser.HasPathAccess(media, _entityService, _appCaches); if (hasAccess == false) { return(Attempt.Fail("The current user does not have access to the media path " + media.Path)); } } } } return(Attempt <string?> .Succeed()); }
public static bool HasMediaPathAccess(this IUser user, IUmbracoEntity entity, IEntityService entityService, AppCaches appCaches) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } return(ContentPermissions.HasPathAccess(entity.Path, user.CalculateMediaStartNodeIds(entityService, appCaches), Constants.System.RecycleBinMedia)); }
public static bool HasPathAccess(this IUser user, IContent content, IEntityService entityService, AppCaches appCaches) { if (content == null) { throw new ArgumentNullException(nameof(content)); } return(ContentPermissions.HasPathAccess(content.Path, user.CalculateContentStartNodeIds(entityService, appCaches), Constants.System.RecycleBinContent)); }
internal void FilterBasedOnStartNode(IList items, IUser user) { var toRemove = new List <dynamic>(); foreach (dynamic item in items) { var hasPathAccess = (item != null && ContentPermissions.HasPathAccess(item?.Path, GetUserStartNodes(user), RecycleBinId)); if (hasPathAccess == false) { toRemove.Add(item); } } foreach (var item in toRemove) { items.Remove(item); } }
internal static bool HasMediaBinAccess(this IUser user, IEntityService entityService, AppCaches appCaches) => ContentPermissions.HasPathAccess( Constants.System.RecycleBinMediaString, user.CalculateMediaStartNodeIds(entityService, appCaches), Constants.System.RecycleBinMedia);
internal static bool HasContentBinAccess(this IUser user, IEntityService entityService, AppCaches appCaches) { return(ContentPermissions.HasPathAccess(Constants.System.RecycleBinContentString, user.CalculateContentStartNodeIds(entityService, appCaches), Constants.System.RecycleBinContent)); }