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 = ContentPermissionsHelper.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 = ContentPermissionsHelper.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());
        }
Пример #2
0
 internal static bool HasMediaPathAccess(this IUser user, IUmbracoEntity entity, IEntityService entityService)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     return(ContentPermissionsHelper.HasPathAccess(entity.Path, user.CalculateMediaStartNodeIds(entityService), Constants.System.RecycleBinMedia));
 }
Пример #3
0
 internal static bool HasPathAccess(this IUser user, IContent content, IEntityService entityService)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     return(ContentPermissionsHelper.HasPathAccess(content.Path, user.CalculateContentStartNodeIds(entityService), Constants.System.RecycleBinContent));
 }
Пример #4
0
 internal static bool HasPathAccess(this IUser user, IMedia media, IEntityService entityService, AppCaches appCaches)
 {
     if (media == null)
     {
         throw new ArgumentNullException(nameof(media));
     }
     return(ContentPermissionsHelper.HasPathAccess(media.Path, user.CalculateMediaStartNodeIds(entityService, appCaches), Constants.System.RecycleBinMedia));
 }
Пример #5
0
        internal void FilterBasedOnStartNode(IList items, IUser user)
        {
            var toRemove = new List <dynamic>();

            foreach (dynamic item in items)
            {
                var hasPathAccess = (item != null && ContentPermissionsHelper.HasPathAccess(item.Path, GetUserStartNodes(user), RecycleBinId));
                if (hasPathAccess == false)
                {
                    toRemove.Add(item);
                }
            }

            foreach (var item in toRemove)
            {
                items.Remove(item);
            }
        }
Пример #6
0
 internal static bool HasMediaBinAccess(this IUser user, IEntityService entityService)
 {
     return(ContentPermissionsHelper.HasPathAccess(Constants.System.RecycleBinMediaString, user.CalculateMediaStartNodeIds(entityService), Constants.System.RecycleBinMedia));
 }
Пример #7
0
 internal static bool HasMediaRootAccess(this IUser user, IEntityService entityService, AppCaches appCaches)
 => ContentPermissionsHelper.HasPathAccess(Constants.System.RootString, user.CalculateMediaStartNodeIds(entityService, appCaches), Constants.System.RecycleBinMedia);
 internal static bool HasContentBinAccess(this IUser user, IEntityService entityService)
 {
     return(ContentPermissionsHelper.HasPathAccess(Constants.System.RecycleBinContent.ToInvariantString(), user.CalculateContentStartNodeIds(entityService), Constants.System.RecycleBinContent));
 }