Merge branch 'temp8' into temp8-macros-dont-render-and-other-macro-bugs
# Conflicts: # src/Umbraco.Tests/Testing/TestingTests/MockTests.cs # src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs # src/Umbraco.Web/Templates/TemplateRenderer.cs
This commit is contained in:
54
src/Umbraco.Web/Routing/IPublishedRouter.cs
Normal file
54
src/Umbraco.Web/Routing/IPublishedRouter.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes requests.
|
||||
/// </summary>
|
||||
public interface IPublishedRouter
|
||||
{
|
||||
// TODO: consider this and RenderRouteHandler - move some code around?
|
||||
|
||||
/// <summary>
|
||||
/// Creates a published request.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The current Umbraco context.</param>
|
||||
/// <param name="uri">The (optional) request Uri.</param>
|
||||
/// <returns>A published request.</returns>
|
||||
PublishedRequest CreateRequest(UmbracoContext umbracoContext, Uri uri = null);
|
||||
|
||||
/// <summary>
|
||||
/// Prepares a request for rendering.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>A value indicating whether the request was successfully prepared and can be rendered.</returns>
|
||||
bool PrepareRequest(PublishedRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to route a request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>A value indicating whether the request can be routed to a document.</returns>
|
||||
bool TryRouteRequest(PublishedRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a template.
|
||||
/// </summary>
|
||||
/// <param name="alias">The template alias</param>
|
||||
/// <returns>The template.</returns>
|
||||
ITemplate GetTemplate(string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the request to "not found".
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <remarks>
|
||||
/// <para>This method is invoked when the pipeline decides it cannot render
|
||||
/// the request, for whatever reason, and wants to force it to be re-routed
|
||||
/// and rendered as if no document were found (404).</para>
|
||||
/// </remarks>
|
||||
void UpdateRequestToNotFound(PublishedRequest request);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace Umbraco.Web.Routing
|
||||
/// </summary>
|
||||
public class PublishedRequest
|
||||
{
|
||||
private readonly PublishedRouter _publishedRouter;
|
||||
private readonly IPublishedRouter _publishedRouter;
|
||||
|
||||
private bool _readonly; // after prepared
|
||||
private bool _readonlyUri; // after preparing
|
||||
@@ -35,7 +35,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <param name="publishedRouter">The published router.</param>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="uri">The request <c>Uri</c>.</param>
|
||||
internal PublishedRequest(PublishedRouter publishedRouter, UmbracoContext umbracoContext, Uri uri = null)
|
||||
internal PublishedRequest(IPublishedRouter publishedRouter, UmbracoContext umbracoContext, Uri uri = null)
|
||||
{
|
||||
UmbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
|
||||
_publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter));
|
||||
@@ -290,11 +290,11 @@ namespace Umbraco.Web.Routing
|
||||
/// </summary>
|
||||
public bool HasTemplate => TemplateModel != null;
|
||||
|
||||
internal void UpdateOnMissingTemplate()
|
||||
internal void UpdateToNotFound()
|
||||
{
|
||||
var __readonly = _readonly;
|
||||
_readonly = false;
|
||||
_publishedRouter.UpdateRequestOnMissingTemplate(this);
|
||||
_publishedRouter.UpdateRequestToNotFound(this);
|
||||
_readonly = __readonly;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Web.Security;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -18,8 +19,10 @@ using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
// TODO: making sense to have an interface?
|
||||
public class PublishedRouter
|
||||
/// <summary>
|
||||
/// Provides the default <see cref="IPublishedRouter"/> implementation.
|
||||
/// </summary>
|
||||
public class PublishedRouter : IPublishedRouter
|
||||
{
|
||||
private readonly IWebRoutingSection _webRoutingSection;
|
||||
private readonly ContentFinderCollection _contentFinders;
|
||||
@@ -47,15 +50,9 @@ namespace Umbraco.Web.Routing
|
||||
_profilingLogger = proflog ?? throw new ArgumentNullException(nameof(proflog));
|
||||
_variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
_logger = proflog;
|
||||
|
||||
GetRolesForLogin = s => Roles.Provider.GetRolesForUser(s);
|
||||
}
|
||||
|
||||
// TODO: in 7.7 this is cached in the PublishedContentRequest, which ... makes little sense
|
||||
// killing it entirely, if we need cache, just implement it properly !!
|
||||
// this is all so weird
|
||||
public Func<string, IEnumerable<string>> GetRolesForLogin { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public PublishedRequest CreateRequest(UmbracoContext umbracoContext, Uri uri = null)
|
||||
{
|
||||
return new PublishedRequest(this, umbracoContext, uri ?? umbracoContext.CleanedUmbracoUrl);
|
||||
@@ -63,10 +60,8 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
#region Request
|
||||
|
||||
/// <summary>
|
||||
/// Tries to route the request.
|
||||
/// </summary>
|
||||
internal bool TryRouteRequest(PublishedRequest request)
|
||||
/// <inheritdoc />
|
||||
public bool TryRouteRequest(PublishedRequest request)
|
||||
{
|
||||
// disabled - is it going to change the routing?
|
||||
//_pcr.OnPreparing();
|
||||
@@ -96,12 +91,7 @@ namespace Umbraco.Web.Routing
|
||||
_variationContextAccessor.VariationContext = new VariationContext(culture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the request.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Returns false if the request was not successfully prepared
|
||||
/// </returns>
|
||||
/// <inheritdoc />
|
||||
public bool PrepareRequest(PublishedRequest request)
|
||||
{
|
||||
// note - at that point the original legacy module did something do handle IIS custom 404 errors
|
||||
@@ -210,11 +200,8 @@ namespace Umbraco.Web.Routing
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the request when there is no template to render the content.
|
||||
/// </summary>
|
||||
/// <remarks>This is called from Mvc when there's a document to render but no template.</remarks>
|
||||
public void UpdateRequestOnMissingTemplate(PublishedRequest request)
|
||||
/// <inheritdoc />
|
||||
public void UpdateRequestToNotFound(PublishedRequest request)
|
||||
{
|
||||
// clear content
|
||||
var content = request.PublishedContent;
|
||||
@@ -381,11 +368,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
#region Document and template
|
||||
|
||||
/// <summary>
|
||||
/// Gets a template.
|
||||
/// </summary>
|
||||
/// <param name="alias">The template alias</param>
|
||||
/// <returns>The template.</returns>
|
||||
/// <inheritdoc />
|
||||
public ITemplate GetTemplate(string alias)
|
||||
{
|
||||
return _services.FileService.GetTemplate(alias);
|
||||
@@ -602,7 +585,7 @@ namespace Umbraco.Web.Routing
|
||||
if (loginPageId != request.PublishedContent.Id)
|
||||
request.PublishedContent = request.UmbracoContext.PublishedSnapshot.Content.GetById(loginPageId);
|
||||
}
|
||||
else if (_services.PublicAccessService.HasAccess(request.PublishedContent.Id, _services.ContentService, membershipHelper.CurrentUserName, GetRolesForLogin(membershipHelper.CurrentUserName)) == false)
|
||||
else if (_services.PublicAccessService.HasAccess(request.PublishedContent.Id, _services.ContentService, membershipHelper.CurrentUserName, membershipHelper.GetCurrentUserRoles()) == false)
|
||||
{
|
||||
_logger.Debug<PublishedRouter>("EnsurePublishedContentAccess: Current member has not access, redirect to error page");
|
||||
var errorPageId = publicAccessAttempt.Result.NoAccessNodeId;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Contains all the Urls that we can figure out (based upon domains, etc).</para>
|
||||
/// </remarks>
|
||||
public static IEnumerable<UrlInfo> GetContentUrls(this IContent content,
|
||||
PublishedRouter publishedRouter,
|
||||
IPublishedRouter publishedRouter,
|
||||
UmbracoContext umbracoContext,
|
||||
ILocalizationService localizationService,
|
||||
ILocalizedTextService textService,
|
||||
@@ -92,7 +92,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<UrlInfo> GetContentUrlsByCulture(IContent content,
|
||||
IEnumerable<string> cultures,
|
||||
PublishedRouter publishedRouter,
|
||||
IPublishedRouter publishedRouter,
|
||||
UmbracoContext umbracoContext,
|
||||
IContentService contentService,
|
||||
ILocalizedTextService textService,
|
||||
@@ -161,7 +161,7 @@ namespace Umbraco.Web.Routing
|
||||
return UrlInfo.Message(textService.Localize("content/parentCultureNotPublished", new[] {parent.Name}), culture);
|
||||
}
|
||||
|
||||
private static bool DetectCollision(IContent content, string url, string culture, UmbracoContext umbracoContext, PublishedRouter publishedRouter, ILocalizedTextService textService, out UrlInfo urlInfo)
|
||||
private static bool DetectCollision(IContent content, string url, string culture, UmbracoContext umbracoContext, IPublishedRouter publishedRouter, ILocalizedTextService textService, out UrlInfo urlInfo)
|
||||
{
|
||||
// test for collisions on the 'main' url
|
||||
var uri = new Uri(url.TrimEnd('/'), UriKind.RelativeOrAbsolute);
|
||||
|
||||
Reference in New Issue
Block a user