Пример #1
0
        // Type specified through page type ID
        private IEnumerable <PageData> FindPagesByPageTypeRecursively(PageReference pageLink, int pageTypeId)
        {
            var criteria = new PropertyCriteriaCollection
            {
                new PropertyCriteria
                {
                    Name      = "PageTypeID",
                    Type      = PropertyDataType.PageType,
                    Condition = CompareCondition.Equal,
                    Value     = pageTypeId.ToString(CultureInfo.InvariantCulture)
                }
            };

            // Include content providers serving content beneath the page link specified for the search
            if (_providerManager.ProviderMap.CustomProvidersExist)
            {
                var contentProvider = _providerManager.ProviderMap.GetProvider(pageLink);

                if (contentProvider.HasCapability(ContentProviderCapabilities.Search))
                {
                    criteria.Add(new PropertyCriteria
                    {
                        Name  = "EPI:MultipleSearch",
                        Value = contentProvider.ProviderKey
                    });
                }
            }

            return(_pageCriteriaQueryService.FindPagesWithCriteria(pageLink, criteria));
        }
Пример #2
0
        public override ActionResult Index(PageListBlock currentBlock)
        {
            PropertyCriteriaCollection criterias = SetupCriterias(currentBlock.PageType);

            var foundPages = _queryService.FindPagesWithCriteria(currentBlock.Root.ToPageReference(), criterias);
            var rootPage   = _contentRepository.Get <PageData>(currentBlock.Root);

            return(PartialView("Blocks/PageListBlock", new PageListBlockViewModel(currentBlock, foundPages, rootPage)));
        }
Пример #3
0
        public CmsqlQueryExecutionResult ExecuteQueries(IEnumerable <CmsqlQuery> queries)
        {
            List <CmsqlQueryExecutionError> errors = new List <CmsqlQueryExecutionError>();
            List <PageData> result = new List <PageData>();

            CmsqlExpressionParser expressionParser = new CmsqlExpressionParser();

            foreach (CmsqlQuery query in queries)
            {
                ContentType contentType = _contentTypeRepository.Load(query.ContentType);
                if (contentType == null)
                {
                    errors.Add(new CmsqlQueryExecutionError($"Couldn't load content-type '{query.ContentType}'."));
                    continue;
                }

                CmsqlExpressionVisitorContext visitorContext = expressionParser.Parse(contentType, query.Criteria);
                if (visitorContext.Errors.Any())
                {
                    errors.AddRange(visitorContext.Errors);
                    continue;
                }

                PageReference searchStartNodeRef = GetStartSearchFromNode(query.StartNode);
                if (PageReference.IsNullOrEmpty(searchStartNodeRef))
                {
                    errors.Add(new CmsqlQueryExecutionError($"Couldn't process start node '{query.StartNode}'."));
                    continue;
                }

                foreach (PropertyCriteriaCollection propertyCriteriaCollection in visitorContext.GetCriteria())
                {
                    PageDataCollection foundPages = _pageCriteriaQueryService.FindPagesWithCriteria(
                        searchStartNodeRef,
                        propertyCriteriaCollection);
                    if (foundPages != null && foundPages.Any())
                    {
                        result.AddRange(foundPages);
                    }
                }
            }

            IEnumerable <ICmsqlQueryResult> pageDataCmsqlQueryResults =
                result.Select(p => new PageDataCmsqlQueryResult(p)).ToList();

            return(new CmsqlQueryExecutionResult(pageDataCmsqlQueryResults, errors));
        }
        public PageDataCollection FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch, ILanguageSelector selector)
        {
            // Any search beneath the entry root should in fact be performed under the clone root as that's where the original content resides
            if (pageLink.CompareToIgnoreWorkID(_entryRoot))
            {
                pageLink = _cloneRoot;
            }
            else if (!string.IsNullOrWhiteSpace(pageLink.ProviderName)) // Any search beneath a cloned page should in fact be performed under the original page, so we use a page link without any provider information
            {
                pageLink = new PageReference(pageLink.ID);
            }

            var pages = _pageQueryService.FindPagesWithCriteria(pageLink, criterias, languageBranch, selector);

            // Return cloned search result set
            return(new PageDataCollection(pages.Select(ClonePage)));
        }
