Merge remote-tracking branch 'origin/netcore/dev' into netcore/feature/AB4919-untable-umbraco-context
# Conflicts: # src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs # src/Umbraco.Web/Macros/MacroRenderer.cs
This commit is contained in:
@@ -9,6 +9,56 @@ namespace Umbraco.Core
|
||||
{
|
||||
public static class PublishedContentExtensions
|
||||
{
|
||||
#region Name
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the content item.
|
||||
/// </summary>
|
||||
/// <param name="content">The content item.</param>
|
||||
/// <param name="variationContextAccessor"></param>
|
||||
/// <param name="culture">The specific culture to get the name for. If null is used the current culture is used (Default is null).</param>
|
||||
public static string Name(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null)
|
||||
{
|
||||
// invariant has invariant value (whatever the requested culture)
|
||||
if (!content.ContentType.VariesByCulture())
|
||||
return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.Name : null;
|
||||
|
||||
// handle context culture for variant
|
||||
if (culture == null)
|
||||
culture = variationContextAccessor?.VariationContext?.Culture ?? "";
|
||||
|
||||
// get
|
||||
return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.Name : null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Url segment
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url segment of the content item.
|
||||
/// </summary>
|
||||
/// <param name="content">The content item.</param>
|
||||
/// <param name="variationContextAccessor"></param>
|
||||
/// <param name="culture">The specific culture to get the url segment for. If null is used the current culture is used (Default is null).</param>
|
||||
public static string UrlSegment(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null)
|
||||
{
|
||||
// invariant has invariant value (whatever the requested culture)
|
||||
if (!content.ContentType.VariesByCulture())
|
||||
return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.UrlSegment : null;
|
||||
|
||||
// handle context culture for variant
|
||||
if (culture == null)
|
||||
culture = variationContextAccessor?.VariationContext?.Culture ?? "";
|
||||
|
||||
// get
|
||||
return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.UrlSegment : null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Culture
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the content has a culture.
|
||||
/// </summary>
|
||||
@@ -40,47 +90,6 @@ namespace Umbraco.Core
|
||||
return contents.Where(x => !x.ContentType.VariesByCulture() || HasCulture(x, culture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the content item.
|
||||
/// </summary>
|
||||
/// <param name="content">The content item.</param>
|
||||
/// <param name="variationContextAccessor"></param>
|
||||
/// <param name="culture">The specific culture to get the name for. If null is used the current culture is used (Default is null).</param>
|
||||
public static string Name(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null)
|
||||
{
|
||||
// invariant has invariant value (whatever the requested culture)
|
||||
if (!content.ContentType.VariesByCulture())
|
||||
return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.Name : null;
|
||||
|
||||
// handle context culture for variant
|
||||
if (culture == null)
|
||||
culture = variationContextAccessor?.VariationContext?.Culture ?? "";
|
||||
|
||||
// get
|
||||
return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.Name : null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url segment of the content item.
|
||||
/// </summary>
|
||||
/// <param name="content">The content item.</param>
|
||||
/// <param name="variationContextAccessor"></param>
|
||||
/// <param name="culture">The specific culture to get the url segment for. If null is used the current culture is used (Default is null).</param>
|
||||
public static string UrlSegment(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null)
|
||||
{
|
||||
// invariant has invariant value (whatever the requested culture)
|
||||
if (!content.ContentType.VariesByCulture())
|
||||
return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.UrlSegment : null;
|
||||
|
||||
// handle context culture for variant
|
||||
if (culture == null)
|
||||
culture = variationContextAccessor?.VariationContext?.Culture ?? "";
|
||||
|
||||
// get
|
||||
return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.UrlSegment : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the culture date of the content item.
|
||||
/// </summary>
|
||||
@@ -101,53 +110,211 @@ namespace Umbraco.Core
|
||||
return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.Date : DateTime.MinValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsComposedOf
|
||||
|
||||
/// <summary>
|
||||
/// Gets the children of the content item.
|
||||
/// Gets a value indicating whether the content is of a content type composed of the given alias
|
||||
/// </summary>
|
||||
/// <param name="content">The content item.</param>
|
||||
/// <param name="variationContextAccessor"></param>
|
||||
/// <param name="culture">
|
||||
/// The specific culture to get the url children for. Default is null which will use the current culture in <see cref="VariationContext"/>
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// <para>Gets children that are available for the specified culture.</para>
|
||||
/// <para>Children are sorted by their sortOrder.</para>
|
||||
/// <para>
|
||||
/// For culture,
|
||||
/// if null is used the current culture is used.
|
||||
/// If an empty string is used only invariant children are returned.
|
||||
/// If "*" is used all children are returned.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If a variant culture is specified or there is a current culture in the <see cref="VariationContext"/> then the Children returned
|
||||
/// will include both the variant children matching the culture AND the invariant children because the invariant children flow with the current culture.
|
||||
/// However, if an empty string is specified only invariant children are returned.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static IEnumerable<IPublishedContent> Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null)
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The content type alias.</param>
|
||||
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
|
||||
public static bool IsComposedOf(this IPublishedContent content, string alias)
|
||||
{
|
||||
// handle context culture for variant
|
||||
if (culture == null)
|
||||
culture = variationContextAccessor?.VariationContext?.Culture ?? "";
|
||||
|
||||
var children = content.ChildrenForAllCultures;
|
||||
return culture == "*"
|
||||
? children
|
||||
: children.Where(x => x.IsInvariantOrHasCulture(culture));
|
||||
return content.ContentType.CompositionAliases.InvariantContains(alias);
|
||||
}
|
||||
|
||||
#region Writer and creator
|
||||
#endregion
|
||||
|
||||
public static string GetCreatorName(this IPublishedContent content, IUserService userService)
|
||||
#region Template
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current template Alias
|
||||
/// </summary>
|
||||
/// <returns>Empty string if none is set.</returns>
|
||||
public static string GetTemplateAlias(this IPublishedContent content, IFileService fileService)
|
||||
{
|
||||
var user = userService.GetProfileById(content.CreatorId);
|
||||
return user?.Name;
|
||||
if (content.TemplateId.HasValue == false)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var template = fileService.GetTemplate(content.TemplateId.Value);
|
||||
return template == null ? string.Empty : template.Alias;
|
||||
}
|
||||
|
||||
public static string GetWriterName(this IPublishedContent content, IUserService userService)
|
||||
public static bool IsAllowedTemplate(this IPublishedContent content, IContentTypeService contentTypeService, bool disableAlternativeTemplates, bool validateAlternativeTemplates, int templateId)
|
||||
{
|
||||
var user = userService.GetProfileById(content.WriterId);
|
||||
return user?.Name;
|
||||
if (disableAlternativeTemplates)
|
||||
return content.TemplateId == templateId;
|
||||
|
||||
if (content.TemplateId == templateId || !validateAlternativeTemplates)
|
||||
return true;
|
||||
|
||||
var publishedContentContentType = contentTypeService.Get(content.ContentType.Id);
|
||||
if (publishedContentContentType == null)
|
||||
throw new NullReferenceException("No content type returned for published content (contentType='" + content.ContentType.Id + "')");
|
||||
|
||||
return publishedContentContentType.IsAllowedTemplate(templateId);
|
||||
|
||||
}
|
||||
public static bool IsAllowedTemplate(this IPublishedContent content, IFileService fileService, IContentTypeService contentTypeService, bool disableAlternativeTemplates, bool validateAlternativeTemplates, string templateAlias)
|
||||
{
|
||||
var template = fileService.GetTemplate(templateAlias);
|
||||
return template != null && content.IsAllowedTemplate(contentTypeService, disableAlternativeTemplates, validateAlternativeTemplates, template.Id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HasValue, Value, Value<T>
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content has a value for a property identified by its alias.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="publishedValueFallback">The published value fallback implementation.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <param name="culture">The variation language.</param>
|
||||
/// <param name="segment">The variation segment.</param>
|
||||
/// <param name="fallback">Optional fallback strategy.</param>
|
||||
/// <returns>A value indicating whether the content has a value for the property identified by the alias.</returns>
|
||||
/// <remarks>Returns true if HasValue is true, or a fallback strategy can provide a value.</remarks>
|
||||
public static bool HasValue(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return true;
|
||||
|
||||
// else let fallback try to get a value
|
||||
return publishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, null, out _, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a content's property identified by its alias, if it exists, otherwise a default value.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="publishedValueFallback">The published value fallback implementation.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <param name="culture">The variation language.</param>
|
||||
/// <param name="segment">The variation segment.</param>
|
||||
/// <param name="fallback">Optional fallback strategy.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <returns>The value of the content's property identified by the alias, if it exists, otherwise a default value.</returns>
|
||||
public static object Value(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.GetValue(culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (publishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value, out property))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable)
|
||||
return property?.GetValue(culture, segment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a content's property identified by its alias, converted to a specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The target property type.</typeparam>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="publishedValueFallback">The published value fallback implementation.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <param name="culture">The variation language.</param>
|
||||
/// <param name="segment">The variation segment.</param>
|
||||
/// <param name="fallback">Optional fallback strategy.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <returns>The value of the content's property identified by the alias, converted to the specified type.</returns>
|
||||
public static T Value<T>(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.Value<T>(publishedValueFallback, culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (publishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value, out property))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable) - otherwise, default
|
||||
return property == null ? default : property.Value<T>(publishedValueFallback, culture, segment);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsSomething: misc.
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified content is a specified content type.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to determine content type of.</param>
|
||||
/// <param name="docTypeAlias">The alias of the content type to test against.</param>
|
||||
/// <returns>True if the content is of the specified content type; otherwise false.</returns>
|
||||
public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias)
|
||||
{
|
||||
return content.ContentType.Alias.InvariantEquals(docTypeAlias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified content is a specified content type or it's derived types.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to determine content type of.</param>
|
||||
/// <param name="docTypeAlias">The alias of the content type to test against.</param>
|
||||
/// <param name="recursive">When true, recurses up the content type tree to check inheritance; when false just calls IsDocumentType(this IPublishedContent content, string docTypeAlias).</param>
|
||||
/// <returns>True if the content is of the specified content type or a derived content type; otherwise false.</returns>
|
||||
public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias, bool recursive)
|
||||
{
|
||||
if (content.IsDocumentType(docTypeAlias))
|
||||
return true;
|
||||
|
||||
return recursive && content.IsComposedOf(docTypeAlias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsSomething: equality
|
||||
|
||||
public static bool IsEqual(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.Id == other.Id;
|
||||
}
|
||||
|
||||
public static bool IsNotEqual(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.IsEqual(other) == false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsSomething: ancestors and descendants
|
||||
|
||||
public static bool IsDescendant(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return other.Level < content.Level && content.Path.InvariantStartsWith(other.Path.EnsureEndsWith(','));
|
||||
}
|
||||
|
||||
public static bool IsDescendantOrSelf(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.Path.InvariantEquals(other.Path) || content.IsDescendant(other);
|
||||
}
|
||||
|
||||
public static bool IsAncestor(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.Level < other.Level && other.Path.InvariantStartsWith(content.Path.EnsureEndsWith(','));
|
||||
}
|
||||
|
||||
public static bool IsAncestorOrSelf(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return other.Path.InvariantEquals(content.Path) || content.IsAncestor(other);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -639,6 +806,41 @@ namespace Umbraco.Core
|
||||
|
||||
#region Axes: children
|
||||
|
||||
/// <summary>
|
||||
/// Gets the children of the content item.
|
||||
/// </summary>
|
||||
/// <param name="content">The content item.</param>
|
||||
/// <param name="variationContextAccessor"></param>
|
||||
/// <param name="culture">
|
||||
/// The specific culture to get the url children for. Default is null which will use the current culture in <see cref="VariationContext"/>
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// <para>Gets children that are available for the specified culture.</para>
|
||||
/// <para>Children are sorted by their sortOrder.</para>
|
||||
/// <para>
|
||||
/// For culture,
|
||||
/// if null is used the current culture is used.
|
||||
/// If an empty string is used only invariant children are returned.
|
||||
/// If "*" is used all children are returned.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If a variant culture is specified or there is a current culture in the <see cref="VariationContext"/> then the Children returned
|
||||
/// will include both the variant children matching the culture AND the invariant children because the invariant children flow with the current culture.
|
||||
/// However, if an empty string is specified only invariant children are returned.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static IEnumerable<IPublishedContent> Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null)
|
||||
{
|
||||
// handle context culture for variant
|
||||
if (culture == null)
|
||||
culture = variationContextAccessor?.VariationContext?.Culture ?? "";
|
||||
|
||||
var children = content.ChildrenForAllCultures;
|
||||
return culture == "*"
|
||||
? children
|
||||
: children.Where(x => x.IsInvariantOrHasCulture(culture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the children of the content, filtered by a predicate.
|
||||
/// </summary>
|
||||
@@ -741,7 +943,7 @@ namespace Umbraco.Core
|
||||
|
||||
#endregion
|
||||
|
||||
#region Axes: Siblings
|
||||
#region Axes: siblings
|
||||
|
||||
/// <summary>
|
||||
/// Gets the siblings of the content.
|
||||
@@ -857,5 +1059,21 @@ namespace Umbraco.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Writer and creator
|
||||
|
||||
public static string GetCreatorName(this IPublishedContent content, IUserService userService)
|
||||
{
|
||||
var user = userService.GetProfileById(content.CreatorId);
|
||||
return user?.Name;
|
||||
}
|
||||
|
||||
public static string GetWriterName(this IPublishedContent content, IUserService userService)
|
||||
{
|
||||
var user = userService.GetProfileById(content.WriterId);
|
||||
return user?.Name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Core
|
||||
@@ -23,5 +22,158 @@ namespace Umbraco.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsComposedOf
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content is of a content type composed of the given alias
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The content type alias.</param>
|
||||
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
|
||||
public static bool IsComposedOf(this IPublishedElement content, string alias)
|
||||
{
|
||||
return content.ContentType.CompositionAliases.InvariantContains(alias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HasProperty
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content has a property identified by its alias.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <returns>A value indicating whether the content has the property identified by the alias.</returns>
|
||||
/// <remarks>The content may have a property, and that property may not have a value.</remarks>
|
||||
public static bool HasProperty(this IPublishedElement content, string alias)
|
||||
{
|
||||
return content.ContentType.GetPropertyType(alias) != null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HasValue
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content has a value for a property identified by its alias.
|
||||
/// </summary>
|
||||
/// <remarks>Returns true if <c>GetProperty(alias)</c> is not <c>null</c> and <c>GetProperty(alias).HasValue</c> is <c>true</c>.</remarks>
|
||||
public static bool HasValue(this IPublishedElement content, string alias, string culture = null, string segment = null)
|
||||
{
|
||||
var prop = content.GetProperty(alias);
|
||||
return prop != null && prop.HasValue(culture, segment);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a content's property identified by its alias.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="publishedValueFallback">The published value fallback implementation.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <param name="culture">The variation language.</param>
|
||||
/// <param name="segment">The variation segment.</param>
|
||||
/// <param name="fallback">Optional fallback strategy.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <returns>The value of the content's property identified by the alias, if it exists, otherwise a default value.</returns>
|
||||
/// <remarks>
|
||||
/// <para>The value comes from <c>IPublishedProperty</c> field <c>Value</c> ie it is suitable for use when rendering content.</para>
|
||||
/// <para>If no property with the specified alias exists, or if the property has no value, returns <paramref name="defaultValue"/>.</para>
|
||||
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
public static object Value(this IPublishedElement content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.GetValue(culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (publishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable) - otherwise, default
|
||||
return property?.GetValue(culture, segment);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value<T>
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a content's property identified by its alias, converted to a specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The target property type.</typeparam>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="publishedValueFallback">The published value fallback implementation.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <param name="culture">The variation language.</param>
|
||||
/// <param name="segment">The variation segment.</param>
|
||||
/// <param name="fallback">Optional fallback strategy.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <returns>The value of the content's property identified by the alias, converted to the specified type.</returns>
|
||||
/// <remarks>
|
||||
/// <para>The value comes from <c>IPublishedProperty</c> field <c>Value</c> ie it is suitable for use when rendering content.</para>
|
||||
/// <para>If no property with the specified alias exists, or if the property has no value, or if it could not be converted, returns <c>default(T)</c>.</para>
|
||||
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
public static T Value<T>(this IPublishedElement content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.Value<T>(publishedValueFallback, culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (publishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable) - otherwise, default
|
||||
return property == null ? default : property.Value<T>(publishedValueFallback, culture, segment);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ToIndexedArray
|
||||
|
||||
public static IndexedArrayItem<TContent>[] ToIndexedArray<TContent>(this IEnumerable<TContent> source)
|
||||
where TContent : class, IPublishedElement
|
||||
{
|
||||
var set = source.Select((content, index) => new IndexedArrayItem<TContent>(content, index)).ToArray();
|
||||
foreach (var setItem in set) setItem.TotalCount = set.Length;
|
||||
return set;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsSomething
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content is visible.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="publishedValueFallback">The published value fallback implementation.</param>
|
||||
/// <returns>A value indicating whether the content is visible.</returns>
|
||||
/// <remarks>A content is not visible if it has an umbracoNaviHide property with a value of "1". Otherwise,
|
||||
/// the content is visible.</remarks>
|
||||
public static bool IsVisible(this IPublishedElement content, IPublishedValueFallback publishedValueFallback)
|
||||
{
|
||||
// rely on the property converter - will return default bool value, ie false, if property
|
||||
// is not defined, or has no value, else will return its value.
|
||||
return content.Value<bool>(publishedValueFallback, Constants.Conventions.Content.NaviHide) == false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extension methods for <c>IPublishedProperty</c>.
|
||||
/// </summary>
|
||||
public static class PublishedPropertyExtension
|
||||
{
|
||||
#region Value
|
||||
|
||||
public static object Value(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default)
|
||||
{
|
||||
if (property.HasValue(culture, segment))
|
||||
return property.GetValue(culture, segment);
|
||||
|
||||
return publishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var value)
|
||||
? value
|
||||
: property.GetValue(culture, segment); // give converter a chance to return it's own vision of "no value"
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value<T>
|
||||
|
||||
public static T Value<T>(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default)
|
||||
{
|
||||
if (property.HasValue(culture, segment))
|
||||
{
|
||||
// we have a value
|
||||
// try to cast or convert it
|
||||
var value = property.GetValue(culture, segment);
|
||||
if (value is T valueAsT) return valueAsT;
|
||||
var valueConverted = value.TryConvertTo<T>();
|
||||
if (valueConverted) return valueConverted.Result;
|
||||
|
||||
// cannot cast nor convert the value, nothing we can return but 'default'
|
||||
// note: we don't want to fallback in that case - would make little sense
|
||||
return default;
|
||||
}
|
||||
|
||||
// we don't have a value, try fallback
|
||||
if (publishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var fallbackValue))
|
||||
return fallbackValue;
|
||||
|
||||
// we don't have a value - neither direct nor fallback
|
||||
// give a chance to the converter to return something (eg empty enumerable)
|
||||
var noValue = property.GetValue(culture, segment);
|
||||
if (noValue is T noValueAsT) return noValueAsT;
|
||||
var noValueConverted = noValue.TryConvertTo<T>();
|
||||
if (noValueConverted) return noValueConverted.Result;
|
||||
|
||||
// cannot cast noValue nor convert it, nothing we can return but 'default'
|
||||
return default;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
_umbracoContext = new UmbracoContext(
|
||||
_httpContextFactory.HttpContext,
|
||||
publishedSnapshotService.Object,
|
||||
new WebSecurity(_httpContextFactory.HttpContext, Mock.Of<IUserService>(), globalSettings),
|
||||
new WebSecurity(_httpContextFactory.HttpContext, Mock.Of<IUserService>(), globalSettings, IOHelper),
|
||||
umbracoSettings,
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Xml;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
@@ -108,7 +109,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
_previewXml = _xmlStore.GetPreviewXml(contentId, includeSubs);
|
||||
|
||||
// make sure the preview folder exists
|
||||
var dir = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.Preview));
|
||||
var dir = new DirectoryInfo(TestHelper.IOHelper.MapPath(Constants.SystemDirectories.Preview));
|
||||
if (dir.Exists == false)
|
||||
dir.Create();
|
||||
|
||||
@@ -122,7 +123,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
// get the full path to the preview set
|
||||
private static string GetPreviewSetPath(int userId, Guid previewSet)
|
||||
{
|
||||
return Current.IOHelper.MapPath(Path.Combine(Constants.SystemDirectories.Preview, userId + "_" + previewSet + ".config"));
|
||||
return TestHelper.IOHelper.MapPath(Path.Combine(Constants.SystemDirectories.Preview, userId + "_" + previewSet + ".config"));
|
||||
}
|
||||
|
||||
// deletes files for the user, and files accessed more than one hour ago
|
||||
|
||||
@@ -22,6 +22,7 @@ using Umbraco.Core.Services.Changes;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Xml;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
@@ -94,7 +95,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(_hostingEnvironment));
|
||||
_xmlFileName = TestHelper.IOHelper.MapPath(SystemFiles.GetContentCacheXml(_hostingEnvironment));
|
||||
|
||||
if (testing)
|
||||
{
|
||||
@@ -118,7 +119,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
_mediaRepository = mediaRepository;
|
||||
_memberRepository = memberRepository;
|
||||
_xmlFileEnabled = false;
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(hostingEnvironment));
|
||||
_xmlFileName = TestHelper.IOHelper.MapPath(SystemFiles.GetContentCacheXml(hostingEnvironment));
|
||||
// do not plug events, we may not have what it takes to handle them
|
||||
}
|
||||
|
||||
@@ -132,7 +133,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
_memberRepository = memberRepository;
|
||||
GetXmlDocument = getXmlDocument ?? throw new ArgumentNullException(nameof(getXmlDocument));
|
||||
_xmlFileEnabled = false;
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(hostingEnvironment));
|
||||
_xmlFileName = TestHelper.IOHelper.MapPath(SystemFiles.GetContentCacheXml(hostingEnvironment));
|
||||
// do not plug events, we may not have what it takes to handle them
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,14 @@ using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Components;
|
||||
using Umbraco.Tests.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.Published
|
||||
{
|
||||
[TestFixture]
|
||||
public class ConvertersTests
|
||||
public class ConvertersTests : UmbracoTestBase
|
||||
{
|
||||
#region SimpleConverter1
|
||||
|
||||
|
||||
@@ -17,16 +17,15 @@ using Umbraco.Web;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Published
|
||||
{
|
||||
[TestFixture]
|
||||
public class NestedContentTests
|
||||
public class NestedContentTests : UmbracoTestBase
|
||||
{
|
||||
private (IPublishedContentType, IPublishedContentType) CreateContentTypes()
|
||||
{
|
||||
Current.Reset();
|
||||
|
||||
var logger = Mock.Of<ILogger>();
|
||||
var profiler = Mock.Of<IProfiler>();
|
||||
var proflog = new ProfilingLogger(logger, profiler);
|
||||
|
||||
@@ -12,13 +12,14 @@ using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.Published
|
||||
{
|
||||
[TestFixture]
|
||||
public class PropertyCacheLevelTests
|
||||
public class PropertyCacheLevelTests : UmbracoTestBase
|
||||
{
|
||||
[TestCase(PropertyCacheLevel.None, 2)]
|
||||
[TestCase(PropertyCacheLevel.Element, 1)]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContext,
|
||||
publishedSnapshotService.Object,
|
||||
new WebSecurity(httpContext, Current.Services.UserService, globalSettings),
|
||||
new WebSecurity(httpContext, Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Umbraco.Tests.Routing
|
||||
public void Is_Reserved_Path_Or_Url(string url)
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var routableDocFilter = new RoutableDocumentFilter(globalSettings);
|
||||
var routableDocFilter = new RoutableDocumentFilter(globalSettings, IOHelper);
|
||||
Assert.IsTrue(routableDocFilter.IsReservedPathOrUrl(url));
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Umbraco.Tests.Routing
|
||||
public void Is_Not_Reserved_Path_Or_Url(string url)
|
||||
{
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var routableDocFilter = new RoutableDocumentFilter(globalSettings);
|
||||
var routableDocFilter = new RoutableDocumentFilter(globalSettings, IOHelper);
|
||||
Assert.IsFalse(routableDocFilter.IsReservedPathOrUrl(url));
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Tests.Routing
|
||||
globalSettingsMock.Setup(x => x.ReservedPaths).Returns("");
|
||||
globalSettingsMock.Setup(x => x.ReservedUrls).Returns("");
|
||||
|
||||
var routableDocFilter = new RoutableDocumentFilter(globalSettingsMock.Object);
|
||||
var routableDocFilter = new RoutableDocumentFilter(globalSettingsMock.Object, IOHelper);
|
||||
|
||||
var routes = new RouteCollection();
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Umbraco.Tests.Routing
|
||||
logger,
|
||||
null, // FIXME: PublishedRouter complexities...
|
||||
Mock.Of<IUmbracoContextFactory>(),
|
||||
new RoutableDocumentFilter(globalSettings)
|
||||
new RoutableDocumentFilter(globalSettings, IOHelper)
|
||||
);
|
||||
|
||||
runtime.Level = RuntimeLevel.Run;
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Umbraco.Tests.Scoping
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContext,
|
||||
service,
|
||||
new WebSecurity(httpContext, Current.Services.UserService, globalSettings),
|
||||
new WebSecurity(httpContext, Current.Services.UserService, globalSettings, IOHelper),
|
||||
umbracoSettings ?? SettingsForTests.GetDefaultUmbracoSettings(),
|
||||
urlProviders ?? Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Tests.Security
|
||||
var umbracoContext = new UmbracoContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
|
||||
new TestVariationContextAccessor(), IOHelper);
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Umbraco.Tests.Security
|
||||
var umbCtx = new UmbracoContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
|
||||
new TestVariationContextAccessor(), IOHelper);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using Moq;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
@@ -385,7 +385,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
httpContext,
|
||||
service,
|
||||
new WebSecurity(httpContext, Factory.GetInstance<IUserService>(),
|
||||
Factory.GetInstance<IGlobalSettings>()),
|
||||
Factory.GetInstance<IGlobalSettings>(), IOHelper),
|
||||
umbracoSettings ?? Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
urlProviders ?? Enumerable.Empty<IUrlProvider>(),
|
||||
mediaUrlProviders ?? Enumerable.Empty<IMediaUrlProvider>(),
|
||||
|
||||
@@ -49,13 +49,11 @@ using Umbraco.Web.Templates;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Net;
|
||||
using Umbraco.Web.Security;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
namespace Umbraco.Tests.Testing
|
||||
{
|
||||
/// <summary>
|
||||
@@ -297,7 +295,7 @@ namespace Umbraco.Tests.Testing
|
||||
Composition.RegisterUnique<HtmlUrlParser>();
|
||||
Composition.RegisterUnique<HtmlImageSourceParser>();
|
||||
Composition.RegisterUnique<RichTextEditorPastedImages>();
|
||||
|
||||
Composition.RegisterUnique<IPublishedValueFallback, NoopPublishedValueFallback>();
|
||||
}
|
||||
|
||||
protected virtual void ComposeMisc()
|
||||
|
||||
@@ -33,6 +33,7 @@ using Umbraco.Web.Features;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
@@ -87,7 +88,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Factory.GetInstance<IRuntimeState>(),
|
||||
helper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IUmbracoSettingsSection>());
|
||||
Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
Factory.GetInstance<IIOHelper>());
|
||||
return usersController;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,9 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Factory.GetInstance<IMediaFileSystem>(),
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IUmbracoSettingsSection>());
|
||||
Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
Factory.GetInstance<IIOHelper>()
|
||||
);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
@@ -157,7 +159,9 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Factory.GetInstance<IMediaFileSystem>(),
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IUmbracoSettingsSection>());
|
||||
Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
Factory.GetInstance<IIOHelper>()
|
||||
);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
@@ -196,7 +200,9 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Factory.GetInstance<IMediaFileSystem>(),
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IUmbracoSettingsSection>());
|
||||
Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
Factory.GetInstance<IIOHelper>()
|
||||
);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
@@ -270,7 +276,9 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Factory.GetInstance<IMediaFileSystem>(),
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IUmbracoSettingsSection>());
|
||||
Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
Factory.GetInstance<IIOHelper>()
|
||||
);
|
||||
return usersController;
|
||||
}
|
||||
|
||||
|
||||
@@ -440,7 +440,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
var ctx = new UmbracoContext(
|
||||
http,
|
||||
_service,
|
||||
new WebSecurity(http, Current.Services.UserService, globalSettings),
|
||||
new WebSecurity(http, Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Tests.Web
|
||||
var umbCtx = new UmbracoContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings()),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
new List<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
@@ -49,7 +49,7 @@ namespace Umbraco.Tests.Web
|
||||
var umbCtx = new UmbracoContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings()),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
new List<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
@@ -79,7 +79,7 @@ namespace Umbraco.Tests.Web
|
||||
var umbCtx = new UmbracoContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings()),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
new List<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
|
||||
@foreach (var item in selection.OrderBy(x => x.Level))
|
||||
{
|
||||
<li><a href="@item.Url">@item.Name</a> <span class="divider">/</span></li>
|
||||
<li><a href="@item.Url()">@item.Name</a> <span class="divider">/</span></li>
|
||||
}
|
||||
|
||||
@* Display the current page as the last item in the list *@
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
@helper Render(IPublishedContent item)
|
||||
{
|
||||
<div class="col-xs-6 col-md-3">
|
||||
<a href="@item.Url" class="thumbnail">
|
||||
<a href="@item.Url()" class="thumbnail">
|
||||
<img src="@item.GetCropUrl(width:200, height:200)" alt="@item.Name" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
|
||||
@foreach (var item in selection.OrderBy(x => x.Level))
|
||||
{
|
||||
<li><a href="@item.Url">@item.Name</a> »</li>
|
||||
<li><a href="@item.Url()">@item.Name</a> »</li>
|
||||
}
|
||||
|
||||
@* Display the current page as the last item in the list *@
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
@foreach (var item in selection)
|
||||
{
|
||||
<li class="@(item.IsAncestorOrSelf(Model.Content) ? "current" : null)">
|
||||
<a href="@item.Url">@item.Name</a>
|
||||
<a href="@item.Url()">@item.Name</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
@foreach (var item in selection)
|
||||
{
|
||||
<li class="level-@item.Level">
|
||||
<a href="@item.Url">@item.Name</a>
|
||||
<a href="@item.Url()">@item.Name</a>
|
||||
|
||||
@* Run the traverse helper again for any child pages *@
|
||||
@Traverse(item)
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
redirectUrl = Url.Action("AuthorizeUpgrade", "BackOffice")
|
||||
});
|
||||
}
|
||||
@Html.BareMinimumServerVariablesScript(Url, externalLoginUrl, Model.Features, Model.GlobalSettings, Model.UmbracoVersion, Model.UmbracoSettingsSection)
|
||||
@Html.BareMinimumServerVariablesScript(Url, externalLoginUrl, Model.Features, Model.GlobalSettings, Model.UmbracoVersion, Model.UmbracoSettingsSection, Model.IOHelper, Model.TreeCollection)
|
||||
|
||||
<script type="text/javascript">
|
||||
document.angularReady = function (app) {
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
on-login="hideLoginScreen()">
|
||||
</umb-login>
|
||||
|
||||
@Html.BareMinimumServerVariablesScript(Url, Url.Action("ExternalLogin", "BackOffice", new { area = ViewData.GetUmbracoPath() }), Model.Features, Current.Configs.Global(), Model.UmbracoVersion, Current.Configs.Settings())
|
||||
@Html.BareMinimumServerVariablesScript(Url, Url.Action("ExternalLogin", "BackOffice", new { area = ViewData.GetUmbracoPath() }), Model.Features, Model.GlobalSettings, Model.UmbracoVersion, Model.UmbracoSettingsSection, Model.IOHelper, Model.TreeCollection)
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.AspNet.SignalR;
|
||||
using Microsoft.Owin.Logging;
|
||||
using Owin;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Logging;
|
||||
|
||||
@@ -43,9 +44,10 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
/// <param name="app">The app builder.</param>
|
||||
/// <param name="globalSettings"></param>
|
||||
public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings)
|
||||
/// <param name="ioHelper"></param>
|
||||
public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.IOHelper);
|
||||
var umbracoPath = globalSettings.GetUmbracoMvcArea(ioHelper);
|
||||
var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr";
|
||||
return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true });
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ using Microsoft.AspNet.Identity.Owin;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -24,11 +23,11 @@ using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Web.Composing;
|
||||
using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Web.Models.Identity;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -44,13 +43,17 @@ namespace Umbraco.Web.Editors
|
||||
private BackOfficeUserManager<BackOfficeIdentityUser> _userManager;
|
||||
private BackOfficeSignInManager _signInManager;
|
||||
private readonly IUserPasswordConfiguration _passwordConfiguration;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public AuthenticationController(IUserPasswordConfiguration passwordConfiguration, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, IUmbracoSettingsSection umbracoSettingsSection)
|
||||
public AuthenticationController(IUserPasswordConfiguration passwordConfiguration, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper)
|
||||
{
|
||||
_passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration));
|
||||
_runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState));
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
}
|
||||
|
||||
protected BackOfficeUserManager<BackOfficeIdentityUser> UserManager => _userManager
|
||||
@@ -518,13 +521,13 @@ namespace Umbraco.Web.Editors
|
||||
var action = urlHelper.Action("ValidatePasswordResetCode", "BackOffice",
|
||||
new
|
||||
{
|
||||
area = GlobalSettings.GetUmbracoMvcArea(Current.IOHelper),
|
||||
area = GlobalSettings.GetUmbracoMvcArea(_ioHelper),
|
||||
u = userId,
|
||||
r = code
|
||||
});
|
||||
|
||||
// Construct full URL using configured application URL (which will fall back to request)
|
||||
var applicationUri = Current.RuntimeState.ApplicationUrl;
|
||||
var applicationUri = _runtimeState.ApplicationUrl;
|
||||
var callbackUri = new Uri(applicationUri, action);
|
||||
return callbackUri.ToString();
|
||||
}
|
||||
|
||||
@@ -16,11 +16,9 @@ using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.JavaScript;
|
||||
using Umbraco.Web.Models.Identity;
|
||||
@@ -29,6 +27,8 @@ using Constants = Umbraco.Core.Constants;
|
||||
using JArray = Newtonsoft.Json.Linq.JArray;
|
||||
using Umbraco.Core.Configuration.Grid;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Trees;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -48,8 +48,24 @@ namespace Umbraco.Web.Editors
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IGridConfig _gridConfig;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly TreeCollection _treeCollection;
|
||||
|
||||
public BackOfficeController(IManifestParser manifestParser, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, IUmbracoVersion umbracoVersion, IGridConfig gridConfig, IUmbracoSettingsSection umbracoSettingsSection)
|
||||
public BackOfficeController(
|
||||
IManifestParser manifestParser,
|
||||
UmbracoFeatures features,
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger profilingLogger,
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoHelper umbracoHelper,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IGridConfig gridConfig,
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper,
|
||||
TreeCollection treeCollection)
|
||||
: base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger, umbracoHelper)
|
||||
{
|
||||
_manifestParser = manifestParser;
|
||||
@@ -58,6 +74,8 @@ namespace Umbraco.Web.Editors
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_gridConfig = gridConfig ?? throw new ArgumentNullException(nameof(gridConfig));
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection));
|
||||
}
|
||||
|
||||
protected BackOfficeSignInManager SignInManager => _signInManager ?? (_signInManager = OwinContext.GetBackOfficeSignInManager());
|
||||
@@ -73,8 +91,8 @@ namespace Umbraco.Web.Editors
|
||||
public async Task<ActionResult> Default()
|
||||
{
|
||||
return await RenderDefaultOrProcessExternalLoginAsync(
|
||||
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection)),
|
||||
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection)));
|
||||
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection,_ioHelper, _treeCollection)),
|
||||
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection, _ioHelper, _treeCollection)));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -157,7 +175,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
return await RenderDefaultOrProcessExternalLoginAsync(
|
||||
//The default view to render when there is no external login info or errors
|
||||
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/AuthorizeUpgrade.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection)),
|
||||
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/AuthorizeUpgrade.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection, _ioHelper, _treeCollection)),
|
||||
//The ActionResult to perform if external login is successful
|
||||
() => Redirect("/"));
|
||||
}
|
||||
@@ -212,7 +230,7 @@ namespace Umbraco.Web.Editors
|
||||
var initCss = new CssInitialization(_manifestParser);
|
||||
|
||||
var files = initJs.OptimizeBackOfficeScriptFiles(HttpContext, JsInitialization.GetDefaultInitialization());
|
||||
var result = JsInitialization.GetJavascriptInitialization(HttpContext, files, "umbraco", GlobalSettings);
|
||||
var result = JsInitialization.GetJavascriptInitialization(HttpContext, files, "umbraco", GlobalSettings, _ioHelper);
|
||||
result += initCss.GetStylesheetInitialization(HttpContext);
|
||||
|
||||
return JavaScript(result);
|
||||
@@ -264,7 +282,7 @@ namespace Umbraco.Web.Editors
|
||||
[MinifyJavaScriptResult(Order = 1)]
|
||||
public JavaScriptResult ServerVariables()
|
||||
{
|
||||
var serverVars = new BackOfficeServerVariables(Url, _runtimeState, _features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection);
|
||||
var serverVars = new BackOfficeServerVariables(Url, _runtimeState, _features, GlobalSettings, _umbracoVersion, _umbracoSettingsSection, _ioHelper, _treeCollection);
|
||||
|
||||
//cache the result if debugging is disabled
|
||||
var result = HttpContext.IsDebuggingEnabled
|
||||
@@ -358,7 +376,7 @@ namespace Umbraco.Web.Editors
|
||||
if (defaultResponse == null) throw new ArgumentNullException("defaultResponse");
|
||||
if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse");
|
||||
|
||||
ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(Current.IOHelper));
|
||||
ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(_ioHelper));
|
||||
|
||||
//check if there is the TempData with the any token name specified, if so, assign to view bag and render the view
|
||||
if (ViewData.FromTempData(TempData, ViewDataExtensions.TokenExternalSignInError) ||
|
||||
|
||||
@@ -1,23 +1,29 @@
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.Trees;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
|
||||
public class BackOfficeModel
|
||||
{
|
||||
public BackOfficeModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoSettingsSection umbracoSettingsSection)
|
||||
public BackOfficeModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, TreeCollection treeCollection)
|
||||
{
|
||||
Features = features;
|
||||
GlobalSettings = globalSettings;
|
||||
UmbracoVersion = umbracoVersion;
|
||||
UmbracoSettingsSection = umbracoSettingsSection;
|
||||
IOHelper = ioHelper;
|
||||
TreeCollection = treeCollection;
|
||||
}
|
||||
|
||||
public UmbracoFeatures Features { get; }
|
||||
public IGlobalSettings GlobalSettings { get; }
|
||||
public IUmbracoVersion UmbracoVersion { get; }
|
||||
public IUmbracoSettingsSection UmbracoSettingsSection { get; }
|
||||
public IIOHelper IOHelper { get; }
|
||||
public TreeCollection TreeCollection { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.Trees;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -11,7 +13,8 @@ namespace Umbraco.Web.Editors
|
||||
private readonly UmbracoFeatures _features;
|
||||
public IEnumerable<ILanguage> Languages { get; }
|
||||
|
||||
public BackOfficePreviewModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IEnumerable<ILanguage> languages, IUmbracoSettingsSection umbracoSettingsSection) : base(features, globalSettings, umbracoVersion, umbracoSettingsSection)
|
||||
public BackOfficePreviewModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IEnumerable<ILanguage> languages, IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, TreeCollection treeCollection)
|
||||
: base(features, globalSettings, umbracoVersion, umbracoSettingsSection, ioHelper, treeCollection)
|
||||
{
|
||||
_features = features;
|
||||
Languages = languages;
|
||||
|
||||
@@ -11,7 +11,6 @@ using ClientDependency.Core.Config;
|
||||
using Microsoft.Owin;
|
||||
using Microsoft.Owin.Security;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.HealthCheck;
|
||||
@@ -22,6 +21,7 @@ using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.Trees;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -38,8 +38,10 @@ namespace Umbraco.Web.Editors
|
||||
private readonly IOwinContext _owinContext;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly TreeCollection _treeCollection;
|
||||
|
||||
internal BackOfficeServerVariables(UrlHelper urlHelper, IRuntimeState runtimeState, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoSettingsSection umbracoSettingsSection)
|
||||
internal BackOfficeServerVariables(UrlHelper urlHelper, IRuntimeState runtimeState, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, TreeCollection treeCollection)
|
||||
{
|
||||
_urlHelper = urlHelper;
|
||||
_runtimeState = runtimeState;
|
||||
@@ -49,6 +51,8 @@ namespace Umbraco.Web.Editors
|
||||
_owinContext = _httpContext.GetOwinContext();
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -323,8 +327,8 @@ namespace Umbraco.Web.Editors
|
||||
"umbracoSettings", new Dictionary<string, object>
|
||||
{
|
||||
{"umbracoPath", _globalSettings.Path},
|
||||
{"mediaPath", Current.IOHelper.ResolveUrl(globalSettings.UmbracoMediaPath).TrimEnd('/')},
|
||||
{"appPluginsPath", Current.IOHelper.ResolveUrl(Constants.SystemDirectories.AppPlugins).TrimEnd('/')},
|
||||
{"mediaPath", _ioHelper.ResolveUrl(globalSettings.UmbracoMediaPath).TrimEnd('/')},
|
||||
{"appPluginsPath", _ioHelper.ResolveUrl(Constants.SystemDirectories.AppPlugins).TrimEnd('/')},
|
||||
{
|
||||
"imageFileTypes",
|
||||
string.Join(",", _umbracoSettingsSection.Content.ImageFileTypes)
|
||||
@@ -343,7 +347,7 @@ namespace Umbraco.Web.Editors
|
||||
},
|
||||
{"keepUserLoggedIn", _umbracoSettingsSection.Security.KeepUserLoggedIn},
|
||||
{"usernameIsEmail", _umbracoSettingsSection.Security.UsernameIsEmail},
|
||||
{"cssPath", Current.IOHelper.ResolveUrl(globalSettings.UmbracoCssPath).TrimEnd('/')},
|
||||
{"cssPath", _ioHelper.ResolveUrl(globalSettings.UmbracoCssPath).TrimEnd('/')},
|
||||
{"allowPasswordReset", _umbracoSettingsSection.Security.AllowPasswordReset},
|
||||
{"loginBackgroundImage", _umbracoSettingsSection.Content.LoginBackgroundImage},
|
||||
{"showUserInvite", EmailSender.CanSendRequiredEmail(globalSettings)},
|
||||
@@ -416,9 +420,8 @@ namespace Umbraco.Web.Editors
|
||||
//
|
||||
// do this instead
|
||||
// inheriting from TreeControllerBase and marked with TreeAttribute
|
||||
var trees = Current.Factory.GetInstance<TreeCollection>();
|
||||
|
||||
foreach (var tree in trees)
|
||||
foreach (var tree in _treeCollection)
|
||||
{
|
||||
var treeType = tree.TreeControllerType;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Strings.Css;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
@@ -35,6 +34,9 @@ namespace Umbraco.Web.Editors
|
||||
[UmbracoApplicationAuthorize(Core.Constants.Applications.Settings)]
|
||||
public class CodeFileController : BackOfficeNotificationsController
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IFileSystems _fileSystems;
|
||||
|
||||
public CodeFileController(
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
@@ -45,9 +47,13 @@ namespace Umbraco.Web.Editors
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoHelper umbracoHelper,
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper)
|
||||
UmbracoMapper umbracoMapper,
|
||||
IIOHelper ioHelper,
|
||||
IFileSystems fileSystems)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
_fileSystems = fileSystems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -517,7 +523,7 @@ namespace Umbraco.Web.Editors
|
||||
/// </remarks>
|
||||
private IScript CreateOrUpdateScript(CodeFileDisplay display)
|
||||
{
|
||||
return CreateOrUpdateFile(display, ".js", Current.FileSystems.ScriptsFileSystem,
|
||||
return CreateOrUpdateFile(display, ".js", _fileSystems.ScriptsFileSystem,
|
||||
name => Services.FileService.GetScriptByName(name),
|
||||
(script, userId) => Services.FileService.SaveScript(script, userId),
|
||||
name => new Script(name));
|
||||
@@ -525,7 +531,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
private IStylesheet CreateOrUpdateStylesheet(CodeFileDisplay display)
|
||||
{
|
||||
return CreateOrUpdateFile(display, ".css", Current.FileSystems.StylesheetsFileSystem,
|
||||
return CreateOrUpdateFile(display, ".css", _fileSystems.StylesheetsFileSystem,
|
||||
name => Services.FileService.GetStylesheetByName(name),
|
||||
(stylesheet, userId) => Services.FileService.SaveStylesheet(stylesheet, userId),
|
||||
name => new Stylesheet(name)
|
||||
@@ -647,7 +653,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
private bool IsDirectory(string virtualPath, string systemDirectory)
|
||||
{
|
||||
var path = Current.IOHelper.MapPath(systemDirectory + "/" + virtualPath);
|
||||
var path = _ioHelper.MapPath(systemDirectory + "/" + virtualPath);
|
||||
var dirInfo = new DirectoryInfo(path);
|
||||
return dirInfo.Attributes == FileAttributes.Directory;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
@@ -50,6 +50,7 @@ namespace Umbraco.Web.Editors
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly PropertyEditorCollection _propertyEditors;
|
||||
private readonly IScopeProvider _scopeProvider;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public ContentTypeController(IEntityXmlSerializer serializer,
|
||||
ICultureDictionary cultureDictionary,
|
||||
@@ -59,13 +60,14 @@ namespace Umbraco.Web.Editors
|
||||
ServiceContext services, AppCaches appCaches,
|
||||
IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper,
|
||||
IScopeProvider scopeProvider,
|
||||
IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper)
|
||||
IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper, IIOHelper ioHelper)
|
||||
: base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_globalSettings = globalSettings;
|
||||
_propertyEditors = propertyEditors;
|
||||
_scopeProvider = scopeProvider;
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public int GetCount()
|
||||
@@ -524,7 +526,7 @@ namespace Umbraco.Web.Editors
|
||||
[HttpPost]
|
||||
public HttpResponseMessage Import(string file)
|
||||
{
|
||||
var filePath = Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Data), file);
|
||||
var filePath = Path.Combine(_ioHelper.MapPath(Core.Constants.SystemDirectories.Data), file);
|
||||
if (string.IsNullOrEmpty(file) || !System.IO.File.Exists(filePath))
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.NotFound);
|
||||
@@ -562,7 +564,7 @@ namespace Umbraco.Web.Editors
|
||||
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
||||
}
|
||||
|
||||
var root = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "FileUploads");
|
||||
var root = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "FileUploads");
|
||||
//ensure it exists
|
||||
Directory.CreateDirectory(root);
|
||||
var provider = new MultipartFormDataStreamProvider(root);
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
private readonly IMediaFileSystem _mediaFileSystem;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public CurrentUserController(
|
||||
IGlobalSettings globalSettings,
|
||||
@@ -46,11 +47,13 @@ namespace Umbraco.Web.Editors
|
||||
IMediaFileSystem mediaFileSystem,
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IUmbracoSettingsSection umbracoSettingsSection)
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_mediaFileSystem = mediaFileSystem;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -184,7 +187,7 @@ namespace Umbraco.Web.Editors
|
||||
public async Task<HttpResponseMessage> PostSetAvatar()
|
||||
{
|
||||
//borrow the logic from the user controller
|
||||
return await UsersController.PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _umbracoSettingsSection, Security.GetUserId().ResultOr(0));
|
||||
return await UsersController.PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _umbracoSettingsSection, _ioHelper, Security.GetUserId().ResultOr(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,7 +13,6 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
@@ -21,6 +20,8 @@ using Umbraco.Web.WebApi.Filters;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
using Umbraco.Core.Mapping;
|
||||
using System.Web.Http.Controllers;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -33,11 +34,27 @@ namespace Umbraco.Web.Editors
|
||||
[MacrosControllerConfiguration]
|
||||
public class MacrosController : BackOfficeNotificationsController
|
||||
{
|
||||
private readonly ParameterEditorCollection _parameterEditorCollection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IMacroService _macroService;
|
||||
|
||||
public MacrosController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper)
|
||||
public MacrosController(
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISqlContext sqlContext,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger logger,
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoHelper umbracoHelper,
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
ParameterEditorCollection parameterEditorCollection,
|
||||
IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_parameterEditorCollection = parameterEditorCollection;
|
||||
_ioHelper = ioHelper;
|
||||
_macroService = Services.MacroService;
|
||||
}
|
||||
|
||||
@@ -246,7 +263,7 @@ namespace Umbraco.Web.Editors
|
||||
/// </returns>
|
||||
public HttpResponseMessage GetParameterEditors()
|
||||
{
|
||||
return this.Request.CreateResponse(HttpStatusCode.OK, Current.ParameterEditors);
|
||||
return this.Request.CreateResponse(HttpStatusCode.OK, _parameterEditorCollection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -257,7 +274,7 @@ namespace Umbraco.Web.Editors
|
||||
/// </returns>
|
||||
public HttpResponseMessage GetGroupedParameterEditors()
|
||||
{
|
||||
var parameterEditors = Current.ParameterEditors.ToArray();
|
||||
var parameterEditors = _parameterEditorCollection.ToArray();
|
||||
|
||||
var grouped = parameterEditors
|
||||
.GroupBy(x => x.Group.IsNullOrWhiteSpace() ? "" : x.Group.ToLower())
|
||||
@@ -275,7 +292,7 @@ namespace Umbraco.Web.Editors
|
||||
/// </returns>
|
||||
public HttpResponseMessage GetParameterEditorByAlias(string alias)
|
||||
{
|
||||
var parameterEditors = Current.ParameterEditors.ToArray();
|
||||
var parameterEditors = _parameterEditorCollection.ToArray();
|
||||
|
||||
var parameterEditor = parameterEditors.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
|
||||
|
||||
@@ -331,7 +348,7 @@ namespace Umbraco.Web.Editors
|
||||
/// </returns>
|
||||
private IEnumerable<string> FindPartialViewFilesInViewsFolder()
|
||||
{
|
||||
var partialsDir = Current.IOHelper.MapPath(Constants.SystemDirectories.MacroPartials);
|
||||
var partialsDir = _ioHelper.MapPath(Constants.SystemDirectories.MacroPartials);
|
||||
|
||||
return this.FindPartialViewFilesInFolder(
|
||||
partialsDir,
|
||||
@@ -348,7 +365,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
var files = new List<string>();
|
||||
|
||||
var appPluginsFolder = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.AppPlugins));
|
||||
var appPluginsFolder = new DirectoryInfo(_ioHelper.MapPath(Constants.SystemDirectories.AppPlugins));
|
||||
|
||||
if (!appPluginsFolder.Exists)
|
||||
{
|
||||
|
||||
@@ -19,35 +19,23 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using System.Linq;
|
||||
using System.Web.Http.Controllers;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.ContentEditing;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Models.Validation;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.ContentApps;
|
||||
using Umbraco.Web.Editors.Binders;
|
||||
using Umbraco.Web.Editors.Filters;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Mapping;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
@@ -62,6 +50,7 @@ namespace Umbraco.Web.Editors
|
||||
public class MediaController : ContentControllerBase
|
||||
{
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public MediaController(
|
||||
ICultureDictionary cultureDictionary,
|
||||
@@ -77,12 +66,14 @@ namespace Umbraco.Web.Editors
|
||||
IMediaFileSystem mediaFileSystem,
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IUmbracoSettingsSection umbracoSettingsSection)
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper)
|
||||
: base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors));
|
||||
_mediaFileSystem = mediaFileSystem;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -653,7 +644,7 @@ namespace Umbraco.Web.Editors
|
||||
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
||||
}
|
||||
|
||||
var root = Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
var root = _ioHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
//ensure it exists
|
||||
Directory.CreateDirectory(root);
|
||||
var provider = new MultipartFormDataStreamProvider(root);
|
||||
|
||||
@@ -8,8 +8,16 @@ using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using Semver;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
@@ -24,6 +32,25 @@ namespace Umbraco.Web.Editors
|
||||
[UmbracoApplicationAuthorize(Core.Constants.Applications.Packages)]
|
||||
public class PackageController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public PackageController(
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISqlContext sqlContext,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger logger,
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoHelper umbracoHelper,
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public IEnumerable<PackageDefinition> GetCreatedPackages()
|
||||
{
|
||||
return Services.PackagingService.GetAllCreatedPackages();
|
||||
@@ -88,7 +115,7 @@ namespace Umbraco.Web.Editors
|
||||
if (package == null)
|
||||
return Request.CreateResponse(HttpStatusCode.NotFound);
|
||||
|
||||
var fullPath = Current.IOHelper.MapPath(package.PackagePath);
|
||||
var fullPath = _ioHelper.MapPath(package.PackagePath);
|
||||
if (!File.Exists(fullPath))
|
||||
return Request.CreateNotificationValidationErrorResponse("No file found for path " + package.PackagePath);
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ using System.Web.Http;
|
||||
using Semver;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
@@ -37,13 +37,25 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
public PackageInstallController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISqlContext sqlContext, ServiceContext services, AppCaches appCaches,
|
||||
IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, IShortStringHelper shortStringHelper, IUmbracoVersion umbracoVersion, UmbracoMapper umbracoMapper)
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public PackageInstallController(
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISqlContext sqlContext,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger logger,
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoHelper umbracoHelper,
|
||||
IShortStringHelper shortStringHelper,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_umbracoVersion = umbracoVersion;
|
||||
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,7 +106,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
private void PopulateFromPackageData(LocalPackageInstallModel model)
|
||||
{
|
||||
var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), model.ZipFileName));
|
||||
var zipFile = new FileInfo(Path.Combine(_ioHelper.MapPath(Core.Constants.SystemDirectories.Packages), model.ZipFileName));
|
||||
|
||||
var ins = Services.PackagingService.GetCompiledPackageInfo(zipFile);
|
||||
|
||||
@@ -136,7 +148,7 @@ namespace Umbraco.Web.Editors
|
||||
if (Request.Content.IsMimeMultipartContent() == false)
|
||||
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
||||
|
||||
var root = Current.IOHelper.MapPath(Core.Constants.SystemDirectories.TempFileUploads);
|
||||
var root = _ioHelper.MapPath(Core.Constants.SystemDirectories.TempFileUploads);
|
||||
//ensure it exists
|
||||
Directory.CreateDirectory(root);
|
||||
var provider = new MultipartFormDataStreamProvider(root);
|
||||
@@ -163,7 +175,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
//we always save package files to /App_Data/packages/package-guid.umb for processing as a standard so lets copy.
|
||||
|
||||
var packagesFolder = Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages);
|
||||
var packagesFolder = _ioHelper.MapPath(Core.Constants.SystemDirectories.Packages);
|
||||
Directory.CreateDirectory(packagesFolder);
|
||||
var packageFile = Path.Combine(packagesFolder, model.PackageGuid + ".umb");
|
||||
File.Copy(file.LocalFileName, packageFile);
|
||||
@@ -215,7 +227,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
//Default path
|
||||
string fileName = packageGuid + ".umb";
|
||||
if (File.Exists(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), fileName)) == false)
|
||||
if (File.Exists(Path.Combine(_ioHelper.MapPath(Core.Constants.SystemDirectories.Packages), fileName)) == false)
|
||||
{
|
||||
var packageFile = await Services.PackagingService.FetchPackageFileAsync(
|
||||
Guid.Parse(packageGuid),
|
||||
@@ -255,7 +267,7 @@ namespace Umbraco.Web.Editors
|
||||
[HttpPost]
|
||||
public PackageInstallModel Import(PackageInstallModel model)
|
||||
{
|
||||
var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), model.ZipFileName));
|
||||
var zipFile = new FileInfo(Path.Combine(_ioHelper.MapPath(Core.Constants.SystemDirectories.Packages), model.ZipFileName));
|
||||
|
||||
var packageInfo = Services.PackagingService.GetCompiledPackageInfo(zipFile);
|
||||
|
||||
@@ -368,7 +380,7 @@ namespace Umbraco.Web.Editors
|
||||
zipFile.Delete();
|
||||
|
||||
//bump cdf to be safe
|
||||
var clientDependencyConfig = new ClientDependencyConfiguration(Logger);
|
||||
var clientDependencyConfig = new ClientDependencyConfiguration(Logger, _ioHelper);
|
||||
var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumber(
|
||||
_umbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd");
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Web.UI;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Features;
|
||||
@@ -13,6 +14,7 @@ using Umbraco.Web.JavaScript;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Trees;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
@@ -27,6 +29,8 @@ namespace Umbraco.Web.Editors
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly TreeCollection _treeCollection;
|
||||
|
||||
public PreviewController(
|
||||
UmbracoFeatures features,
|
||||
@@ -35,7 +39,9 @@ namespace Umbraco.Web.Editors
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ILocalizationService localizationService,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IUmbracoSettingsSection umbracoSettingsSection)
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper,
|
||||
TreeCollection treeCollection)
|
||||
{
|
||||
_features = features;
|
||||
_globalSettings = globalSettings;
|
||||
@@ -44,6 +50,8 @@ namespace Umbraco.Web.Editors
|
||||
_localizationService = localizationService;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_treeCollection = treeCollection;
|
||||
}
|
||||
|
||||
[UmbracoAuthorize(redirectToUmbracoLogin: true)]
|
||||
@@ -52,7 +60,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
var availableLanguages = _localizationService.GetAllLanguages();
|
||||
|
||||
var model = new BackOfficePreviewModel(_features, _globalSettings, _umbracoVersion, availableLanguages, _umbracoSettingsSection);
|
||||
var model = new BackOfficePreviewModel(_features, _globalSettings, _umbracoVersion, availableLanguages, _umbracoSettingsSection, _ioHelper, _treeCollection);
|
||||
|
||||
if (model.PreviewExtendedHeaderView.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -75,7 +83,7 @@ namespace Umbraco.Web.Editors
|
||||
public JavaScriptResult Application()
|
||||
{
|
||||
var files = JsInitialization.OptimizeScriptFiles(HttpContext, JsInitialization.GetPreviewInitialization());
|
||||
var result = JsInitialization.GetJavascriptInitialization(HttpContext, files, "umbraco.preview", _globalSettings);
|
||||
var result = JsInitialization.GetJavascriptInitialization(HttpContext, files, "umbraco.preview", _globalSettings, _ioHelper);
|
||||
|
||||
return JavaScript(result);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,15 @@ using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
@@ -25,19 +29,31 @@ namespace Umbraco.Web.Editors
|
||||
Constants.Applications.Members)]
|
||||
public class TinyMceController : UmbracoAuthorizedApiController
|
||||
{
|
||||
private readonly IMediaService _mediaService;
|
||||
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
|
||||
public TinyMceController(IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IShortStringHelper shortStringHelper, IUmbracoSettingsSection umbracoSettingsSection)
|
||||
public TinyMceController(
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISqlContext sqlContext,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger logger,
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoHelper umbracoHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IShortStringHelper shortStringHelper,
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper)
|
||||
{
|
||||
_mediaService = mediaService;
|
||||
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<HttpResponseMessage> UploadImage()
|
||||
{
|
||||
@@ -47,10 +63,10 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
|
||||
// Create an unique folder path to help with concurrent users to avoid filename clash
|
||||
var imageTempPath = Current.IOHelper.MapPath(Constants.SystemDirectories.TempImageUploads + "/" + Guid.NewGuid().ToString());
|
||||
var imageTempPath = _ioHelper.MapPath(Constants.SystemDirectories.TempImageUploads + "/" + Guid.NewGuid().ToString());
|
||||
|
||||
// Temp folderpath (Files come in as bodypart & will need to move/saved into imgTempPath
|
||||
var folderPath = Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
var folderPath = _ioHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
|
||||
// Ensure image temp path exists
|
||||
if(Directory.Exists(imageTempPath) == false)
|
||||
@@ -88,8 +104,8 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
//var mediaItemName = fileName.ToFriendlyName();
|
||||
var currentFile = file.LocalFileName;
|
||||
var newFilePath = imageTempPath + Current.IOHelper.DirSepChar + safeFileName;
|
||||
var relativeNewFilePath = Current.IOHelper.GetRelativePath(newFilePath);
|
||||
var newFilePath = imageTempPath + _ioHelper.DirSepChar + safeFileName;
|
||||
var relativeNewFilePath = _ioHelper.GetRelativePath(newFilePath);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -4,8 +4,15 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.Tour;
|
||||
@@ -17,11 +24,27 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
private readonly TourFilterCollection _filters;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public TourController(TourFilterCollection filters, IUmbracoSettingsSection umbracoSettingsSection)
|
||||
public TourController(
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISqlContext sqlContext,
|
||||
ServiceContext services,
|
||||
AppCaches appCaches,
|
||||
IProfilingLogger logger,
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoHelper umbracoHelper,
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
TourFilterCollection filters,
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_filters = filters;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public IEnumerable<BackOfficeTourFile> GetTours()
|
||||
@@ -42,7 +65,7 @@ namespace Umbraco.Web.Editors
|
||||
var nonPluginFilters = _filters.Where(x => x.PluginName == null).ToList();
|
||||
|
||||
//add core tour files
|
||||
var coreToursPath = Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Config), "BackOfficeTours");
|
||||
var coreToursPath = Path.Combine(_ioHelper.MapPath(Core.Constants.SystemDirectories.Config), "BackOfficeTours");
|
||||
if (Directory.Exists(coreToursPath))
|
||||
{
|
||||
foreach (var tourFile in Directory.EnumerateFiles(coreToursPath, "*.json"))
|
||||
@@ -52,7 +75,7 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
|
||||
//collect all tour files in packages
|
||||
var appPlugins = Current.IOHelper.MapPath(Core.Constants.SystemDirectories.AppPlugins);
|
||||
var appPlugins = _ioHelper.MapPath(Core.Constants.SystemDirectories.AppPlugins);
|
||||
if (Directory.Exists(appPlugins))
|
||||
{
|
||||
foreach (var plugin in Directory.EnumerateDirectories(appPlugins))
|
||||
|
||||
@@ -13,13 +13,11 @@ using System.Web.Mvc;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Security;
|
||||
@@ -48,6 +46,8 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
private readonly IMediaFileSystem _mediaFileSystem;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly ISqlContext _sqlContext;
|
||||
|
||||
public UsersController(
|
||||
IGlobalSettings globalSettings,
|
||||
@@ -61,11 +61,14 @@ namespace Umbraco.Web.Editors
|
||||
IMediaFileSystem mediaFileSystem,
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IUmbracoSettingsSection umbracoSettingsSection)
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
|
||||
{
|
||||
_mediaFileSystem = mediaFileSystem;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper;
|
||||
_sqlContext = sqlContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,17 +89,17 @@ namespace Umbraco.Web.Editors
|
||||
[AdminUsersAuthorize]
|
||||
public async Task<HttpResponseMessage> PostSetAvatar(int id)
|
||||
{
|
||||
return await PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _umbracoSettingsSection, id);
|
||||
return await PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _umbracoSettingsSection, _ioHelper, id);
|
||||
}
|
||||
|
||||
internal static async Task<HttpResponseMessage> PostSetAvatarInternal(HttpRequestMessage request, IUserService userService, IAppCache cache, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IUmbracoSettingsSection umbracoSettingsSection, int id)
|
||||
internal static async Task<HttpResponseMessage> PostSetAvatarInternal(HttpRequestMessage request, IUserService userService, IAppCache cache, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, int id)
|
||||
{
|
||||
if (request.Content.IsMimeMultipartContent() == false)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
||||
}
|
||||
|
||||
var root = Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
var root = ioHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
//ensure it exists
|
||||
Directory.CreateDirectory(root);
|
||||
var provider = new MultipartFormDataStreamProvider(root);
|
||||
@@ -131,7 +134,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
using (var fs = System.IO.File.OpenRead(file.LocalFileName))
|
||||
{
|
||||
Current.MediaFileSystem.AddFile(user.Avatar, fs, true);
|
||||
mediaFileSystem.AddFile(user.Avatar, fs, true);
|
||||
}
|
||||
|
||||
userService.Save(user);
|
||||
@@ -173,8 +176,8 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
if (filePath.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
if (Current.MediaFileSystem.FileExists(filePath))
|
||||
Current.MediaFileSystem.DeleteFile(filePath);
|
||||
if (_mediaFileSystem.FileExists(filePath))
|
||||
_mediaFileSystem.DeleteFile(filePath);
|
||||
}
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, found.GetUserAvatarUrls(AppCaches.RuntimeCache, _mediaFileSystem));
|
||||
@@ -232,7 +235,7 @@ namespace Umbraco.Web.Editors
|
||||
excludeUserGroups = new[] {Constants.Security.AdminGroupAlias};
|
||||
}
|
||||
|
||||
var filterQuery = Current.SqlContext.Query<IUser>();
|
||||
var filterQuery = _sqlContext.Query<IUser>();
|
||||
|
||||
if (!Security.CurrentUser.IsSuper())
|
||||
{
|
||||
@@ -477,7 +480,7 @@ namespace Umbraco.Web.Editors
|
||||
var action = urlHelper.Action("VerifyInvite", "BackOffice",
|
||||
new
|
||||
{
|
||||
area = GlobalSettings.GetUmbracoMvcArea(Current.IOHelper),
|
||||
area = GlobalSettings.GetUmbracoMvcArea(_ioHelper),
|
||||
invite = inviteToken
|
||||
});
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Microsoft.Owin.Security;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Trees;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
@@ -37,9 +39,9 @@ namespace Umbraco.Web
|
||||
/// These are the bare minimal server variables that are required for the application to start without being authenticated,
|
||||
/// we will load the rest of the server vars after the user is authenticated.
|
||||
/// </remarks>
|
||||
public static IHtmlString BareMinimumServerVariablesScript(this HtmlHelper html, UrlHelper uri, string externalLoginsUrl, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoSettingsSection umbracoSettingsSection)
|
||||
public static IHtmlString BareMinimumServerVariablesScript(this HtmlHelper html, UrlHelper uri, string externalLoginsUrl, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, TreeCollection treeCollection)
|
||||
{
|
||||
var serverVars = new BackOfficeServerVariables(uri, Current.RuntimeState, features, globalSettings, umbracoVersion, umbracoSettingsSection);
|
||||
var serverVars = new BackOfficeServerVariables(uri, Current.RuntimeState, features, globalSettings, umbracoVersion, umbracoSettingsSection, ioHelper, treeCollection);
|
||||
var minVars = serverVars.BareMinimumServerVariables();
|
||||
|
||||
var str = @"<script type=""text/javascript"">
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.JavaScript;
|
||||
using Umbraco.Web.Mvc;
|
||||
@@ -25,8 +26,9 @@ namespace Umbraco.Web.Install.Controllers
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public InstallController(IUmbracoContextAccessor umbracoContextAccessor, InstallHelper installHelper, IRuntimeState runtime, ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion)
|
||||
public InstallController(IUmbracoContextAccessor umbracoContextAccessor, InstallHelper installHelper, IRuntimeState runtime, ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_installHelper = installHelper;
|
||||
@@ -34,6 +36,7 @@ namespace Umbraco.Web.Install.Controllers
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -46,7 +49,7 @@ namespace Umbraco.Web.Install.Controllers
|
||||
if (_runtime.Level == RuntimeLevel.Upgrade)
|
||||
{
|
||||
// Update ClientDependency version
|
||||
var clientDependencyConfig = new ClientDependencyConfiguration(_logger);
|
||||
var clientDependencyConfig = new ClientDependencyConfiguration(_logger, _ioHelper);
|
||||
var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumber(
|
||||
_umbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd");
|
||||
// Delete ClientDependency temp directories to make sure we get fresh caches
|
||||
@@ -66,7 +69,7 @@ namespace Umbraco.Web.Install.Controllers
|
||||
ViewData.SetInstallApiBaseUrl(Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup"));
|
||||
|
||||
// get the base umbraco folder
|
||||
ViewData.SetUmbracoBaseFolder(Current.IOHelper.ResolveUrl(_globalSettings.UmbracoPath));
|
||||
ViewData.SetUmbracoBaseFolder(_ioHelper.ResolveUrl(_globalSettings.UmbracoPath));
|
||||
|
||||
_installHelper.InstallStatus(false, "");
|
||||
|
||||
|
||||
@@ -20,10 +20,12 @@ namespace Umbraco.Web.Install
|
||||
// ensure Umbraco can write to these files (the directories must exist)
|
||||
private readonly string[] _permissionFiles = { };
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public FilePermissionHelper(IGlobalSettings globalSettings)
|
||||
public FilePermissionHelper(IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
_permissionDirs = new[] { _globalSettings.UmbracoCssPath, Constants.SystemDirectories.Config, Constants.SystemDirectories.Data, _globalSettings.UmbracoMediaPath, Constants.SystemDirectories.Preview };
|
||||
_packagesPermissionsDirs = new[] { Constants.SystemDirectories.Bin, _globalSettings.UmbracoPath, Constants.SystemDirectories.Packages };
|
||||
}
|
||||
@@ -138,7 +140,7 @@ namespace Umbraco.Web.Install
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Current.IOHelper.MapPath(dir + "/" + CreateRandomName());
|
||||
var path = _ioHelper.MapPath(dir + "/" + CreateRandomName());
|
||||
Directory.CreateDirectory(path);
|
||||
Directory.Delete(path);
|
||||
return true;
|
||||
@@ -156,7 +158,7 @@ namespace Umbraco.Web.Install
|
||||
{
|
||||
try
|
||||
{
|
||||
var dirPath = Current.IOHelper.MapPath(dir);
|
||||
var dirPath = _ioHelper.MapPath(dir);
|
||||
|
||||
if (Directory.Exists(dirPath) == false)
|
||||
Directory.CreateDirectory(dirPath);
|
||||
@@ -184,7 +186,7 @@ namespace Umbraco.Web.Install
|
||||
{
|
||||
try
|
||||
{
|
||||
var dirPath = Current.IOHelper.MapPath(dir);
|
||||
var dirPath = _ioHelper.MapPath(dir);
|
||||
|
||||
if (Directory.Exists(dirPath) == false)
|
||||
return true;
|
||||
@@ -249,7 +251,7 @@ namespace Umbraco.Web.Install
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Current.IOHelper.MapPath(file);
|
||||
var path = _ioHelper.MapPath(file);
|
||||
File.AppendText(path).Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Configuration;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
@@ -14,6 +14,13 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
PerformsAppRestart = true)]
|
||||
internal class ConfigureMachineKey : InstallSetupStep<bool?>
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public ConfigureMachineKey(IIOHelper ioHelper)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public override string View => HasMachineKey() == false ? base.View : "";
|
||||
|
||||
/// <summary>
|
||||
@@ -36,7 +43,7 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
if (model.HasValue && model.Value == false) return Task.FromResult<InstallSetupResult>(null);
|
||||
|
||||
//install the machine key
|
||||
var fileName = Current.IOHelper.MapPath($"{Current.IOHelper.Root}/web.config");
|
||||
var fileName = _ioHelper.MapPath($"{_ioHelper.Root}/web.config");
|
||||
var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace);
|
||||
|
||||
// we only want to get the element that is under the root, (there may be more under <location> tags we don't want them)
|
||||
|
||||
@@ -4,9 +4,9 @@ using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Migrations.Install;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
@@ -18,12 +18,14 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
private readonly DatabaseBuilder _databaseBuilder;
|
||||
private readonly IRuntimeState _runtime;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public DatabaseInstallStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger)
|
||||
public DatabaseInstallStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger, IIOHelper ioHelper)
|
||||
{
|
||||
_databaseBuilder = databaseBuilder;
|
||||
_runtime = runtime;
|
||||
_logger = logger;
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
@@ -40,7 +42,7 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
|
||||
if (result.RequiresUpgrade == false)
|
||||
{
|
||||
HandleConnectionStrings(_logger);
|
||||
HandleConnectionStrings(_logger, _ioHelper);
|
||||
return Task.FromResult<InstallSetupResult>(null);
|
||||
}
|
||||
|
||||
@@ -51,12 +53,12 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
}));
|
||||
}
|
||||
|
||||
internal static void HandleConnectionStrings(ILogger logger)
|
||||
internal static void HandleConnectionStrings(ILogger logger, IIOHelper ioHelper)
|
||||
{
|
||||
// Remove legacy umbracoDbDsn configuration setting if it exists and connectionstring also exists
|
||||
if (ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName] != null)
|
||||
{
|
||||
GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, Current.IOHelper);
|
||||
GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, ioHelper);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Migrations.Install;
|
||||
using Umbraco.Core.Migrations.Upgrade;
|
||||
@@ -22,8 +23,9 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IConnectionStrings _connectionStrings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public DatabaseUpgradeStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger, IUmbracoVersion umbracoVersion, IGlobalSettings globalSettings, IConnectionStrings connectionStrings)
|
||||
public DatabaseUpgradeStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger, IUmbracoVersion umbracoVersion, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, IIOHelper ioHelper)
|
||||
{
|
||||
_databaseBuilder = databaseBuilder;
|
||||
_runtime = runtime;
|
||||
@@ -31,6 +33,7 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_globalSettings = globalSettings;
|
||||
_connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings));
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
@@ -53,7 +56,7 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
throw new InstallException("The database failed to upgrade. ERROR: " + result.Message);
|
||||
}
|
||||
|
||||
DatabaseInstallStep.HandleConnectionStrings(_logger);
|
||||
DatabaseInstallStep.HandleConnectionStrings(_logger, _ioHelper);
|
||||
}
|
||||
|
||||
return Task.FromResult<InstallSetupResult>(null);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Cache;
|
||||
@@ -22,19 +23,21 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public SetUmbracoVersionStep(HttpContextBase httpContext, InstallHelper installHelper, IGlobalSettings globalSettings, IUserService userService, IUmbracoVersion umbracoVersion)
|
||||
public SetUmbracoVersionStep(HttpContextBase httpContext, InstallHelper installHelper, IGlobalSettings globalSettings, IUserService userService, IUmbracoVersion umbracoVersion, IIOHelper ioHelper)
|
||||
{
|
||||
_httpContext = httpContext;
|
||||
_installHelper = installHelper;
|
||||
_globalSettings = globalSettings;
|
||||
_userService = userService;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
var security = new WebSecurity(_httpContext, _userService, _globalSettings);
|
||||
var security = new WebSecurity(_httpContext, _userService, _globalSettings, _ioHelper);
|
||||
|
||||
if (security.IsAuthenticated() == false && _globalSettings.ConfigurationStatus.IsNullOrWhiteSpace())
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
@@ -12,6 +12,13 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
"StarterKitCleanup", 32, "Almost done")]
|
||||
internal class StarterKitCleanupStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public StarterKitCleanupStep(IIOHelper ioHelper)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
||||
@@ -26,7 +33,7 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
|
||||
private void CleanupInstallation(int packageId, string packageFile)
|
||||
{
|
||||
var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), HttpUtility.UrlDecode(packageFile)));
|
||||
var zipFile = new FileInfo(Path.Combine(_ioHelper.MapPath(Core.Constants.SystemDirectories.Packages), HttpUtility.UrlDecode(packageFile)));
|
||||
|
||||
if (zipFile.Exists)
|
||||
zipFile.Delete();
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Xml.Linq;
|
||||
using ClientDependency.Core.CompositeFiles.Providers;
|
||||
using ClientDependency.Core.Config;
|
||||
using Semver;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
@@ -22,11 +23,11 @@ namespace Umbraco.Web.JavaScript
|
||||
private readonly ILogger _logger;
|
||||
private readonly string _fileName;
|
||||
|
||||
public ClientDependencyConfiguration(ILogger logger)
|
||||
public ClientDependencyConfiguration(ILogger logger, IIOHelper ioHelper)
|
||||
{
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
_logger = logger;
|
||||
_fileName = Current.IOHelper.MapPath(string.Format("{0}/ClientDependency.config", Core.Constants.SystemDirectories.Config));
|
||||
_fileName = ioHelper.MapPath(string.Format("{0}/ClientDependency.config", Core.Constants.SystemDirectories.Config));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Web.JavaScript
|
||||
{
|
||||
@@ -43,7 +44,7 @@ namespace Umbraco.Web.JavaScript
|
||||
/// The angular module name to boot
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static string GetJavascriptInitialization(HttpContextBase httpContext, IEnumerable<string> scripts, string angularModule, IGlobalSettings globalSettings)
|
||||
public static string GetJavascriptInitialization(HttpContextBase httpContext, IEnumerable<string> scripts, string angularModule, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
var jarray = new StringBuilder();
|
||||
jarray.AppendLine("[");
|
||||
@@ -59,7 +60,7 @@ namespace Umbraco.Web.JavaScript
|
||||
}
|
||||
jarray.Append("]");
|
||||
|
||||
return WriteScript(jarray.ToString(), Current.IOHelper.ResolveUrl(globalSettings.UmbracoPath), angularModule);
|
||||
return WriteScript(jarray.ToString(), ioHelper.ResolveUrl(globalSettings.UmbracoPath), angularModule);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using ClientDependency.Core.Controls;
|
||||
using ClientDependency.Core.FileRegistration.Providers;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
namespace Umbraco.Web.JavaScript
|
||||
@@ -16,19 +17,19 @@ namespace Umbraco.Web.JavaScript
|
||||
/// <summary>
|
||||
/// Set the defaults
|
||||
/// </summary>
|
||||
public UmbracoClientDependencyLoader(IGlobalSettings globalSettings)
|
||||
public UmbracoClientDependencyLoader(IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
: base()
|
||||
{
|
||||
this.AddPath("UmbracoRoot", Current.IOHelper.ResolveUrl(globalSettings.UmbracoPath));
|
||||
this.AddPath("UmbracoRoot", ioHelper.ResolveUrl(globalSettings.UmbracoPath));
|
||||
this.ProviderName = LoaderControlProvider.DefaultName;
|
||||
|
||||
}
|
||||
|
||||
public static ClientDependencyLoader TryCreate(Control parent, out bool isNew)
|
||||
public static ClientDependencyLoader TryCreate(Control parent, out bool isNew, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
if (ClientDependencyLoader.Instance == null)
|
||||
{
|
||||
var loader = new UmbracoClientDependencyLoader(Current.Factory.GetInstance<IGlobalSettings>());
|
||||
var loader = new UmbracoClientDependencyLoader(globalSettings, ioHelper);
|
||||
parent.Controls.Add(loader);
|
||||
isNew = true;
|
||||
return loader;
|
||||
|
||||
@@ -6,9 +6,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Macros;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -26,10 +26,11 @@ namespace Umbraco.Web.Macros
|
||||
private readonly ILocalizedTextService _textService;
|
||||
private readonly AppCaches _appCaches;
|
||||
private readonly IMacroService _macroService;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService, IHttpContextAccessor httpContextAccessor)
|
||||
public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService, IHttpContextAccessor httpContextAccessor, IIOHelper ioHelper)
|
||||
{
|
||||
_plogger = plogger ?? throw new ArgumentNullException(nameof(plogger));
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
@@ -37,6 +38,7 @@ namespace Umbraco.Web.Macros
|
||||
_textService = textService;
|
||||
_appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches));
|
||||
_macroService = macroService ?? throw new ArgumentNullException(nameof(macroService));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
@@ -171,12 +173,12 @@ namespace Umbraco.Web.Macros
|
||||
|
||||
// gets the macro source file
|
||||
// null if macro is not file-based
|
||||
private static FileInfo GetMacroFile(MacroModel model)
|
||||
private FileInfo GetMacroFile(MacroModel model)
|
||||
{
|
||||
var filename = GetMacroFileName(model);
|
||||
if (filename == null) return null;
|
||||
|
||||
var mapped = Current.IOHelper.MapPath(filename);
|
||||
var mapped = _ioHelper.MapPath(filename);
|
||||
if (mapped == null) return null;
|
||||
|
||||
var file = new FileInfo(mapped);
|
||||
|
||||
@@ -31,21 +31,6 @@ namespace Umbraco.Web
|
||||
private static IExamineManager ExamineManager => Current.Factory.GetInstance<IExamineManager>();
|
||||
private static IUserService UserService => Current.Services.UserService;
|
||||
|
||||
#region IsComposedOf
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content is of a content type composed of the given alias
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The content type alias.</param>
|
||||
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
|
||||
public static bool IsComposedOf(this IPublishedContent content, string alias)
|
||||
{
|
||||
return content.ContentType.CompositionAliases.InvariantContains(alias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Template
|
||||
|
||||
/// <summary>
|
||||
@@ -55,34 +40,26 @@ namespace Umbraco.Web
|
||||
/// <returns>Empty string if none is set.</returns>
|
||||
public static string GetTemplateAlias(this IPublishedContent content)
|
||||
{
|
||||
if(content.TemplateId.HasValue == false)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var template = Current.Services.FileService.GetTemplate(content.TemplateId.Value);
|
||||
return template == null ? string.Empty : template.Alias;
|
||||
return content.GetTemplateAlias(Current.Services.FileService);
|
||||
}
|
||||
|
||||
public static bool IsAllowedTemplate(this IPublishedContent content, int templateId)
|
||||
{
|
||||
if (Current.Configs.Settings().WebRouting.DisableAlternativeTemplates)
|
||||
return content.TemplateId == templateId;
|
||||
|
||||
if (content.TemplateId == templateId || !Current.Configs.Settings().WebRouting.ValidateAlternativeTemplates)
|
||||
return true;
|
||||
|
||||
var publishedContentContentType = Current.Services.ContentTypeService.Get(content.ContentType.Id);
|
||||
if (publishedContentContentType == null)
|
||||
throw new NullReferenceException("No content type returned for published content (contentType='" + content.ContentType.Id + "')");
|
||||
|
||||
return publishedContentContentType.IsAllowedTemplate(templateId);
|
||||
return content.IsAllowedTemplate(
|
||||
Current.Services.ContentTypeService,
|
||||
Current.Configs.Settings().WebRouting.DisableAlternativeTemplates,
|
||||
Current.Configs.Settings().WebRouting.ValidateAlternativeTemplates,
|
||||
templateId);
|
||||
|
||||
}
|
||||
public static bool IsAllowedTemplate(this IPublishedContent content, string templateAlias)
|
||||
{
|
||||
var template = Current.Services.FileService.GetTemplate(templateAlias);
|
||||
return template != null && content.IsAllowedTemplate(template.Id);
|
||||
return content.IsAllowedTemplate(
|
||||
Current.Services.FileService,
|
||||
Current.Services.ContentTypeService,
|
||||
Current.Configs.Settings().WebRouting.DisableAlternativeTemplates,
|
||||
Current.Configs.Settings().WebRouting.ValidateAlternativeTemplates,
|
||||
templateAlias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -101,14 +78,7 @@ namespace Umbraco.Web
|
||||
/// <remarks>Returns true if HasValue is true, or a fallback strategy can provide a value.</remarks>
|
||||
public static bool HasValue(this IPublishedContent content, string alias, string culture = null, string segment = null, Fallback fallback = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return true;
|
||||
|
||||
// else let fallback try to get a value
|
||||
return PublishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, null, out _, out _);
|
||||
return content.HasValue(PublishedValueFallback, alias, culture, segment, fallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,19 +93,7 @@ namespace Umbraco.Web
|
||||
/// <returns>The value of the content's property identified by the alias, if it exists, otherwise a default value.</returns>
|
||||
public static object Value(this IPublishedContent content, string alias, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.GetValue(culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (PublishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value, out property))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable)
|
||||
return property?.GetValue(culture, segment);
|
||||
return content.Value(PublishedValueFallback, alias, culture, segment, fallback, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -151,19 +109,7 @@ namespace Umbraco.Web
|
||||
/// <returns>The value of the content's property identified by the alias, converted to the specified type.</returns>
|
||||
public static T Value<T>(this IPublishedContent content, string alias, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.Value<T>(culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (PublishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value, out property))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable) - otherwise, default
|
||||
return property == null ? default : property.Value<T>(culture, segment);
|
||||
return content.Value<T>(PublishedValueFallback, alias, culture, segment, fallback, defaultValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -239,42 +185,7 @@ namespace Umbraco.Web
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsSomething: misc.
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified content is a specified content type.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to determine content type of.</param>
|
||||
/// <param name="docTypeAlias">The alias of the content type to test against.</param>
|
||||
/// <returns>True if the content is of the specified content type; otherwise false.</returns>
|
||||
public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias)
|
||||
{
|
||||
return content.ContentType.Alias.InvariantEquals(docTypeAlias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified content is a specified content type or it's derived types.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to determine content type of.</param>
|
||||
/// <param name="docTypeAlias">The alias of the content type to test against.</param>
|
||||
/// <param name="recursive">When true, recurses up the content type tree to check inheritance; when false just calls IsDocumentType(this IPublishedContent content, string docTypeAlias).</param>
|
||||
/// <returns>True if the content is of the specified content type or a derived content type; otherwise false.</returns>
|
||||
public static bool IsDocumentType(this IPublishedContent content, string docTypeAlias, bool recursive)
|
||||
{
|
||||
if (content.IsDocumentType(docTypeAlias))
|
||||
return true;
|
||||
|
||||
return recursive && content.IsComposedOf(docTypeAlias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsSomething: equality
|
||||
|
||||
public static bool IsEqual(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.Id == other.Id;
|
||||
}
|
||||
#region IsSomething: equality
|
||||
|
||||
public static HtmlString IsEqual(this IPublishedContent content, IPublishedContent other, string valueIfTrue)
|
||||
{
|
||||
@@ -286,11 +197,6 @@ namespace Umbraco.Web
|
||||
return new HtmlString(content.IsEqual(other) ? valueIfTrue : valueIfFalse);
|
||||
}
|
||||
|
||||
public static bool IsNotEqual(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.IsEqual(other) == false;
|
||||
}
|
||||
|
||||
public static HtmlString IsNotEqual(this IPublishedContent content, IPublishedContent other, string valueIfTrue)
|
||||
{
|
||||
return content.IsNotEqual(other, valueIfTrue, string.Empty);
|
||||
@@ -305,11 +211,6 @@ namespace Umbraco.Web
|
||||
|
||||
#region IsSomething: ancestors and descendants
|
||||
|
||||
public static bool IsDescendant(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return other.Level < content.Level && content.Path.InvariantStartsWith(other.Path.EnsureEndsWith(','));
|
||||
}
|
||||
|
||||
public static HtmlString IsDescendant(this IPublishedContent content, IPublishedContent other, string valueIfTrue)
|
||||
{
|
||||
return content.IsDescendant(other, valueIfTrue, string.Empty);
|
||||
@@ -320,11 +221,6 @@ namespace Umbraco.Web
|
||||
return new HtmlString(content.IsDescendant(other) ? valueIfTrue : valueIfFalse);
|
||||
}
|
||||
|
||||
public static bool IsDescendantOrSelf(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.Path.InvariantEquals(other.Path) || content.IsDescendant(other);
|
||||
}
|
||||
|
||||
public static HtmlString IsDescendantOrSelf(this IPublishedContent content, IPublishedContent other, string valueIfTrue)
|
||||
{
|
||||
return content.IsDescendantOrSelf(other, valueIfTrue, string.Empty);
|
||||
@@ -335,11 +231,6 @@ namespace Umbraco.Web
|
||||
return new HtmlString(content.IsDescendantOrSelf(other) ? valueIfTrue : valueIfFalse);
|
||||
}
|
||||
|
||||
public static bool IsAncestor(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return content.Level < other.Level && other.Path.InvariantStartsWith(content.Path.EnsureEndsWith(','));
|
||||
}
|
||||
|
||||
public static HtmlString IsAncestor(this IPublishedContent content, IPublishedContent other, string valueIfTrue)
|
||||
{
|
||||
return content.IsAncestor(other, valueIfTrue, string.Empty);
|
||||
@@ -350,11 +241,6 @@ namespace Umbraco.Web
|
||||
return new HtmlString(content.IsAncestor(other) ? valueIfTrue : valueIfFalse);
|
||||
}
|
||||
|
||||
public static bool IsAncestorOrSelf(this IPublishedContent content, IPublishedContent other)
|
||||
{
|
||||
return other.Path.InvariantEquals(content.Path) || content.IsAncestor(other);
|
||||
}
|
||||
|
||||
public static HtmlString IsAncestorOrSelf(this IPublishedContent content, IPublishedContent other, string valueIfTrue)
|
||||
{
|
||||
return content.IsAncestorOrSelf(other, valueIfTrue, string.Empty);
|
||||
@@ -664,7 +550,7 @@ namespace Umbraco.Web
|
||||
|
||||
#endregion
|
||||
|
||||
#region Axes: Siblings
|
||||
#region Axes: siblings
|
||||
|
||||
/// <summary>
|
||||
/// Gets the siblings of the content.
|
||||
|
||||
@@ -23,53 +23,13 @@ namespace Umbraco.Web
|
||||
//
|
||||
// besides, for tests, Current support setting a fallback without even a container
|
||||
//
|
||||
// Update to this comment 8/2/2020: issue as been ameliorated by creating extensions methods in Umbraco.Abstractions
|
||||
// that accept the dependencies as arguments for many of these extension methods, and can be used within the Umbraco code-base.
|
||||
// For site developers, the "friendly" extension methods using service location have been maintained, delegating to the ones that
|
||||
// take the dependencies as parameters.
|
||||
|
||||
private static IPublishedValueFallback PublishedValueFallback => Current.PublishedValueFallback;
|
||||
|
||||
#region IsComposedOf
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content is of a content type composed of the given alias
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The content type alias.</param>
|
||||
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
|
||||
public static bool IsComposedOf(this IPublishedElement content, string alias)
|
||||
{
|
||||
return content.ContentType.CompositionAliases.InvariantContains(alias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HasProperty
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content has a property identified by its alias.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <returns>A value indicating whether the content has the property identified by the alias.</returns>
|
||||
/// <remarks>The content may have a property, and that property may not have a value.</remarks>
|
||||
public static bool HasProperty(this IPublishedElement content, string alias)
|
||||
{
|
||||
return content.ContentType.GetPropertyType(alias) != null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HasValue
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content has a value for a property identified by its alias.
|
||||
/// </summary>
|
||||
/// <remarks>Returns true if <c>GetProperty(alias)</c> is not <c>null</c> and <c>GetProperty(alias).HasValue</c> is <c>true</c>.</remarks>
|
||||
public static bool HasValue(this IPublishedElement content, string alias, string culture = null, string segment = null)
|
||||
{
|
||||
var prop = content.GetProperty(alias);
|
||||
return prop != null && prop.HasValue(culture, segment);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value
|
||||
|
||||
/// <summary>
|
||||
@@ -90,19 +50,7 @@ namespace Umbraco.Web
|
||||
/// </remarks>
|
||||
public static object Value(this IPublishedElement content, string alias, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.GetValue(culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (PublishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable) - otherwise, default
|
||||
return property?.GetValue(culture, segment);
|
||||
return content.Value(PublishedValueFallback, alias, culture, segment, fallback, defaultValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -128,31 +76,7 @@ namespace Umbraco.Web
|
||||
/// </remarks>
|
||||
public static T Value<T>(this IPublishedElement content, string alias, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
|
||||
// if we have a property, and it has a value, return that value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
return property.Value<T>(culture, segment);
|
||||
|
||||
// else let fallback try to get a value
|
||||
if (PublishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value))
|
||||
return value;
|
||||
|
||||
// else... if we have a property, at least let the converter return its own
|
||||
// vision of 'no value' (could be an empty enumerable) - otherwise, default
|
||||
return property == null ? default : property.Value<T>(culture, segment);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ToIndexedArray
|
||||
|
||||
public static IndexedArrayItem<TContent>[] ToIndexedArray<TContent>(this IEnumerable<TContent> source)
|
||||
where TContent : class, IPublishedElement
|
||||
{
|
||||
var set = source.Select((content, index) => new IndexedArrayItem<TContent>(content, index)).ToArray();
|
||||
foreach (var setItem in set) setItem.TotalCount = set.Length;
|
||||
return set;
|
||||
return content.Value<T>(PublishedValueFallback, alias, culture, segment, fallback, defaultValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -168,9 +92,7 @@ namespace Umbraco.Web
|
||||
/// the content is visible.</remarks>
|
||||
public static bool IsVisible(this IPublishedElement content)
|
||||
{
|
||||
// rely on the property converter - will return default bool value, ie false, if property
|
||||
// is not defined, or has no value, else will return its value.
|
||||
return content.Value<bool>(Constants.Conventions.Content.NaviHide) == false;
|
||||
return content.IsVisible(PublishedValueFallback);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
@@ -18,12 +17,7 @@ namespace Umbraco.Web
|
||||
|
||||
public static object Value(this IPublishedProperty property, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default)
|
||||
{
|
||||
if (property.HasValue(culture, segment))
|
||||
return property.GetValue(culture, segment);
|
||||
|
||||
return PublishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var value)
|
||||
? value
|
||||
: property.GetValue(culture, segment); // give converter a chance to return it's own vision of "no value"
|
||||
return property.Value(PublishedValueFallback, culture, segment, fallback, defaultValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -32,33 +26,7 @@ namespace Umbraco.Web
|
||||
|
||||
public static T Value<T>(this IPublishedProperty property, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default)
|
||||
{
|
||||
if (property.HasValue(culture, segment))
|
||||
{
|
||||
// we have a value
|
||||
// try to cast or convert it
|
||||
var value = property.GetValue(culture, segment);
|
||||
if (value is T valueAsT) return valueAsT;
|
||||
var valueConverted = value.TryConvertTo<T>();
|
||||
if (valueConverted) return valueConverted.Result;
|
||||
|
||||
// cannot cast nor convert the value, nothing we can return but 'default'
|
||||
// note: we don't want to fallback in that case - would make little sense
|
||||
return default;
|
||||
}
|
||||
|
||||
// we don't have a value, try fallback
|
||||
if (PublishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var fallbackValue))
|
||||
return fallbackValue;
|
||||
|
||||
// we don't have a value - neither direct nor fallback
|
||||
// give a chance to the converter to return something (eg empty enumerable)
|
||||
var noValue = property.GetValue(culture, segment);
|
||||
if (noValue is T noValueAsT) return noValueAsT;
|
||||
var noValueConverted = noValue.TryConvertTo<T>();
|
||||
if (noValueConverted) return noValueConverted.Result;
|
||||
|
||||
// cannot cast noValue nor convert it, nothing we can return but 'default'
|
||||
return default;
|
||||
return property.Value<T>(PublishedValueFallback, culture, segment, fallback, defaultValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Concurrent;
|
||||
using Umbraco.Core.Collections;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
namespace Umbraco.Web
|
||||
@@ -21,13 +22,15 @@ namespace Umbraco.Web
|
||||
/// </remarks>
|
||||
public sealed class RoutableDocumentFilter
|
||||
{
|
||||
public RoutableDocumentFilter(IGlobalSettings globalSettings)
|
||||
public RoutableDocumentFilter(IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
private static readonly ConcurrentDictionary<string, bool> RouteChecks = new ConcurrentDictionary<string, bool>();
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private object _locker = new object();
|
||||
private bool _isInit = false;
|
||||
private int? _routeCount;
|
||||
@@ -103,7 +106,7 @@ namespace Umbraco.Web
|
||||
.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => x.Trim().ToLowerInvariant())
|
||||
.Where(x => x.IsNullOrWhiteSpace() == false)
|
||||
.Select(reservedUrl => Current.IOHelper.ResolveUrl(reservedUrl).Trim().EnsureStartsWith("/"))
|
||||
.Select(reservedUrl => _ioHelper.ResolveUrl(reservedUrl).Trim().EnsureStartsWith("/"))
|
||||
.Where(reservedUrlTrimmed => reservedUrlTrimmed.IsNullOrWhiteSpace() == false))
|
||||
{
|
||||
newReservedList.Add(reservedUrlTrimmed);
|
||||
@@ -141,7 +144,7 @@ namespace Umbraco.Web
|
||||
return paths
|
||||
.Select(x => x.Trim().ToLowerInvariant())
|
||||
.Where(x => x.IsNullOrWhiteSpace() == false)
|
||||
.Select(reservedPath => Current.IOHelper.ResolveUrl(reservedPath).Trim().EnsureStartsWith("/").EnsureEndsWith("/"))
|
||||
.Select(reservedPath => _ioHelper.ResolveUrl(reservedPath).Trim().EnsureStartsWith("/").EnsureEndsWith("/"))
|
||||
.Where(reservedPathTrimmed => reservedPathTrimmed.IsNullOrWhiteSpace() == false);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
@@ -34,6 +35,7 @@ namespace Umbraco.Web.Scheduling
|
||||
private readonly IUmbracoContextFactory _umbracoContextFactory;
|
||||
private readonly IHealthChecks _healthChecksConfig;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
private BackgroundTaskRunner<IBackgroundTask> _keepAliveRunner;
|
||||
private BackgroundTaskRunner<IBackgroundTask> _publishingRunner;
|
||||
@@ -51,7 +53,7 @@ namespace Umbraco.Web.Scheduling
|
||||
HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications,
|
||||
IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger,
|
||||
IHostingEnvironment hostingEnvironment, IHealthChecks healthChecksConfig,
|
||||
IUmbracoSettingsSection umbracoSettingsSection)
|
||||
IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper)
|
||||
{
|
||||
_runtime = runtime;
|
||||
_contentService = contentService;
|
||||
@@ -65,6 +67,7 @@ namespace Umbraco.Web.Scheduling
|
||||
_notifications = notifications;
|
||||
_healthChecksConfig = healthChecksConfig ?? throw new ArgumentNullException(nameof(healthChecksConfig));
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
@@ -182,7 +185,7 @@ namespace Umbraco.Web.Scheduling
|
||||
// temp file cleanup, will run on all servers - even though file upload should only be handled on the master, this will
|
||||
// ensure that in the case it happes on replicas that they are cleaned up.
|
||||
var task = new TempFileCleanup(_fileCleanupRunner, DefaultDelayMilliseconds, OneHourMilliseconds,
|
||||
new[] { new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads)) },
|
||||
new[] { new DirectoryInfo(_ioHelper.MapPath(Constants.SystemDirectories.TempFileUploads)) },
|
||||
TimeSpan.FromDays(1), //files that are over a day old
|
||||
_runtime, _logger);
|
||||
_scrubberRunner.TryAdd(task);
|
||||
|
||||
@@ -8,6 +8,7 @@ using Umbraco.Core.Models.Membership;
|
||||
using Microsoft.AspNet.Identity.Owin;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Web.Models.Identity;
|
||||
@@ -24,12 +25,14 @@ namespace Umbraco.Web.Security
|
||||
private readonly HttpContextBase _httpContext;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public WebSecurity(HttpContextBase httpContext, IUserService userService, IGlobalSettings globalSettings)
|
||||
public WebSecurity(HttpContextBase httpContext, IUserService userService, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
_httpContext = httpContext;
|
||||
_userService = userService;
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
private IUser _currentUser;
|
||||
@@ -196,7 +199,7 @@ namespace Umbraco.Web.Security
|
||||
var user = CurrentUser;
|
||||
|
||||
// Check for console access
|
||||
if (user == null || (requiresApproval && user.IsApproved == false) || (user.IsLockedOut && RequestIsInUmbracoApplication(_httpContext, _globalSettings)))
|
||||
if (user == null || (requiresApproval && user.IsApproved == false) || (user.IsLockedOut && RequestIsInUmbracoApplication(_httpContext, _globalSettings, _ioHelper)))
|
||||
{
|
||||
if (throwExceptions) throw new ArgumentException("You have no privileges to the umbraco console. Please contact your administrator");
|
||||
return ValidateRequestAttempt.FailedNoPrivileges;
|
||||
@@ -205,9 +208,9 @@ namespace Umbraco.Web.Security
|
||||
|
||||
}
|
||||
|
||||
private static bool RequestIsInUmbracoApplication(HttpContextBase context, IGlobalSettings globalSettings)
|
||||
private static bool RequestIsInUmbracoApplication(HttpContextBase context, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
return context.Request.Path.ToLower().IndexOf(Current.IOHelper.ResolveUrl(globalSettings.UmbracoPath).ToLower(), StringComparison.Ordinal) > -1;
|
||||
return context.Request.Path.ToLower().IndexOf(ioHelper.ResolveUrl(globalSettings.UmbracoPath).ToLower(), StringComparison.Ordinal) > -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Umbraco.Web
|
||||
}
|
||||
|
||||
|
||||
var webSecurity = new WebSecurity(httpContext, _userService, _globalSettings);
|
||||
var webSecurity = new WebSecurity(httpContext, _userService, _globalSettings, _ioHelper);
|
||||
|
||||
return new UmbracoContext(httpContext, _publishedSnapshotService, webSecurity, _umbracoSettings, _urlProviders, _mediaUrlProviders, _globalSettings, _variationContextAccessor, _ioHelper);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Umbraco.Web
|
||||
ConfigureUmbracoAuthentication(app);
|
||||
|
||||
app
|
||||
.UseSignalR(GlobalSettings)
|
||||
.UseSignalR(GlobalSettings, IOHelper)
|
||||
.FinalizeMiddlewareConfiguration();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user