Placement's path condition now strips the Tenant/Site UrlPrefix (#8222)

Fixes #6962
This commit is contained in:
Hermes Sbicego 2019-07-11 21:09:13 +02:00 committed by Sébastien Ros
parent bb87e47bc3
commit 96ffefd078
4 changed files with 63 additions and 13 deletions

View File

@ -5,7 +5,9 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Environment.Configuration;
using Orchard.FileSystems.VirtualPath;
using Orchard.Mvc.Routes;
using Orchard.UI.Zones;
namespace Orchard.Layouts.Services {
@ -30,9 +32,9 @@ namespace Orchard.Layouts.Services {
_requestContext = requestContext;
_virtualPathProvider = virtualPathProvider;
_workContextAccessor = workContextAccessor;
}
public abstract UrlPrefix TenantUrlPrefix { get; }
public abstract string DefaultStereotype { get; }
public BuildDisplayContext BuildDisplayContext(IContent content, string displayType, string groupId) {
@ -145,7 +147,12 @@ namespace Orchard.Layouts.Services {
/// Gets the current app-relative path, i.e. ~/my-blog/foo.
/// </summary>
private string GetPath() {
return VirtualPathUtility.AppendTrailingSlash(_virtualPathProvider.ToAppRelative(_requestContext.HttpContext.Request.Path));
var appRelativePath = _virtualPathProvider.ToAppRelative(_requestContext.HttpContext.Request.Path);
// If the tenant has a prefix, we strip the tenant prefix away.
if (TenantUrlPrefix != null)
appRelativePath = TenantUrlPrefix.RemoveLeadingSegments(appRelativePath);
return VirtualPathUtility.AppendTrailingSlash(appRelativePath);
}
}
}

View File

@ -6,24 +6,39 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Environment.Configuration;
using Orchard.FileSystems.VirtualPath;
using Orchard.Mvc.Routes;
namespace Orchard.Layouts.Services {
public class ContentFieldDisplay : ContentDisplayBase, IContentFieldDisplay {
private readonly IEnumerable<IContentFieldDriver> _contentFieldDrivers;
private readonly ShellSettings _shellSettings;
public ContentFieldDisplay(
IShapeFactory shapeFactory,
Lazy<IShapeTableLocator> shapeTableLocator,
Lazy<IShapeTableLocator> shapeTableLocator,
RequestContext requestContext,
IVirtualPathProvider virtualPathProvider,
IWorkContextAccessor workContextAccessor,
IEnumerable<IContentFieldDriver> contentFieldDrivers)
IWorkContextAccessor workContextAccessor,
ShellSettings shellSettings,
IEnumerable<IContentFieldDriver> contentFieldDrivers)
: base(shapeFactory, shapeTableLocator, requestContext, virtualPathProvider, workContextAccessor) {
_shellSettings = shellSettings;
_contentFieldDrivers = contentFieldDrivers;
}
public override UrlPrefix TenantUrlPrefix {
get {
if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix)) {
return new UrlPrefix(_shellSettings.RequestUrlPrefix);
}
else {
return null;
}
}
}
public override string DefaultStereotype {
get { return "ContentField"; }
}
@ -63,7 +78,7 @@ namespace Orchard.Layouts.Services {
if (result != null)
result.Apply(context);
}, Logger);
return context.Shape;
}

View File

@ -6,23 +6,38 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Environment.Configuration;
using Orchard.FileSystems.VirtualPath;
using Orchard.Mvc.Routes;
namespace Orchard.Layouts.Services {
public class ContentPartDisplay : ContentDisplayBase, IContentPartDisplay {
private readonly IEnumerable<IContentPartDriver> _contentPartDrivers;
private readonly ShellSettings _shellSettings;
public ContentPartDisplay(
IShapeFactory shapeFactory,
Lazy<IShapeTableLocator> shapeTableLocator,
RequestContext requestContext,
IVirtualPathProvider virtualPathProvider,
IWorkContextAccessor workContextAccessor,
IWorkContextAccessor workContextAccessor,
ShellSettings shellSettings,
IEnumerable<IContentPartDriver> contentPartDrivers)
: base(shapeFactory, shapeTableLocator, requestContext, virtualPathProvider, workContextAccessor) {
_shellSettings = shellSettings;
_contentPartDrivers = contentPartDrivers;
}
public override UrlPrefix TenantUrlPrefix {
get {
if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix)) {
return new UrlPrefix(_shellSettings.RequestUrlPrefix);
}
else {
return null;
}
}
}
public override string DefaultStereotype {
get { return "ContentPart"; }

View File

@ -5,8 +5,10 @@ using System.Web.Routing;
using Orchard.ContentManagement.Handlers;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Environment.Configuration;
using Orchard.FileSystems.VirtualPath;
using Orchard.Logging;
using Orchard.Mvc.Routes;
using Orchard.UI.Zones;
namespace Orchard.ContentManagement {
@ -18,6 +20,8 @@ namespace Orchard.ContentManagement {
private readonly RequestContext _requestContext;
private readonly IVirtualPathProvider _virtualPathProvider;
private readonly IWorkContextAccessor _workContextAccessor;
private readonly ShellSettings _shellSettings;
private readonly UrlPrefix _urlPrefix;
public DefaultContentDisplay(
Lazy<IEnumerable<IContentHandler>> handlers,
@ -25,15 +29,19 @@ namespace Orchard.ContentManagement {
Lazy<IShapeTableLocator> shapeTableLocator,
RequestContext requestContext,
IVirtualPathProvider virtualPathProvider,
IWorkContextAccessor workContextAccessor) {
IWorkContextAccessor workContextAccessor,
ShellSettings shellSettings) {
_handlers = handlers;
_shapeFactory = shapeFactory;
_shapeTableLocator = shapeTableLocator;
_requestContext = requestContext;
_virtualPathProvider = virtualPathProvider;
_workContextAccessor = workContextAccessor;
_shellSettings = shellSettings;
if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
_urlPrefix = new UrlPrefix(_shellSettings.RequestUrlPrefix);
Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
@ -158,7 +166,12 @@ namespace Orchard.ContentManagement {
/// Gets the current app-relative path, i.e. ~/my-blog/foo.
/// </summary>
private string GetPath() {
return VirtualPathUtility.AppendTrailingSlash(_virtualPathProvider.ToAppRelative(_requestContext.HttpContext.Request.Path));
var appRelativePath = _virtualPathProvider.ToAppRelative(_requestContext.HttpContext.Request.Path);
// If the tenant has a prefix, we strip the tenant prefix away.
if (_urlPrefix != null)
appRelativePath = _urlPrefix.RemoveLeadingSegments(appRelativePath);
return VirtualPathUtility.AppendTrailingSlash(appRelativePath);
}
}
}