From b3c06be83acfb077f14604b0705c64b36a175a58 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 18 Dec 2019 13:38:03 +0100 Subject: [PATCH] AB4227 - Moved a mix of files --- src/Umbraco.Core/ContentExtensions.cs | 203 ------------------ src/Umbraco.Core/Umbraco.Core.csproj | 6 +- .../ContentExtensions.cs | 165 ++++++++++++++ .../Security/MachineKeyGenerator.cs | 2 +- .../PublishedContentCacheTests.cs | 2 +- .../PublishedMemberCache.cs | 14 +- .../XmlPublishedSnapshotService.cs | 2 +- .../PublishedContentTestBase.cs | 3 +- .../PublishedContent/PublishedContentTests.cs | 3 +- src/Umbraco.Web/Editors/MediaController.cs | 21 +- .../PublishedContentHashtableConverter.cs | 11 +- .../RichTextEditorPastedImages.cs | 9 +- .../PublishedCache/PublishedMember.cs | 12 +- 13 files changed, 221 insertions(+), 232 deletions(-) delete mode 100644 src/Umbraco.Core/ContentExtensions.cs rename src/{Umbraco.Core => Umbraco.Infrastructure}/Security/MachineKeyGenerator.cs (98%) diff --git a/src/Umbraco.Core/ContentExtensions.cs b/src/Umbraco.Core/ContentExtensions.cs deleted file mode 100644 index 16a86a1527..0000000000 --- a/src/Umbraco.Core/ContentExtensions.cs +++ /dev/null @@ -1,203 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Xml.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Core.Composing; -using Umbraco.Core.IO; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Services; -using Umbraco.Core.Strings; - -namespace Umbraco.Core -{ - public static class ContentExtensions - { - // this ain't pretty - private static IMediaFileSystem _mediaFileSystem; - private static IMediaFileSystem MediaFileSystem => _mediaFileSystem ?? (_mediaFileSystem = Current.MediaFileSystem); - - - - - /// - /// Checks if the IContentBase has children - /// - /// - /// - /// - /// - /// This is a bit of a hack because we need to type check! - /// - internal static bool HasChildren(IContentBase content, ServiceContext services) - { - if (content is IContent) - { - return services.ContentService.HasChildren(content.Id); - } - if (content is IMedia) - { - return services.MediaService.HasChildren(content.Id); - } - return false; - } - - /// - /// Returns properties that do not belong to a group - /// - /// - /// - public static IEnumerable GetNonGroupedProperties(this IContentBase content) - { - return content.Properties - .Where(x => x.PropertyType.PropertyGroupId == null) - .OrderBy(x => x.PropertyType.SortOrder); - } - - /// - /// Returns the Property object for the given property group - /// - /// - /// - /// - public static IEnumerable GetPropertiesForGroup(this IContentBase content, PropertyGroup propertyGroup) - { - //get the properties for the current tab - return content.Properties - .Where(property => propertyGroup.PropertyTypes - .Select(propertyType => propertyType.Id) - .Contains(property.PropertyTypeId)); - } - - #region SetValue for setting file contents - - /// - /// Sets the posted file value of a property. - /// - public static void SetValue(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) - { - if (filename == null || filestream == null) return; - - // get a safe & clean filename - var shortStringHelper = Current.Factory.GetInstance(); - - filename = shortStringHelper.CleanStringForSafeFileName(filename); - if (string.IsNullOrWhiteSpace(filename)) return; - filename = filename.ToLower(); - - SetUploadFile(content,contentTypeBaseServiceProvider, propertyTypeAlias, filename, filestream, culture, segment); - } - - private static void SetUploadFile(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) - { - var property = GetProperty(content, contentTypeBaseServiceProvider, propertyTypeAlias); - - // Fixes https://github.com/umbraco/Umbraco-CMS/issues/3937 - Assigning a new file to an - // existing IMedia with extension SetValue causes exception 'Illegal characters in path' - string oldpath = null; - if (property.GetValue(culture, segment) is string svalue) - { - if (svalue.DetectIsJson()) - { - // the property value is a JSON serialized image crop data set - grab the "src" property as the file source - var jObject = JsonConvert.DeserializeObject(svalue); - svalue = jObject != null ? jObject.GetValueAsString("src") : svalue; - } - oldpath = MediaFileSystem.GetRelativePath(svalue); - } - - var filepath = MediaFileSystem.StoreFile(content, property.PropertyType, filename, filestream, oldpath); - property.SetValue(MediaFileSystem.GetUrl(filepath), culture, segment); - } - - // gets or creates a property for a content item. - private static IProperty GetProperty(IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias) - { - var property = content.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); - if (property != null) return property; - - var contentType = contentTypeBaseServiceProvider.GetContentTypeOf(content); - var propertyType = contentType.CompositionPropertyTypes - .FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); - if (propertyType == null) - throw new Exception("No property type exists with alias " + propertyTypeAlias + "."); - - property = new Property(propertyType); - content.Properties.Add(property); - return property; - } - - /// - /// Stores a file. - /// - /// A content item. - /// The property alias. - /// The name of the file. - /// A stream containing the file data. - /// The original file path, if any. - /// The path to the file, relative to the media filesystem. - /// - /// Does NOT set the property value, so one should probably store the file and then do - /// something alike: property.Value = MediaHelper.FileSystem.GetUrl(filepath). - /// The original file path is used, in the old media file path scheme, to try and reuse - /// the "folder number" that was assigned to the previous file referenced by the property, - /// if any. - /// - public static string StoreFile(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string filepath) - { - var contentType = contentTypeBaseServiceProvider.GetContentTypeOf(content); - var propertyType = contentType - .CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); - if (propertyType == null) throw new ArgumentException("Invalid property type alias " + propertyTypeAlias + "."); - return MediaFileSystem.StoreFile(content, propertyType, filename, filestream, filepath); - } - - #endregion - - #region User/Profile methods - - /// - /// Gets the for the Creator of this media item. - /// - public static IProfile GetCreatorProfile(this IMedia media, IUserService userService) - { - return userService.GetProfileById(media.CreatorId); - } - - [Obsolete("Use the overload that declares the IUserService to use")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static IProfile GetCreatorProfile(this IContentBase content) - { - return Current.Services.UserService.GetProfileById(content.CreatorId); - } - - - [Obsolete("Use the overload that declares the IUserService to use")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static IProfile GetWriterProfile(this IContent content) - { - return Current.Services.UserService.GetProfileById(content.WriterId); - } - - - - #endregion - - - - #region Dirty - - public static IEnumerable GetDirtyUserProperties(this IContentBase entity) - { - return entity.Properties.Where(x => x.IsDirty()).Select(x => x.Alias); - } - - - - #endregion - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 110707c5b9..9f44c65a2a 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -140,6 +140,8 @@ + + @@ -147,15 +149,11 @@ - - - - diff --git a/src/Umbraco.Infrastructure/ContentExtensions.cs b/src/Umbraco.Infrastructure/ContentExtensions.cs index f3341c9c8e..f74ecd5693 100644 --- a/src/Umbraco.Infrastructure/ContentExtensions.cs +++ b/src/Umbraco.Infrastructure/ContentExtensions.cs @@ -1,8 +1,15 @@ using System; +using System.Collections.Generic; +using System.IO; using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Umbraco.Composing; +using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; +using Umbraco.Core.Strings; namespace Umbraco.Core { @@ -88,5 +95,163 @@ namespace Umbraco.Core { return userService.GetProfileById(content.WriterId); } + + #region User/Profile methods + + /// + /// Gets the for the Creator of this media item. + /// + public static IProfile GetCreatorProfile(this IMedia media, IUserService userService) + { + return userService.GetProfileById(media.CreatorId); + } + + + #endregion + + /// + /// Checks if the IContentBase has children + /// + /// + /// + /// + /// + /// This is a bit of a hack because we need to type check! + /// + internal static bool HasChildren(IContentBase content, ServiceContext services) + { + if (content is IContent) + { + return services.ContentService.HasChildren(content.Id); + } + if (content is IMedia) + { + return services.MediaService.HasChildren(content.Id); + } + return false; + } + + + /// + /// Returns properties that do not belong to a group + /// + /// + /// + public static IEnumerable GetNonGroupedProperties(this IContentBase content) + { + return content.Properties + .Where(x => x.PropertyType.PropertyGroupId == null) + .OrderBy(x => x.PropertyType.SortOrder); + } + + /// + /// Returns the Property object for the given property group + /// + /// + /// + /// + public static IEnumerable GetPropertiesForGroup(this IContentBase content, PropertyGroup propertyGroup) + { + //get the properties for the current tab + return content.Properties + .Where(property => propertyGroup.PropertyTypes + .Select(propertyType => propertyType.Id) + .Contains(property.PropertyTypeId)); + } + + + #region SetValue for setting file contents + + /// + /// Sets the posted file value of a property. + /// + public static void SetValue(this IContentBase content, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) + { + if (filename == null || filestream == null) return; + + filename = shortStringHelper.CleanStringForSafeFileName(filename); + if (string.IsNullOrWhiteSpace(filename)) return; + filename = filename.ToLower(); + + SetUploadFile(content, mediaFileSystem, contentTypeBaseServiceProvider, propertyTypeAlias, filename, filestream, culture, segment); + } + + private static void SetUploadFile(this IContentBase content, IMediaFileSystem mediaFileSystem, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) + { + var property = GetProperty(content, contentTypeBaseServiceProvider, propertyTypeAlias); + + // Fixes https://github.com/umbraco/Umbraco-CMS/issues/3937 - Assigning a new file to an + // existing IMedia with extension SetValue causes exception 'Illegal characters in path' + string oldpath = null; + if (property.GetValue(culture, segment) is string svalue) + { + if (svalue.DetectIsJson()) + { + // the property value is a JSON serialized image crop data set - grab the "src" property as the file source + var jObject = JsonConvert.DeserializeObject(svalue); + svalue = jObject != null ? jObject.GetValueAsString("src") : svalue; + } + oldpath = mediaFileSystem.GetRelativePath(svalue); + } + + var filepath = mediaFileSystem.StoreFile(content, property.PropertyType, filename, filestream, oldpath); + property.SetValue(mediaFileSystem.GetUrl(filepath), culture, segment); + } + + // gets or creates a property for a content item. + private static IProperty GetProperty(IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias) + { + var property = content.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); + if (property != null) return property; + + var contentType = contentTypeBaseServiceProvider.GetContentTypeOf(content); + var propertyType = contentType.CompositionPropertyTypes + .FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); + if (propertyType == null) + throw new Exception("No property type exists with alias " + propertyTypeAlias + "."); + + property = new Property(propertyType); + content.Properties.Add(property); + return property; + } + + /// + /// Stores a file. + /// + /// A content item. + /// The property alias. + /// The name of the file. + /// A stream containing the file data. + /// The original file path, if any. + /// The path to the file, relative to the media filesystem. + /// + /// Does NOT set the property value, so one should probably store the file and then do + /// something alike: property.Value = MediaHelper.FileSystem.GetUrl(filepath). + /// The original file path is used, in the old media file path scheme, to try and reuse + /// the "folder number" that was assigned to the previous file referenced by the property, + /// if any. + /// + public static string StoreFile(this IContentBase content, IMediaFileSystem mediaFileSystem, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string filepath) + { + var contentType = contentTypeBaseServiceProvider.GetContentTypeOf(content); + var propertyType = contentType + .CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); + if (propertyType == null) throw new ArgumentException("Invalid property type alias " + propertyTypeAlias + "."); + return mediaFileSystem.StoreFile(content, propertyType, filename, filestream, filepath); + } + + #endregion + + + #region Dirty + + public static IEnumerable GetDirtyUserProperties(this IContentBase entity) + { + return entity.Properties.Where(x => x.IsDirty()).Select(x => x.Alias); + } + + + + #endregion } } diff --git a/src/Umbraco.Core/Security/MachineKeyGenerator.cs b/src/Umbraco.Infrastructure/Security/MachineKeyGenerator.cs similarity index 98% rename from src/Umbraco.Core/Security/MachineKeyGenerator.cs rename to src/Umbraco.Infrastructure/Security/MachineKeyGenerator.cs index a20f04c919..60b0ef72c2 100644 --- a/src/Umbraco.Core/Security/MachineKeyGenerator.cs +++ b/src/Umbraco.Infrastructure/Security/MachineKeyGenerator.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Security /// /// Used to generate a machine key /// - internal class MachineKeyGenerator + public class MachineKeyGenerator { /// /// Generates the string to be stored in the web.config diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index 579923744c..5297f7afd6 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.Cache.PublishedCache var publishedShapshot = new PublishedSnapshot( new PublishedContentCache(xmlStore, domainCache, appCache, globalSettings, ContentTypesCache, null, null), new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, appCache, ContentTypesCache, Factory.GetInstance(), umbracoContextAccessor), - new PublishedMemberCache(null, appCache, Current.Services.MemberService, ContentTypesCache), + new PublishedMemberCache(null, appCache, Current.Services.MemberService, ContentTypesCache, Current.Services.UserService), domainCache); var publishedSnapshotService = new Mock(); publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny())).Returns(publishedShapshot); diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs index c9ff68b254..6990ffe8a2 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs @@ -18,13 +18,15 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache private readonly IAppCache _requestCache; private readonly XmlStore _xmlStore; private readonly PublishedContentTypeCache _contentTypeCache; + private readonly IUserService _userService; - public PublishedMemberCache(XmlStore xmlStore, IAppCache requestCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache) + public PublishedMemberCache(XmlStore xmlStore, IAppCache requestCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache, IUserService userService) { _requestCache = requestCache; _memberService = memberService; _xmlStore = xmlStore; _contentTypeCache = contentTypeCache; + _userService = userService; } public IPublishedContent GetByProviderKey(object key) @@ -37,7 +39,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache var result = _memberService.GetByProviderKey(key); if (result == null) return null; var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId); - return new PublishedMember(result, type).CreateModel(Current.PublishedModelFactory); + return new PublishedMember(result, type, _userService).CreateModel(Current.PublishedModelFactory); }); } @@ -51,7 +53,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache var result = _memberService.GetById(memberId); if (result == null) return null; var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId); - return new PublishedMember(result, type).CreateModel(Current.PublishedModelFactory); + return new PublishedMember(result, type, _userService).CreateModel(Current.PublishedModelFactory); }); } @@ -65,7 +67,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache var result = _memberService.GetByUsername(username); if (result == null) return null; var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId); - return new PublishedMember(result, type).CreateModel(Current.PublishedModelFactory); + return new PublishedMember(result, type, _userService).CreateModel(Current.PublishedModelFactory); }); } @@ -79,14 +81,14 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache var result = _memberService.GetByEmail(email); if (result == null) return null; var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId); - return new PublishedMember(result, type).CreateModel(Current.PublishedModelFactory); + return new PublishedMember(result, type, _userService).CreateModel(Current.PublishedModelFactory); }); } public IPublishedContent GetByMember(IMember member) { var type = _contentTypeCache.Get(PublishedItemType.Member, member.ContentTypeId); - return new PublishedMember(member, type).CreateModel(Current.PublishedModelFactory); + return new PublishedMember(member, type, _userService).CreateModel(Current.PublishedModelFactory); } public XPathNavigator CreateNavigator() diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs index aed55f3f49..1447e24522 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs @@ -152,7 +152,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache return new PublishedSnapshot( new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _contentTypeCache, _routesCache, previewToken), new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache, _entitySerializer, _umbracoContextAccessor), - new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache), + new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache, _userService), domainCache); } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index e9f923c029..177561d1ea 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -6,6 +6,7 @@ using Umbraco.Core.PropertyEditors.ValueConverters; using Umbraco.Tests.TestHelpers; using Moq; using Umbraco.Core.Composing; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Web.PropertyEditors; @@ -44,7 +45,7 @@ namespace Umbraco.Tests.PublishedContent var logger = Mock.Of(); var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor); - var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, logger, IOHelper, Mock.Of(), Mock.Of()); + var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, logger, IOHelper, Mock.Of(), Mock.Of(), Mock.Of(), ShortStringHelper); var localLinkParser = new HtmlLocalLinkParser(umbracoContextAccessor); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new RichTextPropertyEditor( diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index 78ef0318af..d08a573917 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -49,10 +49,11 @@ namespace Umbraco.Tests.PublishedContent var logger = Mock.Of(); var mediaService = Mock.Of(); + var mediaFileService = Mock.Of(); var contentTypeBaseServiceProvider = Mock.Of(); var umbracoContextAccessor = Mock.Of(); var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor); - var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, logger, IOHelper, mediaService, contentTypeBaseServiceProvider); + var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, logger, IOHelper, mediaService, contentTypeBaseServiceProvider, mediaFileService, ShortStringHelper); var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor); var localizationService = Mock.Of(); diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index 65c0d561b9..2953c018fc 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -38,6 +38,7 @@ using Umbraco.Web.Editors.Filters; using Umbraco.Core.Models.Entities; using Constants = Umbraco.Core.Constants; using Umbraco.Core.Dictionary; +using Umbraco.Core.Strings; namespace Umbraco.Web.Editors { @@ -50,10 +51,24 @@ namespace Umbraco.Web.Editors [MediaControllerControllerConfiguration] public class MediaController : ContentControllerBase { - public MediaController(ICultureDictionary cultureDictionary, PropertyEditorCollection propertyEditors, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) + public MediaController( + ICultureDictionary cultureDictionary, + PropertyEditorCollection propertyEditors, + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + IMediaFileSystem mediaFileSystem, + IShortStringHelper shortStringHelper) : base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper) { _propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors)); + _mediaFileSystem = mediaFileSystem; + _shortStringHelper = shortStringHelper; } /// @@ -237,6 +252,8 @@ namespace Umbraco.Web.Editors private int[] _userStartNodes; private readonly PropertyEditorCollection _propertyEditors; + private readonly IMediaFileSystem _mediaFileSystem; + private readonly IShortStringHelper _shortStringHelper; protected int[] UserStartNodes { @@ -724,7 +741,7 @@ namespace Umbraco.Web.Editors if (fs == null) throw new InvalidOperationException("Could not acquire file stream"); using (fs) { - f.SetValue(Services.ContentTypeBaseServices, Constants.Conventions.Media.File,fileName, fs); + f.SetValue(_mediaFileSystem, _shortStringHelper, Services.ContentTypeBaseServices, Constants.Conventions.Media.File,fileName, fs); } var saveResult = mediaService.Save(f, Security.CurrentUser.Id); diff --git a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs index 0e43de6410..88b957ad96 100644 --- a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs +++ b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Web.Composing; using Umbraco.Web.Editors; @@ -76,8 +77,8 @@ namespace Umbraco.Web.Macros /// The content. /// /// This is for usage only. - internal PublishedContentHashtableConverter(IContent content, IVariationContextAccessor variationContextAccessor) - : this(new PagePublishedContent(content, variationContextAccessor)) + internal PublishedContentHashtableConverter(IContent content, IVariationContextAccessor variationContextAccessor, IUserService userService) + : this(new PagePublishedContent(content, variationContextAccessor, userService)) { } #endregion @@ -192,15 +193,15 @@ namespace Umbraco.Web.Macros Id = id; } - public PagePublishedContent(IContent inner, IVariationContextAccessor variationContextAccessor) + public PagePublishedContent(IContent inner, IVariationContextAccessor variationContextAccessor, IUserService userService) { _inner = inner ?? throw new NullReferenceException("content"); _variationContextAccessor = variationContextAccessor; Id = _inner.Id; Key = _inner.Key; - CreatorName = _inner.GetCreatorProfile()?.Name; - WriterName = _inner.GetWriterProfile()?.Name; + CreatorName = _inner.GetCreatorProfile(userService)?.Name; + WriterName = _inner.GetWriterProfile(userService)?.Name; // TODO: inject var contentType = Current.Services.ContentTypeBaseServices.GetContentTypeOf(_inner); diff --git a/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs b/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs index 23b3050035..e3fa1ce082 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs @@ -8,6 +8,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Web.Templates; namespace Umbraco.Web.PropertyEditors @@ -19,16 +20,20 @@ namespace Umbraco.Web.PropertyEditors private readonly IIOHelper _ioHelper; private readonly IMediaService _mediaService; private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; + private readonly IMediaFileSystem _mediaFileSystem; + private readonly IShortStringHelper _shortStringHelper; const string TemporaryImageDataAttribute = "data-tmpimg"; - public RichTextEditorPastedImages(IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IIOHelper ioHelper, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + public RichTextEditorPastedImages(IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IIOHelper ioHelper, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _ioHelper = ioHelper; _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider ?? throw new ArgumentNullException(nameof(contentTypeBaseServiceProvider)); + _mediaFileSystem = mediaFileSystem; + _shortStringHelper = shortStringHelper; } /// @@ -82,7 +87,7 @@ namespace Umbraco.Web.PropertyEditors if (fileStream == null) throw new InvalidOperationException("Could not acquire file stream"); using (fileStream) { - mediaFile.SetValue(_contentTypeBaseServiceProvider, Constants.Conventions.Media.File, safeFileName, fileStream); + mediaFile.SetValue(_mediaFileSystem, _shortStringHelper, _contentTypeBaseServiceProvider, Constants.Conventions.Media.File, safeFileName, fileStream); } _mediaService.Save(mediaFile, userId); diff --git a/src/Umbraco.Web/PublishedCache/PublishedMember.cs b/src/Umbraco.Web/PublishedCache/PublishedMember.cs index 2c3ba1d7ea..ed8e3bd7cf 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedMember.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedMember.cs @@ -5,6 +5,7 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.Services; using Umbraco.Web.Models; namespace Umbraco.Web.PublishedCache @@ -18,14 +19,17 @@ namespace Umbraco.Web.PublishedCache private readonly IMembershipUser _membershipUser; private readonly IPublishedProperty[] _properties; private readonly IPublishedContentType _publishedMemberType; + private readonly IUserService _userService; public PublishedMember( IMember member, - IPublishedContentType publishedMemberType) + IPublishedContentType publishedMemberType, + IUserService userService) { _member = member ?? throw new ArgumentNullException(nameof(member)); _membershipUser = member; _publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType)); + _userService = userService ?? throw new ArgumentNullException(nameof(userService)); // RawValueProperty is used for two things here // - for the 'map properties' thing that we should really get rid of @@ -136,11 +140,9 @@ namespace Umbraco.Web.PublishedCache public override string UrlSegment => throw new NotSupportedException(); - // TODO: ARGH! need to fix this - this is not good because it uses ApplicationContext.Current - public override string WriterName => _member.GetCreatorProfile().Name; + public override string WriterName => _member.GetCreatorProfile(_userService).Name; - // TODO: ARGH! need to fix this - this is not good because it uses ApplicationContext.Current - public override string CreatorName => _member.GetCreatorProfile().Name; + public override string CreatorName => _member.GetCreatorProfile(_userService).Name; public override int WriterId => _member.CreatorId;