예제 #1
0
        private RenderPageViewModel CreatePageViewModel(Page renderingPage, List <PageContent> allPageContents, Page page,
                                                        GetPageToRenderRequest request, List <Page> childPagesList)
        {
            if (request.PreviewPageContentId == null && !request.IsAuthenticated && page.Status != PageStatus.Published)
            {
                throw new HttpException(403, "403 Access Forbidden");
            }

            // Preview and published pages can be accessible to users without content managing roles
            // Unpublished pages can be accessible only to content managers
            if (page.Status != PageStatus.Published && page.Status != PageStatus.Preview && !request.HasContentAccess)
            {
                if (!cmsConfiguration.Security.AccessControlEnabled)
                {
                    return(null); // Force 404.
                }
            }

            RenderPageViewModel renderPageViewModel = new RenderPageViewModel(page);

            renderPageViewModel.CanManageContent   = request.CanManageContent;
            renderPageViewModel.AreRegionsEditable = request.CanManageContent && !childPagesList.Any();

            if (page.Layout != null)
            {
                renderPageViewModel.LayoutPath = page.Layout.LayoutPath;
                renderPageViewModel.Options    = GetMergedOptionValues(page.Layout.LayoutOptions, page.Options, childPagesList);
                renderPageViewModel.Regions    = page.Layout.LayoutRegions
                                                 .Distinct()
                                                 .Select(f => new PageRegionViewModel
                {
                    RegionId         = f.Region.Id,
                    RegionIdentifier = f.Region.RegionIdentifier
                })
                                                 .ToList();
            }
            else if (page.MasterPage != null)
            {
                var masterPage = renderingPage.MasterPages.FirstOrDefault(p => p.Master.Id == page.MasterPage.Id);
                if (masterPage == null)
                {
                    throw new InvalidOperationException(string.Format("Cannot find a master page in master pages path collection for page {0}.", request.PageUrl));
                }

                childPagesList.Insert(0, page);
                renderPageViewModel.MasterPage = CreatePageViewModel(renderingPage, allPageContents, masterPage.Master, request, childPagesList);
                childPagesList.Remove(page);

                renderPageViewModel.Options = GetMergedOptionValues(new List <IOption>(), page.Options, childPagesList);
                renderPageViewModel.Regions = allPageContents
                                              .Where(pc => pc.Page == page.MasterPage)
                                              .SelectMany(pc => pc.Content.ContentRegions.Distinct())
                                              .Select(cr => new PageRegionViewModel
                {
                    RegionId         = cr.Region.Id,
                    RegionIdentifier = cr.Region.RegionIdentifier
                })
                                              .ToList();
            }
            else
            {
                throw new InvalidOperationException(string.Format("Failed to load layout or master page for page {0}.", request.PageUrl));
            }

            var pageContents       = allPageContents.Where(pc => pc.Page.Id == page.Id).Where(pc => pc.Parent == null || allPageContents.All(apc => apc.Id != pc.Parent.Id));
            var contentProjections = pageContents.Distinct()
                                     .Select(f => contentProjectionService.CreatePageContentProjection(request.CanManageContent, f, allPageContents, null, request.PreviewPageContentId))
                                     .Where(c => c != null).ToList();

            renderPageViewModel.Contents = contentProjections;
            renderPageViewModel.Metadata = pageAccessor.GetPageMetaData(page).ToList();

            if (page.AccessRules != null)
            {
                var list = page.AccessRules.Cast <IAccessRule>().ToList();
                list.RemoveDuplicates((a, b) => a.Id == b.Id ? 0 : -1);

                renderPageViewModel.AccessRules = list;
            }

            if (cmsConfiguration.Security.AccessControlEnabled)
            {
                SetIsReadOnly(renderPageViewModel, renderPageViewModel.AccessRules);
            }
            renderPageViewModel.HasEditRole = SecurityService.IsAuthorized(RootModuleConstants.UserRoles.EditContent);

            // Add <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> if current view is in an edit mode.
            if (request.CanManageContent)
            {
                if (renderPageViewModel.Metadata == null)
                {
                    renderPageViewModel.Metadata = new List <IPageActionProjection>();
                }

                renderPageViewModel.Metadata.Insert(0, new MetaDataProjection("X-UA-Compatible", "IE=edge,chrome=1"));
            }

            // Attach styles.
            var styles = new List <IStylesheetAccessor>();

            styles.Add(pageStylesheetProjectionFactory.Create(page, renderPageViewModel.Options));
            styles.AddRange(contentProjections);
            renderPageViewModel.Stylesheets = styles;

            // Attach JavaScript includes.
            var js = new List <IJavaScriptAccessor>();

            js.Add(pageJavaScriptProjectionFactory.Create(page, renderPageViewModel.Options));
            js.AddRange(contentProjections);
            renderPageViewModel.JavaScripts = js;

            // TODO: Fix main.js and processor.js IE cache.
            renderPageViewModel.MainJsPath    = string.Format(RootModuleConstants.AutoGeneratedJsFilePathPattern, "bcms.main.js");
            renderPageViewModel.RequireJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath,
                                                                    cmsConfiguration.UseMinifiedResources
                                                                        ? "bcms.require-2.1.5.min.js"
                                                                        : "bcms.require-2.1.5.js");
            renderPageViewModel.Html5ShivJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, "html5shiv.js");

            return(renderPageViewModel);
        }