Пример #5
0
        public PageDataCollection GetPagesByPageType(string pageType)
        {
            var criterias = new PropertyCriteriaCollection();

            var criteria = new PropertyCriteria
            {
                Condition = CompareCondition.Equal,
                Name      = "PageTypeID",
                Type      = PropertyDataType.PageType,
                Value     = pageType,
                Required  = true,
            };

            criterias.Add(criteria);

            var pages = _queryService.FindPagesWithCriteria(ContentReference.RootPage, criterias);

            return(pages);
        }
        public ActionResult Index(DemoPage currentPage)
        {
            // Andrahandsalternativ till Constructor Injection
            // var loader1 = ServiceLocator.Current.GetInstance<IContentLoader>();

            var currentPageId = currentPage.ContentLink; // ID of a page is always in ContentLink property

            var startPageId = ContentReference.StartPage;
            IEnumerable <IContent> pages = loader.GetChildren <IContent>(startPageId);

            //Tvättar bort sidor som man inte får eller kan länka till
            IEnumerable <PageData> filteredListOfPages = FilterForVisitor.Filter(pages).Cast <PageData>();

            //Tvätta bort sidor som inte ska synas i navigeringen.
            IEnumerable <PageData> listWithPagesVisibleInNavigation = filteredListOfPages.Where(p => p.VisibleInMenu == true);

            // Ladda in alla föräldrar
            var allAncestors = loader.GetAncestors(currentPageId);

            // Bygg en lista med MenuItem som view model för menyn.
            var list = new List <MenuItem>();

            foreach (var page in listWithPagesVisibleInNavigation)
            {
                var item = new MenuItem();
                item.Page   = page;
                item.Active = allAncestors.Contains(page);

                list.Add(item);
            }

            // Laddar nyheter med GetChildren
            IEnumerable <PageData> myListOfPages = new List <PageData>();

            // Hämta sidor under sidan som egenskapen IdOfParentPageToList pekar ut
            if (!ContentReference.IsNullOrEmpty(currentPage.IdOfParentPageToList))
            {
                myListOfPages = loader.GetChildren <PageData>(currentPage.IdOfParentPageToList);
            }

            // Ladda nyheter med databas sök
            PageReference startPageForSearch = new PageReference(startPageId);
            var           criterias          = new PropertyCriteriaCollection
            {
                new PropertyCriteria
                {
                    Type      = PropertyDataType.String,
                    Name      = "PageName",
                    Condition = CompareCondition.Contained,
                    Value     = "alloy"
                }
            };
            var result = query.FindPagesWithCriteria(startPageForSearch, criterias);

            var model = new DemoPageViewModel();

            model.CurrentPage             = currentPage;
            model.MainMenuList            = listWithPagesVisibleInNavigation;
            model.MainMenuListWithItems   = list;
            model.MyListOfPages           = myListOfPages;
            model.RootPageOfMyListOfPages = loader.Get <PageData>(currentPage.IdOfParentPageToList);
            model.SearchResult            = result;

            return(View(model));
        }
        public ActionResult Index(string submit)
        {
            int countOfRolesCreated = 0;
            int countOfUsersCreated = 0;

            #region Use EPiServer classes to create roles and users

            UIUserCreateStatus   status;
            IEnumerable <string> errors = new List <string>();

            foreach (string role in rolesToCreate)
            {
                if (!roles.RoleExists(role))
                {
                    roles.CreateRole(role);
                    countOfRolesCreated++;
                }
            }

            foreach (var item in Users)
            {
                if (users.GetUser(item.UserName) == null)
                {
                    var newUser = users.CreateUser(item.UserName, password,
                                                   email: $"{item.UserName.ToLower()}{email}",
                                                   passwordQuestion: null, passwordAnswer: null,
                                                   isApproved: true,
                                                   status: out status, errors: out errors);

                    if (status == UIUserCreateStatus.Success)
                    {
                        countOfUsersCreated++;
                        roles.AddUserToRoles(item.UserName, item.Roles);
                    }
                }
            }

            #endregion

            #region Use EPiServer classes to give access rights to Root, Recycle Bin, and News & Events

            SetSecurity(ContentReference.RootPage, adminsRole, AccessLevel.FullAccess);
            SetSecurity(ContentReference.RootPage, "WebAdmins", AccessLevel.NoAccess);
            SetSecurity(ContentReference.RootPage, "Administrators", AccessLevel.NoAccess);
            SetSecurity(ContentReference.RootPage, contentCreatorsRole, AccessLevel.Read | AccessLevel.Create | AccessLevel.Edit | AccessLevel.Delete);
            SetSecurity(ContentReference.RootPage, marketersRole, AccessLevel.Create | AccessLevel.Publish);

            SetSecurity(ContentReference.WasteBasket, adminsRole, AccessLevel.FullAccess);
            SetSecurity(ContentReference.WasteBasket, "Administrators", AccessLevel.NoAccess);

            // find the News & Events page
            var criteria = new PropertyCriteriaCollection
            {
                new PropertyCriteria
                {
                    Name      = "PageName",
                    Type      = PropertyDataType.LongString,
                    Condition = CompareCondition.Equal,
                    Value     = "News & Events"
                }
            };

            var pages = pageFinder.FindPagesWithCriteria(ContentReference.StartPage, criteria);

            if (pages.Count == 1)
            {
                // give News Editors full access and remove all access for others
                var news = pages[0].ContentLink;
                SetSecurity(news, newsEditorsRole, AccessLevel.FullAccess, overrideInherited: true);
                SetSecurity(news, contentCreatorsRole, AccessLevel.NoAccess, overrideInherited: true);
                SetSecurity(news, marketersRole, AccessLevel.NoAccess, overrideInherited: true);
            }

            // find the Press Releases page
            criteria = new PropertyCriteriaCollection
            {
                new PropertyCriteria
                {
                    Name      = "PageName",
                    Type      = PropertyDataType.LongString,
                    Condition = CompareCondition.Equal,
                    Value     = "Press Releases"
                }
            };

            pages = pageFinder.FindPagesWithCriteria(ContentReference.StartPage, criteria);

            if (pages.Count == 1)
            {
                // allow Lawyers and C-Level Execs to edit Press Releases
                // so they can approve/decline changes
                var pressReleases = pages[0].ContentLink;
                SetSecurity(pressReleases, lawyersRole, AccessLevel.Edit, overrideInherited: true);
                SetSecurity(pressReleases, cLevelExecsRole, AccessLevel.Edit, overrideInherited: true);
            }

            #endregion

            RegisterPersonas.IsEnabled = false;

            ViewData["message"] = $"Register personas completed successfully. {countOfRolesCreated} roles created. {countOfUsersCreated} users created and added to roles.";

            return(View("~/Features/RegisterPersonas/RegisterPersonas.cshtml"));
        }