Exemple #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (RequestSegmentContext.CurrentContextMode == ContextMode.Edit ||
                RequestSegmentContext.CurrentContextMode == ContextMode.Preview)
            {
                return;
            }

            var content = PageRouteHelper.Service.Content;

            // ReSharper disable once SuspiciousTypeConversion.Global
            var redirectPage = (content as IRedirectVisitorGroup)?.RedirectContentArea?.FilteredItems.Select(x => x.GetContent())
                               .FirstOrDefault();

            if (redirectPage == null)
            {
                return;
            }

            string url = UrlResolver.Service.GetUrl(redirectPage.ContentLink);

            if (redirectPage is PageData)
            {
                PageShortcutType propertyLinkType = ((PageData)redirectPage).LinkType;

                if (propertyLinkType == PageShortcutType.External)
                {
                    url = ((PageData)redirectPage).LinkURL;
                }
            }

            filterContext.Result = new RedirectResult(url);
        }
Exemple #2
0
        public void ShouldHideFromSearch_InvalidPageLinkType_ReturnsTrue(PageShortcutType shortcutType)
        {
            var content = Factory.GetPageData(shortcutType: shortcutType);
            var result  = _indexer.ShouldHideFromSearch(content);

            Assert.True(result);
        }
        public void ShouldHideFromSearch_ValidPageLinkType_ReturnsFalse(PageShortcutType shortcutType)
        {
            var content = Factory.GetPageData(shortcutType: shortcutType);
            var result  = _indexer.SkipIndexing(content);

            Assert.False(result);
        }
 public static PageData GetPageData(
     bool visibleInMenu            = true,
     bool isPublished              = true,
     bool userHasAccess            = true,
     bool isNotInWaste             = true,
     PageShortcutType shortcutType = PageShortcutType.Normal,
     int id       = 0,
     int parentId = 0) => GetPageData <PageData>(visibleInMenu, isPublished, userHasAccess, isNotInWaste, shortcutType, id, parentId);
        public void Update_SkipsShortcutTypesOtherThanNormal(PageShortcutType type)
        {
            PageData page = Factory.GetPageData();

            page.LinkType = type;

            IndexingStatus result = _indexer.Update(page);

            Assert.Equal(IndexingStatus.HideFromSearchProperty, result);

            _coreIndexerMock.Verify(m => m.Update(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <string>(), It.IsAny <Type>()),
                                    Times.Never);
        }
        public static T GetPageData <T>(
            bool visibleInMenu            = true,
            bool isPublished              = true,
            bool userHasAccess            = true,
            bool isNotInWaste             = true,
            PageShortcutType shortcutType = PageShortcutType.Normal,
            int id               = 0,
            int parentId         = 0,
            CultureInfo language = null) where T : PageData
        {
            var securityDescriptor = new Mock <IContentSecurityDescriptor>();

            securityDescriptor.Setup(m => m.HasAccess(It.IsAny <IPrincipal>(), It.IsAny <AccessLevel>())).Returns(userHasAccess);

            if (language == null)
            {
                language = CultureInfo.CurrentCulture;
            }

            PageReference pageLink   = id > 0 ? new PageReference(id) : GetPageReference();
            PageReference parentLink = parentId > 0 ? new PageReference(parentId) : GetPageReference();

            var pageGuid = Guid.NewGuid();
            var instance = new Mock <T>();

            instance.SetupAllProperties();
            instance.Setup(m => m.VisibleInMenu).Returns(visibleInMenu);
            instance.Setup(m => m.Status).Returns(isPublished ? VersionStatus.Published : VersionStatus.NotCreated);
            instance.Setup(m => m.GetSecurityDescriptor()).Returns(securityDescriptor.Object);
            instance.Setup(m => m.ContentGuid).Returns(pageGuid);
            instance.Setup(m => m.ParentLink).Returns(parentLink);
            instance.Setup(m => m.ContentLink).Returns(pageLink);
            instance.Setup(m => m.Language).Returns(language);
            instance.Setup(m => m.Property).Returns(new PropertyDataCollection());
            instance.Setup(m => m.StaticLinkURL).Returns($"/link/{pageGuid:N}.aspx?id={pageLink.ID}");

            ContentReference.WasteBasket = new PageReference(1);
            if (!isNotInWaste)
            {
                instance.Setup(m => m.ContentLink).Returns(ContentReference.WasteBasket);
            }

            instance.Object.PageTypeName = typeof(T).Name;
            instance.Object.LinkType     = shortcutType;
            return(instance.Object);
        }
        public static TestPage GetTestPage(int id = 0, int parentId = 0, PageShortcutType shortcutType = PageShortcutType.Normal)
        {
            id       = id > 0 ? id : GetInteger();
            parentId = parentId > 0 ? parentId : GetInteger();

            return(new TestPage
            {
                Property =
                {
                    ["PageName"] = new PropertyString(),
                    ["PageStartPublish"] = new PropertyDate(new DateTime(3000, 1, 1)),
                    ["PageStopPublish"] = new PropertyDate(),
                    ["PageLink"] = new PropertyPageReference(id),
                    ["PageParentLink"] = new PropertyPageReference(parentId),
                    ["PageShortcutType"] = new PropertyNumber((int)shortcutType)
                }
            });
        }