diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 710c68eeb3..256c64ee30 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -1,13 +1,12 @@ -using System.Linq; -using Umbraco.Core.Logging; +using Newtonsoft.Json; +using System.Linq; using Umbraco.Core; -using Umbraco.Core.PropertyEditors; -using Newtonsoft.Json; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; -using Umbraco.Web.Templates; -using Umbraco.Web.Composing; +using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; +using Umbraco.Web.Templates; namespace Umbraco.Web.PropertyEditors { @@ -26,12 +25,14 @@ namespace Umbraco.Web.PropertyEditors { private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; + private IUmbracoContextAccessor _umbracoContextAccessor; - public GridPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + public GridPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) : base(logger) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; + _umbracoContextAccessor = umbracoContextAccessor; } public override IPropertyIndexValueFactory PropertyIndexValueFactory => new GridPropertyIndexValueFactory(); @@ -40,7 +41,7 @@ namespace Umbraco.Web.PropertyEditors /// Overridden to ensure that the value is validated /// /// - protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider); + protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor); protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); @@ -48,12 +49,14 @@ namespace Umbraco.Web.PropertyEditors { private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; + private IUmbracoContextAccessor _umbracoContextAccessor; - public GridPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + public GridPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) : base(attribute) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; + _umbracoContextAccessor = umbracoContextAccessor; } /// @@ -81,8 +84,8 @@ namespace Umbraco.Web.PropertyEditors { // Parse the HTML var html = rte.Value?.ToString(); - - var userId = Current.UmbracoContext.Security.CurrentUser.Id; + + var userId = _umbracoContextAccessor.UmbracoContext?.Security.CurrentUser.Id ?? -1; // TODO: In future task(get the parent folder from this config) to save the media into var parsedHtml = TemplateUtilities.FindAndPersistPastedTempImages(html, Constants.System.Root, userId, _mediaService, _contentTypeBaseServiceProvider); diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 8cab94a4be..61461859aa 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -1,15 +1,11 @@ -using HtmlAgilityPack; -using System; +using System; using System.Collections.Generic; -using System.IO; using Umbraco.Core; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Examine; -using Umbraco.Web.Composing; using Umbraco.Web.Macros; using Umbraco.Web.Templates; @@ -30,21 +26,23 @@ namespace Umbraco.Web.PropertyEditors { private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; + private IUmbracoContextAccessor _umbracoContextAccessor; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public RichTextPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) : base(logger) + public RichTextPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) : base(logger) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; + _umbracoContextAccessor = umbracoContextAccessor; } /// /// Create a custom value editor /// /// - protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider); + protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor); protected override IConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(); @@ -57,12 +55,14 @@ namespace Umbraco.Web.PropertyEditors { private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; + private IUmbracoContextAccessor _umbracoContextAccessor; - public RichTextPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + public RichTextPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) : base(attribute) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; + _umbracoContextAccessor = umbracoContextAccessor; } /// @@ -113,7 +113,7 @@ namespace Umbraco.Web.PropertyEditors var editorValueWithMediaUrlsRemoved = TemplateUtilities.RemoveMediaUrlsFromTextString(editorValue.Value.ToString()); var parsed = MacroTagParser.FormatRichTextContentForPersistence(editorValueWithMediaUrlsRemoved); - var userId = Current.UmbracoContext.Security.CurrentUser.Id; + var userId = _umbracoContextAccessor.UmbracoContext?.Security.CurrentUser.Id ?? -1; // TODO: In future task(get the parent folder from this config) to save the media into parsed = TemplateUtilities.FindAndPersistPastedTempImages(parsed, Constants.System.Root, userId, _mediaService, _contentTypeBaseServiceProvider);