예제 #2
0
        /// <summary>
        /// Executes this command.
        /// </summary>
        /// <param name="request">The request data with page data.</param>
        /// <returns>Executed command result.</returns>
        public CmsRequestViewModel Execute(GetPageToRenderRequest request)
        {
            var pageQuery         = GetPageFutureQuery(request);
            var pageContentsQuery = GetPageContentFutureQuery(request);

            var page = pageQuery.ToList().FirstOrDefault();

            if (page == null)
            {
                return(FindRedirect(request.PageUrl));
            }

            if (request.PreviewPageContentId == null && !request.IsAuthenticated && page.Status != PageStatus.Published)
            {
                throw new HttpException(403, "403 Access Forbidden");
            }

            // Preview and published pages can be accessible to users without content managing roles
            // Unpublished pages can be accessible only to content managers
            if (page.Status != PageStatus.Published && page.Status != PageStatus.Preview && !request.HasContentAccess)
            {
                if (!cmsConfiguration.Security.AccessControlEnabled)
                {
                    return(null); // Force 404.
                }
            }

            var pageContents       = pageContentsQuery.ToList();
            var contentProjections = pageContents.Distinct().Select(f => CreatePageContentProjection(request, f)).Where(c => c != null).ToList();

            RenderPageViewModel renderPageViewModel = new RenderPageViewModel(page);

            renderPageViewModel.CanManageContent = request.CanManageContent;
            renderPageViewModel.LayoutPath       = page.Layout.LayoutPath;

            renderPageViewModel.Regions =
                page.Layout.LayoutRegions.Distinct().Select(f => new PageRegionViewModel
            {
                RegionId         = f.Region.Id,
                RegionIdentifier = f.Region.RegionIdentifier
            })
                .ToList();

            renderPageViewModel.Contents = contentProjections;
            renderPageViewModel.Metadata = pageAccessor.GetPageMetaData(page).ToList();
            renderPageViewModel.Options  = optionService.GetMergedOptionValues(page.Layout.LayoutOptions, page.Options).ToList();

            if (page.AccessRules != null)
            {
                var list = page.AccessRules.Cast <IAccessRule>().ToList();
                list.RemoveDuplicates((a, b) => a.Id == b.Id ? 0 : -1);

                renderPageViewModel.AccessRules = list;
            }

            if (cmsConfiguration.Security.AccessControlEnabled)
            {
                SetIsReadOnly(renderPageViewModel, renderPageViewModel.AccessRules);
            }
            renderPageViewModel.HasEditRole = SecurityService.IsAuthorized(RootModuleConstants.UserRoles.EditContent);

            // Add <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> if current view is in an edit mode.
            if (request.CanManageContent)
            {
                if (renderPageViewModel.Metadata == null)
                {
                    renderPageViewModel.Metadata = new List <IPageActionProjection>();
                }

                renderPageViewModel.Metadata.Insert(0, new MetaDataProjection("X-UA-Compatible", "IE=edge,chrome=1"));
            }

            // Attach styles.
            var styles = new List <IStylesheetAccessor>();

            styles.Add(pageStylesheetProjectionFactory.Create(page, renderPageViewModel.Options));
            styles.AddRange(contentProjections);
            renderPageViewModel.Stylesheets = styles;

            // Attach JavaScript includes.
            var js = new List <IJavaScriptAccessor>();

            js.Add(pageJavaScriptProjectionFactory.Create(page, renderPageViewModel.Options));
            js.AddRange(contentProjections);
            renderPageViewModel.JavaScripts = js;

            // TODO: Fix main.js and processor.js IE cache.
            renderPageViewModel.MainJsPath    = string.Format(RootModuleConstants.AutoGeneratedJsFilePathPattern, "bcms.main.js");
            renderPageViewModel.RequireJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath,
                                                                    cmsConfiguration.UseMinifiedResources
                                                                        ? "bcms.require-2.1.5.min.js"
                                                                        : "bcms.require-2.1.5.js");
            renderPageViewModel.Html5ShivJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, "html5shiv.js");

            // Notify about retrieved page.
            var result = Events.RootEvents.Instance.OnPageRetrieved(renderPageViewModel, page);

            switch (result)
            {
            case PageRetrievedEventResult.ForcePageNotFound:
                return(null);

            default:
                return(new CmsRequestViewModel(renderPageViewModel));
            }
        }
