Merge branch 'netcore/task/9727-published-request' into netcore/task/9733-routabledocumentfilter

This commit is contained in:
Shannon
2021-01-11 16:44:01 +11:00
42 changed files with 231 additions and 200 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Options;
@@ -112,10 +112,10 @@ namespace Umbraco.Web.Routing
// if the property varies, get the variant value, URL is "<domain>/<variant-alias>"
// but! only if the culture is published, else ignore
if (varies && !node.HasCulture(domainUri.Culture.Name)) continue;
if (varies && !node.HasCulture(domainUri.Culture)) continue;
var umbracoUrlName = varies
? node.Value<string>(_publishedValueFallback,Constants.Conventions.Content.UrlAlias, culture: domainUri.Culture.Name)
? node.Value<string>(_publishedValueFallback,Constants.Conventions.Content.UrlAlias, culture: domainUri.Culture)
: node.Value<string>(_publishedValueFallback, Constants.Conventions.Content.UrlAlias);
var aliases = umbracoUrlName?.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries);
@@ -127,7 +127,7 @@ namespace Umbraco.Web.Routing
{
var path = "/" + alias;
var uri = new Uri(CombinePaths(domainUri.Uri.GetLeftPart(UriPartial.Path), path));
yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _requestConfig).ToString(), domainUri.Culture.Name);
yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _requestConfig).ToString(), domainUri.Culture);
}
}
}

View File

@@ -77,7 +77,7 @@ namespace Umbraco.Web.Routing
if (!string.IsNullOrEmpty(cultureFromQuerystring))
{
// we're assuming it will match a culture, if an invalid one is passed in, an exception will throw (there is no TryGetCultureInfo method), i think this is ok though
frequest.SetCulture(CultureInfo.GetCultureInfo(cultureFromQuerystring));
frequest.SetCulture(cultureFromQuerystring);
}
frequest.SetPublishedContent(node);

View File

