/// <summary>
        /// Returns all the content items of <typeparamref name="T"/> from <paramref name="contentAreaItems"/>
        /// </summary>
        /// <typeparam name="T">Type of <see cref="IContentData"/> items to extract.</typeparam>
        /// <param name="contentAreaItems">The <see cref="IEnumerable{ContentAreaItem}"/> to extract <see cref="IContent"/> instances of type <typeparamref name="T"/> from.</param>
        /// <param name="language">The <see cref="CultureInfo"/> to use. If none is specified, current culture will be used.</param>
        /// <param name="contentLoader">The <see cref="IContentLoader"/> to use</param>
        /// <returns>A <see cref="IEnumerable{T}"/> containing all <see cref="IContent"/> items found in the <paramref name="contentAreaItems"/> collection.</returns>
        public static IEnumerable <T> GetContentItems <T>(this IEnumerable <ContentAreaItem> contentAreaItems, CultureInfo language = null,
                                                          IContentLoader contentLoader = null)
            where T : IContentData
        {
            if (contentAreaItems == null)
            {
                return(Enumerable.Empty <T>());
            }

            if (contentLoader == null)
            {
                contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>();
            }

            if (language == null)
            {
                language = LanguageSelector.AutoDetect().Language;
            }


            var items = contentLoader.GetItems(contentAreaItems.Select(i => i.ContentLink), language).OfType <T>();

            var publishedFilter = new FilterPublished();
            var accessFilter    = new FilterAccess();

            var filterItems = items.OfType <IContent>().Where(x => !publishedFilter.ShouldFilter(x) && !accessFilter.ShouldFilter(x));

            return(filterItems.OfType <T>());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Filters content which should not be visible to the user.
        /// </summary>
        /// <typeparam name="T">Type of content (IContent).</typeparam>
        /// <param name="content">Enumeration of content instances to filter.</param>
        /// <param name="requirePageTemplate">Mark if should include only content with template.</param>
        /// <param name="requireVisibleInMenu">Mark if should include only pages with mark VisibleInMenu = true.</param>
        /// <returns>Returns enumeration of filtered content.</returns>
        public static IEnumerable <T> FilterForDisplay <T>(this IEnumerable <T> content, bool requirePageTemplate = false, bool requireVisibleInMenu = false)
            where T : IContent
        {
            if (content == null)
            {
                return(Enumerable.Empty <T>());
            }

            var publishedFilter = new FilterPublished();
            var accessFilter    = new FilterAccess();

            content = content.Where(x => !publishedFilter.ShouldFilter(x) && !accessFilter.ShouldFilter(x));

            if (requirePageTemplate)
            {
                var templateFilter = ServiceLocator.Current.GetInstance <FilterTemplate>();
                templateFilter.TemplateTypeCategories = TemplateTypeCategories.Page;
                content = content.Where(x => !templateFilter.ShouldFilter(x));
            }

            if (requireVisibleInMenu)
            {
                content = content.Where(x => VisibleInMenu(x));
            }

            return(content);
        }
Ejemplo n.º 3
0
        public IEnumerable<PageData> ExecuteCommand(PageBase currentPage)
        {
            var fa = new FilterAccess(EPiServer.Security.AccessLevel.Read);
            var pdc = currentPage.GetChildren(currentPage.CurrentPageLink);

            fa.Filter(pdc);

            return pdc;
        }
Ejemplo n.º 4
0
        private IEnumerable <MenuItem> GetMenuItemsRecursive(ContentReference contentLink)
        {
            var publishedFilter = new FilterPublished();
            var accessFilter    = new FilterAccess();

            var menuItems = _contentLoader
                            .GetChildren <BasePageData>(contentLink)
                            .Where(p => p.VisibleInSiteMap && !publishedFilter.ShouldFilter(p) && !accessFilter.ShouldFilter(p))
                            .Select(p => new MenuItem
            {
                Name        = p.Name,
                ContentLink = p.ContentLink,
                Children    = GetMenuItemsRecursive(p.ContentLink)
            });

            return(menuItems);
        }
Ejemplo n.º 5
0
        public static IEnumerable <T> FilterForDisplay <T>(
            this IEnumerable <T> contents,
            bool requirePageTemplate  = false,
            bool requireVisibleInMenu = false) where T : IContent
        {
            var accessFilter    = new FilterAccess();
            var publishedFilter = new FilterPublished();

            contents = contents.Where(x =>
                                      !publishedFilter.ShouldFilter(x) &&
                                      !accessFilter.ShouldFilter(x));

            if (requireVisibleInMenu)
            {
                contents = contents.Where(x => VisibleInMenu(x));
            }

            return(contents);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Finds all blocks of a block type below <paramref name="reference"/>, and runs it through FilterForVisitor.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reference">ContentReference to search below</param>
        /// <param name="recursive">Whether to search recursively</param>
        /// <returns>A list containing items of type <typeparam name="T">T</typeparam>, or null</returns>
        public IEnumerable <T> FindFilteredBlocksOfType <T>(ContentReference reference, bool recursive) where T : BlockData
        {
            if (reference == null || reference.ID == 0)
            {
                return(new List <T>());
            }

            var subPages = FindBlocksOfType <T>(reference, recursive).Cast <BlockData>();

            var filterAcces     = new FilterAccess(AccessLevel.Read);
            var publishedFilter = new FilterPublished();

            var filteredBlocks = subPages
                                 .Where(b => !filterAcces.ShouldFilter((IContent)b))
                                 .Where(b => !publishedFilter.ShouldFilter((IContent)b));

            // FilterForVisitor.Filter doesn't work for some reason.
            //It returns null, even if the exact code it uses (tested through reflection) does return the correct list of items.
            //var filteredSubPages = FilterForVisitor.Filter(subPages);

            return(filteredBlocks.Cast <T>());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Finds all pages of a page type below <paramref name="pageLink"/>, and runs it through FilterForVisitor.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageLink">PageReference to search below</param>
        /// <param name="recursive">Whether to search recursively</param>
        /// <param name="culture"></param>
        /// <returns>A list containing items of type <typeparam name="T">T</typeparam> or an empty list</returns>
        public IEnumerable <T> FindFilteredPagesOfType <T>(ContentReference pageLink, bool recursive, CultureInfo culture) where T : IContent
        {
            if (pageLink == null || pageLink.ID == 0)
            {
                return(new List <T>());
            }

            var subPages = FindPagesOfType <T>(pageLink, recursive, culture).Cast <IContent>();

            var filterAcces     = new FilterAccess(AccessLevel.Read);
            var publishedFilter = new FilterPublished();

            var filteredSubPages = subPages
                                   .Where(p => !filterAcces.ShouldFilter(p))
                                   .Where(p => !publishedFilter.ShouldFilter(p));

            // FilterForVisitor.Filter doesn't work for some reason.
            //It returns null, even if the exact code it uses (tested through reflection) does return the correct list of items.
            //var filteredSubPages = FilterForVisitor.Filter(subPages);

            return(filteredSubPages.Cast <T>());
        }
Ejemplo n.º 8
0
        public virtual bool IsReadableForCurrentUser(IContent content)
        {
            var result = FilterAccess.QueryDistinctAccessEdit(content, AccessLevel.Read);

            return(result);
        }
Ejemplo n.º 9
0
 public bool QueryDistinctAccessEdit(PageData page, AccessLevel accessLevel)
 {
     return(FilterAccess.QueryDistinctAccessEdit(page, accessLevel));
 }