예제 #3
0
        /// <summary>
        /// Executes this command.
        /// </summary>
        /// <param name="request">The request data with page data.</param>
        /// <returns>Executed command result.</returns>
        public CmsRequestViewModel Execute(GetPageToRenderRequest request)
        {
            var pageQuery         = GetPageFutureQuery(request);
            var pageContentsQuery = GetPageContentFutureQuery(request);

            var page = pageQuery.FirstOrDefault();

            if (page == null)
            {
                return(Redirect(request.PageUrl));
            }

            // Redirect user to login page, if page is inaccessible for public users
            // and user is not authenticated
            if (request.PreviewPageContentId == null && !request.IsAuthenticated && page.Status != PageStatus.Published && !string.IsNullOrWhiteSpace(cmsConfiguration.LoginUrl))
            {
                // TODO: uncomment redirect to login form, when login form will be im
                return(null);
                // return Redirect(cmsConfiguration.LoginUrl);
            }

            var pageContents       = pageContentsQuery.ToList();
            var contentProjections = pageContents.Distinct().Select(f => CreatePageContentProjection(request, f)).Where(c => c != null).ToList();

            RenderPageViewModel renderPageViewModel = new RenderPageViewModel(page);

            renderPageViewModel.CanManageContent = request.CanManageContent;
            renderPageViewModel.LayoutPath       = page.Layout.LayoutPath;

            renderPageViewModel.Regions =
                page.Layout.LayoutRegions.Distinct().Select(f => new PageRegionViewModel
            {
                RegionId         = f.Region.Id,
                RegionIdentifier = f.Region.RegionIdentifier
            })
                .ToList();

            renderPageViewModel.Contents = contentProjections;
            renderPageViewModel.Metadata = pageAccessor.GetPageMetaData(page).ToList();
            renderPageViewModel.Options  = optionService.GetMergedOptionValues(page.Layout.LayoutOptions, page.Options).ToList();

            // Attach styles.
            var styles = new List <IStylesheetAccessor>();

            styles.Add(pageStylesheetProjectionFactory.Create(page));
            styles.AddRange(contentProjections);
            renderPageViewModel.Stylesheets = styles;

            // Attach JavaScript includes.
            var js = new List <IJavaScriptAccessor>();

            js.Add(pageJavaScriptProjectionFactory.Create(page));
            js.AddRange(contentProjections);

            renderPageViewModel.JavaScripts = js;
            // TODO: Fix main.js and processor.js IE cache.
            renderPageViewModel.MainJsPath    = string.Format(RootModuleConstants.AutoGeneratedJsFilePathPattern, "bcms.main.js");
            renderPageViewModel.RequireJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath,
                                                                    cmsConfiguration.UseMinifiedResources
                                                                        ? "bcms.require-2.1.5.min.js"
                                                                        : "bcms.require-2.1.5.js");
            renderPageViewModel.Html5ShivJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, "html5shiv.js");

            // Notify about retrieved page.
            var result = Events.RootEvents.Instance.OnPageRetrieved(renderPageViewModel, page);

            switch (result)
            {
            case PageRetrievedEventResult.ForcePageNotFound:
                return(null);

            default:
                return(new CmsRequestViewModel(renderPageViewModel));
            }
        }