@@ -54,7 +54,7 @@ namespace Umbraco.Web.Routing
? frequest.Domain.ContentId + DomainUtilities.PathRelativeToDomain(frequest.Domain.Uri, frequest.Uri.GetAbsolutePathDecoded())
: frequest.Uri.GetAbsolutePathDecoded();
IRedirectUrl redirectUrl = _redirectUrlService.GetMostRecentRedirectUrl(route, frequest.Culture.Name);
IRedirectUrl redirectUrl = _redirectUrlService.GetMostRecentRedirectUrl(route, frequest.Culture);
if (redirectUrl == null)
{

View File

@@ -74,7 +74,7 @@ namespace Umbraco.Web.Routing
_logger.LogDebug("Test route {Route}", route);
IPublishedContent node = umbCtx.Content.GetByRoute(umbCtx.InPreviewMode, route, culture: docreq.Culture?.Name);
IPublishedContent node = umbCtx.Content.GetByRoute(umbCtx.InPreviewMode, route, culture: docreq.Culture);
if (node != null)
{
docreq.SetPublishedContent(node);

View File

@@ -59,7 +59,7 @@ namespace Umbraco.Web.Routing
node = FindContentByAlias(
umbCtx.Content,
frequest.Domain != null ? frequest.Domain.ContentId : 0,
frequest.Culture.Name,
frequest.Culture,
frequest.Uri.GetAbsolutePathDecoded());
if (node != null)

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
@@ -83,7 +83,9 @@ namespace Umbraco.Web.Routing
var umbracoContext = _umbracoContextAccessor.UmbracoContext;
var node = umbracoContext.Content.GetById(id);
if (node == null)
{
yield break;
}
// look for domains, walking up the tree
var n = node;
@@ -96,17 +98,19 @@ namespace Umbraco.Web.Routing
// no domains = exit
if (domainUris ==null)
{
yield break;
}
foreach (var d in domainUris)
{
var culture = d?.Culture?.Name;
var culture = d?.Culture;
//although we are passing in culture here, if any node in this path is invariant, it ignores the culture anyways so this is ok
// although we are passing in culture here, if any node in this path is invariant, it ignores the culture anyways so this is ok
var route = umbracoContext.Content.GetRouteById(id, culture);
if (route == null) continue;
//need to strip off the leading ID for the route if it exists (occurs if the route is for a node with a domain assigned)
// need to strip off the leading ID for the route if it exists (occurs if the route is for a node with a domain assigned)
var pos = route.IndexOf('/');
var path = pos == 0 ? route : route.Substring(pos);

View File

@@ -1,4 +1,4 @@
using System.Globalization;
using System.Globalization;
namespace Umbraco.Web.Routing
{
@@ -15,7 +15,7 @@ namespace Umbraco.Web.Routing
/// <param name="contentId">The identifier of the content which supports the domain.</param>
/// <param name="culture">The culture of the domain.</param>
/// <param name="isWildcard">A value indicating whether the domain is a wildcard domain.</param>
public Domain(int id, string name, int contentId, CultureInfo culture, bool isWildcard)
public Domain(int id, string name, int contentId, string culture, bool isWildcard)
{
Id = id;
Name = name;
@@ -55,7 +55,7 @@ namespace Umbraco.Web.Routing
/// <summary>
/// Gets the culture of the domain.
/// </summary>
public CultureInfo Culture { get; }
public string Culture { get; }
/// <summary>
/// Gets a value indicating whether the domain is a wildcard domain.

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
@@ -51,8 +51,8 @@ namespace Umbraco.Web.Routing
var rootContentId = domain?.ContentId ?? -1;
var wcDomain = FindWildcardDomainInPath(umbracoContext.Domains.GetAll(true), contentPath, rootContentId);
if (wcDomain != null) return wcDomain.Culture.Name;
if (domain != null) return domain.Culture.Name;
if (wcDomain != null) return wcDomain.Culture;
if (domain != null) return domain.Culture;
return umbracoContext.Domains.DefaultCulture;
}
@@ -233,13 +233,13 @@ namespace Umbraco.Web.Routing
if (culture != null) // try the supplied culture
{
var cultureDomains = domainsAndUris.Where(x => x.Culture.Name.InvariantEquals(culture)).ToList();
var cultureDomains = domainsAndUris.Where(x => x.Culture.InvariantEquals(culture)).ToList();
if (cultureDomains.Count > 0) return cultureDomains;
}
if (defaultCulture != null) // try the defaultCulture culture
{
var cultureDomains = domainsAndUris.Where(x => x.Culture.Name.InvariantEquals(defaultCulture)).ToList();
var cultureDomains = domainsAndUris.Where(x => x.Culture.InvariantEquals(defaultCulture)).ToList();
if (cultureDomains.Count > 0) return cultureDomains;
}
@@ -254,13 +254,13 @@ namespace Umbraco.Web.Routing
if (culture != null) // try the supplied culture
{
domainAndUri = domainsAndUris.FirstOrDefault(x => x.Culture.Name.InvariantEquals(culture));
domainAndUri = domainsAndUris.FirstOrDefault(x => x.Culture.InvariantEquals(culture));
if (domainAndUri != null) return domainAndUri;
}
if (defaultCulture != null) // try the defaultCulture culture
{
domainAndUri = domainsAndUris.FirstOrDefault(x => x.Culture.Name.InvariantEquals(defaultCulture));
domainAndUri = domainsAndUris.FirstOrDefault(x => x.Culture.InvariantEquals(defaultCulture));
if (domainAndUri != null) return domainAndUri;
}

View File

@@ -45,7 +45,11 @@ namespace Umbraco.Web.Routing
/// <summary>
/// Gets the content request's culture.
/// </summary>
CultureInfo Culture { get; }
/// <remarks>
/// This will get mapped to a CultureInfo eventually but CultureInfo are expensive to create so we want to leave that up to the
/// localization middleware to do. See https://github.com/dotnet/aspnetcore/blob/b795ac3546eb3e2f47a01a64feb3020794ca33bb/src/Middleware/Localization/src/RequestLocalizationMiddleware.cs#L165.
/// </remarks>
string Culture { get; }
/// <summary>
/// Gets the url to redirect to, when the content request triggers a redirect.

View File

@@ -26,7 +26,7 @@ namespace Umbraco.Web.Routing
/// <summary>
/// Gets the <see cref="CultureInfo"/> assigned (if any)
/// </summary>
CultureInfo Culture { get; }
string Culture { get; }
/// <summary>
/// Gets a value indicating whether the current published content has been obtained
@@ -64,7 +64,7 @@ namespace Umbraco.Web.Routing
/// <summary>
/// Sets the culture for the request
/// </summary>
IPublishedRequestBuilder SetCulture(CultureInfo culture);
IPublishedRequestBuilder SetCulture(string culture);
/// <summary>
/// Sets the found <see cref="IPublishedContent"/> for the request

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Web.Routing
/// <summary>
/// Initializes a new instance of the <see cref="PublishedRequest"/> class.
/// </summary>
public PublishedRequest(Uri uri, IPublishedContent publishedContent, bool isInternalRedirect, ITemplate template, DomainAndUri domain, CultureInfo culture, string redirectUrl, int? responseStatusCode, IReadOnlyList<string> cacheExtensions, IReadOnlyDictionary<string, string> headers, bool cacheabilityNoCache, bool ignorePublishedContentCollisions)
public PublishedRequest(Uri uri, IPublishedContent publishedContent, bool isInternalRedirect, ITemplate template, DomainAndUri domain, string culture, string redirectUrl, int? responseStatusCode, IReadOnlyList<string> cacheExtensions, IReadOnlyDictionary<string, string> headers, bool setNoCacheHeader, bool ignorePublishedContentCollisions)
{
Uri = uri ?? throw new ArgumentNullException(nameof(uri));
PublishedContent = publishedContent;
@@ -25,7 +25,7 @@ namespace Umbraco.Web.Routing
ResponseStatusCode = responseStatusCode;
CacheExtensions = cacheExtensions;
Headers = headers;
SetNoCacheHeader = cacheabilityNoCache;
SetNoCacheHeader = setNoCacheHeader;
IgnorePublishedContentCollisions = ignorePublishedContentCollisions;
}
@@ -48,7 +48,7 @@ namespace Umbraco.Web.Routing
public DomainAndUri Domain { get; }
/// <inheritdoc/>
public CultureInfo Culture { get; }
public string Culture { get; }
/// <inheritdoc/>
public string RedirectUrl { get; }

View File

@@ -36,7 +36,7 @@ namespace Umbraco.Web.Routing
public DomainAndUri Domain { get; private set; }
/// <inheritdoc/>
public CultureInfo Culture { get; private set; }
public string Culture { get; private set; }
/// <inheritdoc/>
public ITemplate Template { get; private set; }
@@ -89,7 +89,7 @@ namespace Umbraco.Web.Routing
}
/// <inheritdoc/>
public IPublishedRequestBuilder SetCulture(CultureInfo culture)
public IPublishedRequestBuilder SetCulture(string culture)
{
Culture = culture;
return this;

View File

@@ -121,15 +121,15 @@ namespace Umbraco.Web.Routing
return request.Build();
}
private void SetVariationContext(CultureInfo culture)
private void SetVariationContext(string culture)
{
VariationContext variationContext = _variationContextAccessor.VariationContext;
if (variationContext != null && variationContext.Culture == culture?.Name)
if (variationContext != null && variationContext.Culture == culture)
{
return;
}
_variationContextAccessor.VariationContext = new VariationContext(culture?.Name);
_variationContextAccessor.VariationContext = new VariationContext(culture);
}
/// <inheritdoc />
@@ -272,7 +272,7 @@ namespace Umbraco.Web.Routing
}
// variant, ensure that the culture corresponding to the domain's language is published
return domainDocument.Cultures.ContainsKey(domain.Culture.Name);
return domainDocument.Cultures.ContainsKey(domain.Culture);
}
domains = domains.Where(IsPublishedContentDomain).ToList();
@@ -302,10 +302,10 @@ namespace Umbraco.Web.Routing
// not matching any existing domain
_logger.LogDebug("{TracePrefix}Matches no domain", tracePrefix);
request.SetCulture(defaultCulture == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultCulture));
request.SetCulture(defaultCulture ?? CultureInfo.CurrentUICulture.Name);
}
_logger.LogDebug("{TracePrefix}Culture={CultureName}", tracePrefix, request.Culture.Name);
_logger.LogDebug("{TracePrefix}Culture={CultureName}", tracePrefix, request.Culture);
return request.Domain != null;
}
@@ -331,7 +331,7 @@ namespace Umbraco.Web.Routing
if (domain != null)
{
request.SetCulture(domain.Culture);
_logger.LogDebug("{TracePrefix}Got domain on node {DomainContentId}, set culture to {CultureName}", tracePrefix, domain.ContentId, request.Culture.Name);
_logger.LogDebug("{TracePrefix}Got domain on node {DomainContentId}, set culture to {CultureName}", tracePrefix, domain.ContentId, request.Culture);
}
else
{
@@ -665,7 +665,14 @@ namespace Umbraco.Web.Routing
var templateId = request.PublishedContent.TemplateId;
ITemplate template = GetTemplate(templateId);
request.SetTemplate(template);
_logger.LogDebug("FindTemplate: Running with template id={TemplateId} alias={TemplateAlias}", template.Id, template.Alias);
if (template != null)
{
_logger.LogDebug("FindTemplate: Running with template id={TemplateId} alias={TemplateAlias}", template.Id, template.Alias);
}
else
{
_logger.LogWarning("FindTemplate: Could not find template with id {TemplateId}", templateId);
}
}
else
{

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -284,9 +284,11 @@ namespace Umbraco.Web.Routing
// we do our best, but can't do the impossible
// get the "default" domain ie the first one for the culture, else the first one (exists, length > 0)
if (qualifiedSites == null)
return domainAndUris.FirstOrDefault(x => x.Culture.Name.InvariantEquals(culture)) ??
domainAndUris.FirstOrDefault(x => x.Culture.Name.InvariantEquals(defaultCulture)) ??
domainAndUris.First();
{
return domainAndUris.FirstOrDefault(x => x.Culture.InvariantEquals(culture))
?? domainAndUris.FirstOrDefault(x => x.Culture.InvariantEquals(defaultCulture))
?? domainAndUris.First();
}
// find a site that contains the current authority
var currentSite = qualifiedSites.FirstOrDefault(site => site.Value.Contains(currentAuthority));
@@ -308,7 +310,7 @@ namespace Umbraco.Web.Routing
.FirstOrDefault(domainAndUri => domainAndUri != null);
// random, really
ret = ret ?? domainAndUris.FirstOrDefault(x => x.Culture.Name.InvariantEquals(culture)) ?? domainAndUris.First();
ret = ret ?? domainAndUris.FirstOrDefault(x => x.Culture.InvariantEquals(culture)) ?? domainAndUris.First();
return ret;
}