From 1c651b4e59485df9528ad78b79e8af3bb1b2a1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 11 Sep 2019 14:31:03 +0200 Subject: [PATCH 1/8] store img size as html attributes --- .../src/common/services/tinymce.service.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js index 5578c7a609..e479a0d348 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js @@ -442,10 +442,10 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s if (editor.settings.maxImageSize && editor.settings.maxImageSize !== 0) { var newSize = imageHelper.scaleToMaxSize(editor.settings.maxImageSize, size.w, size.h); - - var s = "width: " + newSize.width + "px; height:" + newSize.height + "px;"; - editor.dom.setAttrib(imgElm, 'style', s); - + + editor.dom.setAttrib(imgElm, 'width', newSize.width); + editor.dom.setAttrib(imgElm, 'height', newSize.height); + if (img.url) { var src = img.url + "?width=" + newSize.width + "&height=" + newSize.height; editor.dom.setAttrib(imgElm, 'data-mce-src', src); From 4ccebbc20902fe482a15ecf0d8b23ba6037f1d1c Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 12 Sep 2019 08:49:40 +0100 Subject: [PATCH 2/8] Reopen branch/PR for fixes * Reorder usings * Add an error response & log the reason if we can't move a file about * Add UmbracoApplicationAuthorize attribute for security so not any user can upload images --- src/Umbraco.Web/Editors/TinyMceController.cs | 38 ++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web/Editors/TinyMceController.cs b/src/Umbraco.Web/Editors/TinyMceController.cs index 7ed71f0268..0951b88443 100644 --- a/src/Umbraco.Web/Editors/TinyMceController.cs +++ b/src/Umbraco.Web/Editors/TinyMceController.cs @@ -1,32 +1,41 @@ -using System.Net; -using System.Net.Http; -using System.Web.Http; -using Umbraco.Core.Services; -using Umbraco.Web.WebApi; -using Umbraco.Core; -using Umbraco.Web.Mvc; -using Umbraco.Core.IO; +using System; using System.IO; -using System.Threading.Tasks; -using Umbraco.Web.Composing; -using Umbraco.Core.Configuration.UmbracoSettings; using System.Linq; -using System; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using System.Web.Http; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Services; +using Umbraco.Web.Composing; +using Umbraco.Web.Mvc; +using Umbraco.Web.WebApi; +using Umbraco.Web.WebApi.Filters; +using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Editors { [PluginController("UmbracoApi")] + [UmbracoApplicationAuthorize( + Constants.Applications.Content, + Constants.Applications.Media, + Constants.Applications.Members)] public class TinyMceController : UmbracoAuthorizedApiController { private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; + public TinyMceController(IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; } + [UmbracoApplicationAuthorize(Constants.Applications.Content)] [HttpPost] public async Task UploadImage() { @@ -91,8 +100,9 @@ namespace Umbraco.Web.Editors } catch (Exception ex) { - // Could be a file permission ex - throw; + // IOException, PathTooLong, DirectoryNotFound, UnathorizedAccess + Logger.Error(ex, "Error when trying to move {CurrentFilePath} to {NewFilePath}", currentFile, newFilePath); + return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, $"Error when trying to move {currentFile} to {newFilePath}", ex); } return Request.CreateResponse(HttpStatusCode.OK, new { tmpLocation = relativeNewFilePath }); From 632808acdbdc87c6a27abd4f54fa248db33d7ea7 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 12 Sep 2019 09:04:23 +0100 Subject: [PATCH 3/8] * Inbject UmbracoContextAccessor & null check it for the user id * Remove unused & sort usings --- .../PropertyEditors/GridPropertyEditor.cs | 25 +++++++++++-------- .../PropertyEditors/RichTextPropertyEditor.cs | 18 ++++++------- 2 files changed, 23 insertions(+), 20 deletions(-) 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); From ba319609f2dee4e8ae88814aab6fc88c90519f0b Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 12 Sep 2019 09:40:21 +0100 Subject: [PATCH 4/8] Fix up tests - thanks again VS for not notifying me that the Build fails when I build the entire SLN --- src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs | 3 ++- src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index 46636483b6..f1e2bf20d6 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Web.PropertyEditors; using Umbraco.Core.Services; +using Umbraco.Web; namespace Umbraco.Tests.PublishedContent { @@ -39,7 +40,7 @@ namespace Umbraco.Tests.PublishedContent var converters = Factory.GetInstance(); var dataTypeService = new TestObjects.TestDataTypeService( - new DataType(new RichTextPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of())) { Id = 1 }); + new DataType(new RichTextPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())) { Id = 1 }); var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index e98e28c3dd..6ef632bf90 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -44,11 +44,12 @@ namespace Umbraco.Tests.PublishedContent var logger = Mock.Of(); var mediaService = Mock.Of(); var contentTypeBaseServiceProvider = Mock.Of(); + var umbracoContextAccessor = Mock.Of(); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(logger)) { Id = 1 }, new DataType(new TrueFalsePropertyEditor(logger)) { Id = 1001 }, - new DataType(new RichTextPropertyEditor(logger, mediaService, contentTypeBaseServiceProvider)) { Id = 1002 }, + new DataType(new RichTextPropertyEditor(logger, mediaService, contentTypeBaseServiceProvider, umbracoContextAccessor)) { Id = 1002 }, new DataType(new IntegerPropertyEditor(logger)) { Id = 1003 }, new DataType(new TextboxPropertyEditor(logger)) { Id = 1004 }, new DataType(new MediaPickerPropertyEditor(logger)) { Id = 1005 }); From a5c5a12a009f2309b6a6d2fd62705c247eafe69d Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 12 Sep 2019 12:07:57 +0100 Subject: [PATCH 5/8] Remove dupe Authz attribute --- src/Umbraco.Web/Editors/TinyMceController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Umbraco.Web/Editors/TinyMceController.cs b/src/Umbraco.Web/Editors/TinyMceController.cs index 0951b88443..9bc6830491 100644 --- a/src/Umbraco.Web/Editors/TinyMceController.cs +++ b/src/Umbraco.Web/Editors/TinyMceController.cs @@ -35,7 +35,6 @@ namespace Umbraco.Web.Editors _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; } - [UmbracoApplicationAuthorize(Constants.Applications.Content)] [HttpPost] public async Task UploadImage() { From f6e9fb2845b01a49aa50a1bf325087489f109c4c Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 12 Sep 2019 14:27:22 +0100 Subject: [PATCH 6/8] Adds same code loop as FileUploadCleanupFilterAttribute to delete files --- .../Templates/TemplateUtilities.cs | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Templates/TemplateUtilities.cs b/src/Umbraco.Web/Templates/TemplateUtilities.cs index 96ea2659b1..e9f7105c57 100644 --- a/src/Umbraco.Web/Templates/TemplateUtilities.cs +++ b/src/Umbraco.Web/Templates/TemplateUtilities.cs @@ -3,7 +3,6 @@ using System; using System.IO; using System.Text.RegularExpressions; using Umbraco.Core; -using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Services; using Umbraco.Web.Composing; @@ -236,6 +235,39 @@ namespace Umbraco.Web.Templates // Remove the data attribute (so we do not re-process this) img.Attributes.Remove(TemporaryImageDataAttribute); + + // Delete folder & image now its saved in media + // The folder should contain one image - as a unique guid folder created + // for each image uploaded from TinyMceController + var folderName = Path.GetDirectoryName(absoluteTempImagePath); + try + { + File.Delete(absoluteTempImagePath); + Directory.Delete(folderName); + } + catch (Exception ex) + { + Current.Logger.Error(typeof(TemplateUtilities), ex, "Could not delete temp file or folder {FileName}", absoluteTempImagePath); + } + + } + + // Now remove all old files so that the temp folder(s) never grow + // Anything older than one day gets deleted + var files = Directory.GetFiles(SystemDirectories.TempFileUploads, "*", SearchOption.AllDirectories); + foreach (var file in files) + { + if (DateTime.UtcNow - File.GetLastWriteTimeUtc(file) > TimeSpan.FromDays(1)) + { + try + { + File.Delete(file); + } + catch (Exception ex) + { + Current.Logger.Error(typeof(TemplateUtilities), ex, "Could not delete temp file {FileName}", file); + } + } } return htmlDoc.DocumentNode.OuterHtml; From 0d0abca255929ab5330250d691f786c16177b5fb Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 12 Sep 2019 14:35:45 +0100 Subject: [PATCH 7/8] Move the general cleanup of the App_Data/TEMP/FileUploads folder for one day+ old files --- src/Umbraco.Web/Editors/TinyMceController.cs | 20 ++++++++++++++++++- .../Templates/TemplateUtilities.cs | 18 ----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web/Editors/TinyMceController.cs b/src/Umbraco.Web/Editors/TinyMceController.cs index 9bc6830491..5bed080f7f 100644 --- a/src/Umbraco.Web/Editors/TinyMceController.cs +++ b/src/Umbraco.Web/Editors/TinyMceController.cs @@ -102,7 +102,25 @@ namespace Umbraco.Web.Editors // IOException, PathTooLong, DirectoryNotFound, UnathorizedAccess Logger.Error(ex, "Error when trying to move {CurrentFilePath} to {NewFilePath}", currentFile, newFilePath); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, $"Error when trying to move {currentFile} to {newFilePath}", ex); - } + } + + // Now remove all old files so that the temp folder(s) never grow + // Anything older than one day gets deleted + var tempFiles = Directory.GetFiles(SystemDirectories.TempFileUploads, "*", SearchOption.AllDirectories); + foreach (var tempFile in tempFiles) + { + if (DateTime.UtcNow - File.GetLastWriteTimeUtc(tempFile) > TimeSpan.FromDays(1)) + { + try + { + File.Delete(tempFile); + } + catch (Exception ex) + { + Logger.Error(ex, "Could not delete temp file {FileName}", tempFile); + } + } + } return Request.CreateResponse(HttpStatusCode.OK, new { tmpLocation = relativeNewFilePath }); } diff --git a/src/Umbraco.Web/Templates/TemplateUtilities.cs b/src/Umbraco.Web/Templates/TemplateUtilities.cs index e9f7105c57..decd547be3 100644 --- a/src/Umbraco.Web/Templates/TemplateUtilities.cs +++ b/src/Umbraco.Web/Templates/TemplateUtilities.cs @@ -252,24 +252,6 @@ namespace Umbraco.Web.Templates } - // Now remove all old files so that the temp folder(s) never grow - // Anything older than one day gets deleted - var files = Directory.GetFiles(SystemDirectories.TempFileUploads, "*", SearchOption.AllDirectories); - foreach (var file in files) - { - if (DateTime.UtcNow - File.GetLastWriteTimeUtc(file) > TimeSpan.FromDays(1)) - { - try - { - File.Delete(file); - } - catch (Exception ex) - { - Current.Logger.Error(typeof(TemplateUtilities), ex, "Could not delete temp file {FileName}", file); - } - } - } - return htmlDoc.DocumentNode.OuterHtml; } } From c4026fb92fe8d3cc7aff596a5fd3fcc75987f691 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Thu, 12 Sep 2019 14:54:21 +0100 Subject: [PATCH 8/8] Inject all the things - aka make sure Shan doesn't poke with a sharp pointy stick for using Current --- src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs | 10 +++++++--- .../PropertyEditors/RichTextPropertyEditor.cs | 10 +++++++--- src/Umbraco.Web/Templates/TemplateUtilities.cs | 5 +++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 256c64ee30..48273a1651 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -26,6 +26,7 @@ namespace Umbraco.Web.PropertyEditors private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private IUmbracoContextAccessor _umbracoContextAccessor; + private ILogger _logger; public GridPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) : base(logger) @@ -33,6 +34,7 @@ namespace Umbraco.Web.PropertyEditors _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; _umbracoContextAccessor = umbracoContextAccessor; + _logger = logger; } public override IPropertyIndexValueFactory PropertyIndexValueFactory => new GridPropertyIndexValueFactory(); @@ -41,7 +43,7 @@ namespace Umbraco.Web.PropertyEditors /// Overridden to ensure that the value is validated /// /// - protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor); + protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger); protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); @@ -50,13 +52,15 @@ namespace Umbraco.Web.PropertyEditors private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private IUmbracoContextAccessor _umbracoContextAccessor; + private ILogger _logger; - public GridPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) + public GridPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, ILogger logger) : base(attribute) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; _umbracoContextAccessor = umbracoContextAccessor; + _logger = logger; } /// @@ -88,7 +92,7 @@ namespace Umbraco.Web.PropertyEditors 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); + var parsedHtml = TemplateUtilities.FindAndPersistPastedTempImages(html, Constants.System.Root, userId, _mediaService, _contentTypeBaseServiceProvider, _logger); rte.Value = parsedHtml; } diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 61461859aa..ec18ff203f 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -27,6 +27,7 @@ namespace Umbraco.Web.PropertyEditors private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private IUmbracoContextAccessor _umbracoContextAccessor; + private ILogger _logger; /// /// The constructor will setup the property editor based on the attribute if one is found @@ -36,13 +37,14 @@ namespace Umbraco.Web.PropertyEditors _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; _umbracoContextAccessor = umbracoContextAccessor; + _logger = logger; } /// /// Create a custom value editor /// /// - protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor); + protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger); protected override IConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(); @@ -56,13 +58,15 @@ namespace Umbraco.Web.PropertyEditors private IMediaService _mediaService; private IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private IUmbracoContextAccessor _umbracoContextAccessor; + private ILogger _logger; - public RichTextPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) + public RichTextPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, ILogger logger) : base(attribute) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; _umbracoContextAccessor = umbracoContextAccessor; + _logger = logger; } /// @@ -116,7 +120,7 @@ namespace Umbraco.Web.PropertyEditors 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); + parsed = TemplateUtilities.FindAndPersistPastedTempImages(parsed, Constants.System.Root, userId, _mediaService, _contentTypeBaseServiceProvider, _logger); return parsed; } } diff --git a/src/Umbraco.Web/Templates/TemplateUtilities.cs b/src/Umbraco.Web/Templates/TemplateUtilities.cs index decd547be3..60a57b500e 100644 --- a/src/Umbraco.Web/Templates/TemplateUtilities.cs +++ b/src/Umbraco.Web/Templates/TemplateUtilities.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text.RegularExpressions; using Umbraco.Core; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; @@ -188,7 +189,7 @@ namespace Umbraco.Web.Templates // see comment in ResolveMediaFromTextString for group reference => ResolveImgPattern.Replace(text, "$1$3$4$5"); - internal static string FindAndPersistPastedTempImages(string html, int mediaParentFolder, int userId, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + internal static string FindAndPersistPastedTempImages(string html, int mediaParentFolder, int userId, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, ILogger logger) { // Find all img's that has data-tmpimg attribute // Use HTML Agility Pack - https://html-agility-pack.net @@ -247,7 +248,7 @@ namespace Umbraco.Web.Templates } catch (Exception ex) { - Current.Logger.Error(typeof(TemplateUtilities), ex, "Could not delete temp file or folder {FileName}", absoluteTempImagePath); + logger.Error(typeof(TemplateUtilities), ex, "Could not delete temp file or folder {FileName}", absoluteTempImagePath); } }