Esempio n. 1
0
        /// <summary>
        /// Gets the view model for rendering widget preview.
        /// </summary>
        /// <param name="contentId">The content id.</param>
        /// <param name="user">The user.</param>
        /// <returns>
        /// View model for rendering widget preview
        /// </returns>
        public RenderPageViewModel GetContentPreviewViewModel(Guid contentId, IPrincipal user, bool allowJavaScript)
        {
            // Creating fake region.
            var regionGuid = new Guid(regionId);
            var region     = new Region {
                Id = regionGuid, RegionIdentifier = regionIdentifier
            };
            var regionViewModel = new PageRegionViewModel {
                RegionId = regionGuid, RegionIdentifier = regionIdentifier
            };

            // Creating fake page content and loading it's children.
            var pageContent = new PageContent
            {
                Options = new List <PageContentOption>(),
                Region  = region
            };

            pageContent.Content = repository
                                  .AsQueryable <ContentEntity>(c => c.Id == contentId)
                                  .FetchMany(f => f.ContentOptions)
                                  .FetchMany(f => f.ChildContents)
                                  .ThenFetch(f => f.Child)
                                  .FetchMany(f => f.ChildContents)
                                  .ThenFetchMany(f => f.Options)
                                  .ToList()
                                  .FirstOrDefault();

            if (pageContent.Content != null)
            {
                DemandAccess(user, RootModuleConstants.UserRoles.EditContent, RootModuleConstants.UserRoles.PublishContent);
            }

            childContentService.RetrieveChildrenContentsRecursively(true, new[] { pageContent.Content });

            var contentProjection = contentProjectionService.CreatePageContentProjection(true, pageContent, retrieveCorrectVersion: false);

            var pageViewModel = new RenderPageViewModel
            {
                Contents = new List <PageContentProjection> {
                    contentProjection
                },
                Stylesheets = new List <IStylesheetAccessor> {
                    contentProjection
                },
                Regions = new List <PageRegionViewModel> {
                    regionViewModel
                },
                AreRegionsEditable = true
            };

            if (allowJavaScript)
            {
                pageViewModel.JavaScripts = new List <IJavaScriptAccessor> {
                    contentProjection
                };
            }

            return(pageViewModel);
        }
Esempio n. 2
0
        private void CheckIfContentHasDeletingWidgetsWithDynamicRegions(Widget widget, string targetHtml)
        {
            var sourceHtml    = ((IDynamicContentContainer)widget).Html;
            var sourceWidgets = PageContentRenderHelper.ParseWidgetsFromHtml(sourceHtml);
            var targetWidgets = PageContentRenderHelper.ParseWidgetsFromHtml(targetHtml);

            // Get ids of child widgets, which are being removed from the content
            var removingWidgetIds = sourceWidgets
                                    .Where(sw => targetWidgets.All(tw => tw.WidgetId != sw.WidgetId))
                                    .Select(sw => sw.WidgetId)
                                    .Distinct()
                                    .ToArray();

            if (removingWidgetIds.Any())
            {
                var childContents   = childContentService.RetrieveChildrenContentsRecursively(true, removingWidgetIds);
                var childContentIds = childContents.Select(cc => cc.Child.Id).Distinct().ToList();

                PageContent   pcAlias            = null;
                ContentRegion contentRegionAlias = null;

                var subQuery = QueryOver.Of(() => contentRegionAlias)
                               .Where(() => !contentRegionAlias.IsDeleted)
                               .And(Restrictions.In(Projections.Property(() => contentRegionAlias.Content.Id), childContentIds))
                               .And(() => contentRegionAlias.Region == pcAlias.Region)
                               .Select(cr => cr.Id);

                var areAnyContentUsages = repository.AsQueryOver(() => pcAlias)
                                          .WithSubquery.WhereExists(subQuery)
                                          .And(() => !pcAlias.IsDeleted)
                                          .RowCount() > 0;

                if (areAnyContentUsages)
                {
                    var message    = PagesGlobalization.SaveWidget_ContentHasChildrenWidgetWithDynamicContents_ConfirmationMessage;
                    var logMessage = string.Format("User is trying to remove child widget which has children with dynamic regions and assigned contents. Confirmation is required.");
                    throw new ConfirmationRequestException(() => message, logMessage);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the page contents.
        /// </summary>
        /// <param name="pageIds">The page ids.</param>
        /// <param name="request">The request.</param>
        /// <returns>The list of page contents</returns>
        private List <PageContent> GetPageContents(Guid[] pageIds, GetPageToRenderRequest request)
        {
            IQueryable <PageContent> pageContentsQuery = Repository.AsQueryable <PageContent>();

            pageContentsQuery = pageContentsQuery.Where(f => pageIds.Contains(f.Page.Id));

            if (request.PreviewPageContentId != null)
            {
                pageContentsQuery = pageContentsQuery.Where(f => f.Content.Status == ContentStatus.Published || f.Content.Status == ContentStatus.Draft || f.Id == request.PreviewPageContentId.Value);
            }
            else if (request.CanManageContent)
            {
                pageContentsQuery = pageContentsQuery.Where(f => f.Content.Status == ContentStatus.Published || f.Content.Status == ContentStatus.Draft);
            }
            else
            {
                pageContentsQuery = pageContentsQuery.Where(f => f.Content.Status == ContentStatus.Published);
            }

            pageContentsQuery = pageContentsQuery.Where(f => !f.IsDeleted && !f.Content.IsDeleted && !f.Page.IsDeleted);

            pageContentsQuery = pageContentsQuery
                                .Fetch(f => f.Content)
                                .ThenFetchMany(f => f.ContentOptions)

                                .FetchMany(f => f.Options)

                                .Fetch(f => f.Content)
                                .ThenFetchMany(f => f.ContentRegions)
                                .ThenFetch(f => f.Region)

                                // Fetch child contents
                                .Fetch(f => f.Content)
                                .ThenFetchMany(f => f.ChildContents);

            if (request.CanManageContent || request.PreviewPageContentId != null)
            {
                pageContentsQuery = pageContentsQuery
                                    .Fetch(f => f.Content)
                                    .ThenFetchMany(f => f.History)
                                    .ThenFetchMany(f => f.ChildContents);
            }

            var pageContents = pageContentsQuery.ToList();

            childContentService.RetrieveChildrenContentsRecursively(request.CanManageContent, pageContents.Select(pc => pc.Content).Distinct().ToList());

            return(pageContents);
        }