Esempio n. 1
0
        /// <summary>
        /// Processes the GetPage action.
        /// </summary>
        /// <param name="pagePreviewUrl">The page URL decorated with the preview URL prefix (virtual context).</param>
        public GetPageActionResult ProcessAction(string pagePreviewUrl)
        {
            if (!VirtualContext.IsPreviewLinkInitialized)
            {
                return(new GetPageActionResult(HttpStatusCode.Forbidden, statusCodeMessage: "The request is not authenticated via the preview URL decorator."));
            }

            if (String.IsNullOrEmpty(pagePreviewUrl))
            {
                return(new GetPageActionResult(HttpStatusCode.BadRequest, statusCodeMessage: "URL is missing the \"pageUrl\" parameter."));
            }

            string pageUrlPath = ExtractPageUrlPath(pagePreviewUrl);

            if (pageUrlPath == null)
            {
                return(new GetPageActionResult(HttpStatusCode.BadRequest, statusCodeMessage: "Invalid \"pageUrl\" parameter."));
            }

            TreeNode page = pagesProvider.GetPage(pageUrlPath);

            if (page == null)
            {
                return(new GetPageActionResult(HttpStatusCode.NotFound, statusCodeMessage: $"No page was found for the URL '{pageUrlPath}'."));
            }

            if (!page.CheckPermissions(PermissionsEnum.Read, SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser))
            {
                return(new GetPageActionResult(HttpStatusCode.Forbidden, statusCodeMessage: $"You are not authorized to access data of the page '{pageUrlPath}'."));
            }

            var pageModel = new PageLinkModel
            {
                Name     = GetPageName(page),
                NodeGuid = page.NodeGUID
            };

            return(new GetPageActionResult(HttpStatusCode.OK, pageModel));
        }
 public GetPageActionResult(HttpStatusCode statusCode, PageLinkModel page = null, string statusCodeMessage = null)
 {
     Page              = page;
     StatusCode        = statusCode;
     StatusCodeMessage = statusCodeMessage;
 }