From ee3615e36d2162cfe0e594c9384b5b902b2e6145 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 25 May 2020 13:41:05 +0200 Subject: [PATCH] https://dev.azure.com/umbraco/D-Team%20Tracker/_workitems/edit/6587 - Moved controllers: TagsDataController, RteEmbedController, RichTextPreValueController, NestedContentController, WebProfilingController + Moved compose of MapDefinitionCollectionBuilder into core, and uncommented missing map definitions --- .../Mapping/ContentPropertyMapDefinition.cs | 2 +- .../CoreMappingProfiles.cs | 23 ++++++++ .../UmbracoApplicationAuthorizeAttribute.cs | 55 +++++++++++++++++++ .../Profiling/WebProfilingController.cs | 28 ++++++++++ .../NestedContentController.cs | 16 ++++-- .../RichTextPreValueController.cs | 35 +++--------- .../PropertyEditors/RteEmbedController.cs | 11 ++-- .../PropertyEditors/TagsDataController.cs | 6 +- .../Config}/tinyMceConfig.Release.config | 0 .../Config}/tinyMceConfig.config | 0 .../Umbraco.Web.UI.NetCore.csproj | 8 ++- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 7 --- .../Editors/BackOfficeServerVariables.cs | 47 ++++++++-------- .../Profiling/WebProfilingController.cs | 48 ---------------- src/Umbraco.Web/Umbraco.Web.csproj | 6 -- 15 files changed, 165 insertions(+), 127 deletions(-) create mode 100644 src/Umbraco.Web.BackOffice/Filters/UmbracoApplicationAuthorizeAttribute.cs create mode 100644 src/Umbraco.Web.BackOffice/Profiling/WebProfilingController.cs rename src/{Umbraco.Web => Umbraco.Web.BackOffice}/PropertyEditors/NestedContentController.cs (64%) rename src/{Umbraco.Web => Umbraco.Web.BackOffice}/PropertyEditors/RichTextPreValueController.cs (80%) rename src/{Umbraco.Web => Umbraco.Web.BackOffice}/PropertyEditors/RteEmbedController.cs (82%) rename src/{Umbraco.Web => Umbraco.Web.BackOffice}/PropertyEditors/TagsDataController.cs (92%) rename src/{Umbraco.Web.UI/config => Umbraco.Web.UI.NetCore/Config}/tinyMceConfig.Release.config (100%) rename src/{Umbraco.Web.UI/config => Umbraco.Web.UI.NetCore/Config}/tinyMceConfig.config (100%) delete mode 100644 src/Umbraco.Web/Profiling/WebProfilingController.cs diff --git a/src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs index d55791f068..c5b989e39c 100644 --- a/src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs +++ b/src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs @@ -12,7 +12,7 @@ namespace Umbraco.Web.Models.Mapping /// A mapper which declares how to map content properties. These mappings are shared among media (and probably members) which is /// why they are in their own mapper /// - internal class ContentPropertyMapDefinition : IMapDefinition + public class ContentPropertyMapDefinition : IMapDefinition { private readonly ContentPropertyBasicMapper _contentPropertyBasicConverter; private readonly ContentPropertyDtoMapper _contentPropertyDtoConverter; diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs index 9835d17fb6..3a980fb7cf 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Mapping; +using Umbraco.Web.Models.Mapping; namespace Umbraco.Core.Composing.CompositionExtensions @@ -9,6 +10,28 @@ namespace Umbraco.Core.Composing.CompositionExtensions { composition.RegisterUnique(); + composition.WithCollectionBuilder() + .Add() + .Add() + //.Add() //TODO Add these + .Add() + .Add() + .Add() + .Add() + .Add() + .Add() + // .Add() //TODO Add these + // .Add() //TODO Add these + .Add() + .Add() + .Add() + .Add() + .Add() + .Add() + .Add() + // .Add() //TODO Add these + ; + return composition; } } diff --git a/src/Umbraco.Web.BackOffice/Filters/UmbracoApplicationAuthorizeAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/UmbracoApplicationAuthorizeAttribute.cs new file mode 100644 index 0000000000..88a4c4f8ff --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Filters/UmbracoApplicationAuthorizeAttribute.cs @@ -0,0 +1,55 @@ +using System; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.DependencyInjection; +using Umbraco.Core; + +namespace Umbraco.Web.BackOffice.Filters +{ + public class UmbracoApplicationAuthorizeAttribute : Attribute, IAuthorizationFilter + { + /// + /// Can be used by unit tests to enable/disable this filter + /// + internal static bool Enable = true; + + private readonly string[] _appNames; + + /// + /// Constructor to set any number of applications that the user needs access to be authorized + /// + /// + /// If the user has access to any of the specified apps, they will be authorized. + /// + public UmbracoApplicationAuthorizeAttribute(params string[] appName) + { + _appNames = appName; + } + + + public void OnAuthorization(AuthorizationFilterContext context) + { + var umbracoContextAccessor = context.HttpContext.RequestServices.GetRequiredService(); + if (!IsAuthorized(umbracoContextAccessor)) + { + context.Result = new ForbidResult(); + } + } + + private bool IsAuthorized(IUmbracoContextAccessor umbracoContextAccessor) + { + if (Enable == false) + { + return true; + } + + var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext(); + var authorized = umbracoContext.Security.CurrentUser != null + && _appNames.Any(app => umbracoContext.Security.UserHasSectionAccess( + app, umbracoContext.Security.CurrentUser)); + + return authorized; + } + } +} diff --git a/src/Umbraco.Web.BackOffice/Profiling/WebProfilingController.cs b/src/Umbraco.Web.BackOffice/Profiling/WebProfilingController.cs new file mode 100644 index 0000000000..a053c28d42 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Profiling/WebProfilingController.cs @@ -0,0 +1,28 @@ +using Umbraco.Core.Hosting; +using Umbraco.Web.BackOffice.Filters; +using Umbraco.Web.Editors; + + +namespace Umbraco.Web.BackOffice.Profiling +{ + /// + /// The API controller used to display the state of the web profiler + /// + [UmbracoApplicationAuthorizeAttribute(Core.Constants.Applications.Settings)] + public class WebProfilingController : UmbracoAuthorizedJsonController + { + private readonly IHostingEnvironment _hosting; + + public WebProfilingController(IHostingEnvironment hosting) + { + _hosting = hosting; + } + + public object GetStatus() + { + return new + { + Enabled = _hosting.IsDebugMode + }; + } + }} diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentController.cs b/src/Umbraco.Web.BackOffice/PropertyEditors/NestedContentController.cs similarity index 64% rename from src/Umbraco.Web/PropertyEditors/NestedContentController.cs rename to src/Umbraco.Web.BackOffice/PropertyEditors/NestedContentController.cs index 590a286c5d..17184dad5e 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentController.cs +++ b/src/Umbraco.Web.BackOffice/PropertyEditors/NestedContentController.cs @@ -1,18 +1,26 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.AspNetCore.Mvc; using Umbraco.Core.Services; +using Umbraco.Web.Common.Attributes; using Umbraco.Web.Editors; -using Umbraco.Web.Mvc; -namespace Umbraco.Web.PropertyEditors +namespace Umbraco.Web.BackOffice.PropertyEditors { [PluginController("UmbracoApi")] public class NestedContentController : UmbracoAuthorizedJsonController { - [System.Web.Http.HttpGet] + private readonly IContentTypeService _contentTypeService; + + public NestedContentController(IContentTypeService contentTypeService) + { + _contentTypeService = contentTypeService; + } + + [HttpGet] public IEnumerable GetContentTypes() { - return Services.ContentTypeService + return _contentTypeService .GetAllElementTypes() .OrderBy(x => x.SortOrder) .Select(x => new diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPreValueController.cs b/src/Umbraco.Web.BackOffice/PropertyEditors/RichTextPreValueController.cs similarity index 80% rename from src/Umbraco.Web/PropertyEditors/RichTextPreValueController.cs rename to src/Umbraco.Web.BackOffice/PropertyEditors/RichTextPreValueController.cs index e7ed10c8bf..fb5f9c0a42 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPreValueController.cs +++ b/src/Umbraco.Web.BackOffice/PropertyEditors/RichTextPreValueController.cs @@ -1,21 +1,13 @@ using System.Collections.Generic; using System.Xml; using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; -using Umbraco.Web.Composing; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; -using Umbraco.Core.Logging; -using Umbraco.Core.Persistence; -using Umbraco.Core.Services; -using Umbraco.Core.Strings; using Umbraco.Web.Editors; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Mvc; -using Umbraco.Core.Mapping; -using Umbraco.Web.Routing; +using Umbraco.Web.Common.Attributes; -namespace Umbraco.Web.PropertyEditors +namespace Umbraco.Web.BackOffice.PropertyEditors { /// /// ApiController to provide RTE configuration with available plugins and commands from the RTE config @@ -23,24 +15,11 @@ namespace Umbraco.Web.PropertyEditors [PluginController("UmbracoApi")] public class RichTextPreValueController : UmbracoAuthorizedJsonController { - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; - public RichTextPreValueController( - IGlobalSettings globalSettings, - IUmbracoContextAccessor umbracoContextAccessor, - ISqlContext sqlContext, - ServiceContext services, - AppCaches appCaches, - IProfilingLogger logger, - IRuntimeState runtimeState, - IShortStringHelper shortStringHelper, - IIOHelper ioHelper, - UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider - ) - : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, shortStringHelper, umbracoMapper, publishedUrlProvider) + public RichTextPreValueController(IHostingEnvironment hostingEnvironment) { - _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; } private static volatile bool _init; @@ -79,7 +58,7 @@ namespace Umbraco.Web.PropertyEditors { // Load config XmlDocument xd = new XmlDocument(); - xd.Load(_ioHelper.MapPath(SystemFiles.TinyMceConfig)); + xd.Load(_hostingEnvironment.MapPathContentRoot(SystemFiles.TinyMceConfig)); foreach (XmlNode n in xd.DocumentElement.SelectNodes("//command")) { diff --git a/src/Umbraco.Web/PropertyEditors/RteEmbedController.cs b/src/Umbraco.Web.BackOffice/PropertyEditors/RteEmbedController.cs similarity index 82% rename from src/Umbraco.Web/PropertyEditors/RteEmbedController.cs rename to src/Umbraco.Web.BackOffice/PropertyEditors/RteEmbedController.cs index b3498c16ae..242cdc895e 100644 --- a/src/Umbraco.Web/PropertyEditors/RteEmbedController.cs +++ b/src/Umbraco.Web.BackOffice/PropertyEditors/RteEmbedController.cs @@ -4,9 +4,10 @@ using Umbraco.Core.Logging; using Umbraco.Web.Editors; using Umbraco.Web.Mvc; using Umbraco.Core.Media; +using Umbraco.Web.Common.Attributes; using Umbraco.Web.Media.EmbedProviders; -namespace Umbraco.Web.PropertyEditors +namespace Umbraco.Web.BackOffice.PropertyEditors { /// /// A controller used for the embed dialog @@ -14,11 +15,13 @@ namespace Umbraco.Web.PropertyEditors [PluginController("UmbracoApi")] public class RteEmbedController : UmbracoAuthorizedJsonController { - private EmbedProvidersCollection _embedCollection; + private readonly EmbedProvidersCollection _embedCollection; + private readonly ILogger _logger; - public RteEmbedController(EmbedProvidersCollection embedCollection) + public RteEmbedController(EmbedProvidersCollection embedCollection, ILogger logger) { _embedCollection = embedCollection ?? throw new ArgumentNullException(nameof(embedCollection)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } public OEmbedResult GetEmbed(string url, int width, int height) @@ -60,7 +63,7 @@ namespace Umbraco.Web.PropertyEditors } catch(Exception ex) { - Logger.Error(ex, "Error embedding url {Url} - width: {Width} height: {Height}", url, width, height); + _logger.Error(ex, "Error embedding url {Url} - width: {Width} height: {Height}", url, width, height); result.OEmbedStatus = OEmbedStatus.Error; } diff --git a/src/Umbraco.Web/PropertyEditors/TagsDataController.cs b/src/Umbraco.Web.BackOffice/PropertyEditors/TagsDataController.cs similarity index 92% rename from src/Umbraco.Web/PropertyEditors/TagsDataController.cs rename to src/Umbraco.Web.BackOffice/PropertyEditors/TagsDataController.cs index 9cb00090e3..37dbd84bfc 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsDataController.cs +++ b/src/Umbraco.Web.BackOffice/PropertyEditors/TagsDataController.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Core; +using Umbraco.Web.BackOffice.Controllers; +using Umbraco.Web.Common.Attributes; using Umbraco.Web.Models; -using Umbraco.Web.Mvc; -using Umbraco.Web.WebApi; -namespace Umbraco.Web.PropertyEditors +namespace Umbraco.Web.BackOffice.PropertyEditors { /// /// A controller used for type-ahead values for tags diff --git a/src/Umbraco.Web.UI/config/tinyMceConfig.Release.config b/src/Umbraco.Web.UI.NetCore/Config/tinyMceConfig.Release.config similarity index 100% rename from src/Umbraco.Web.UI/config/tinyMceConfig.Release.config rename to src/Umbraco.Web.UI.NetCore/Config/tinyMceConfig.Release.config diff --git a/src/Umbraco.Web.UI/config/tinyMceConfig.config b/src/Umbraco.Web.UI.NetCore/Config/tinyMceConfig.config similarity index 100% rename from src/Umbraco.Web.UI/config/tinyMceConfig.config rename to src/Umbraco.Web.UI.NetCore/Config/tinyMceConfig.config diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj index 219b819b11..d77d9b483c 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -13,7 +13,6 @@ - @@ -29,6 +28,10 @@ + + tinyMceConfig.config + Designer + @@ -46,6 +49,9 @@ true PreserveNewest + + Designer + diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 8c0b98787c..7e2d1c209f 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -200,10 +200,6 @@ umbracoSettings.config Designer - - tinyMceConfig.config - Designer - @@ -293,9 +289,6 @@ Designer - - Designer - Designer diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 6441f6ad6a..9c10479f3b 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -5,21 +5,16 @@ using System.Linq; using System.Runtime.Serialization; using System.Web; using System.Web.Mvc; -using Microsoft.Owin.Security; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Web.Features; using Umbraco.Web.HealthCheck; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Mvc; -using Umbraco.Web.Profiling; -using Umbraco.Web.PropertyEditors; using Umbraco.Web.Trees; using Constants = Umbraco.Core.Constants; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; -using Umbraco.Core.Runtime; using Umbraco.Core.WebAssets; using Umbraco.Web.Security; @@ -151,10 +146,11 @@ namespace Umbraco.Web.Editors // "tourApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( // controller => controller.GetTours()) // }, - { - "embedApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( - controller => controller.GetEmbed("", 0, 0)) - }, + //TODO reintroduce + // { + // "embedApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( + // controller => controller.GetEmbed("", 0, 0)) + // }, { "userApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.PostSaveUser(null)) @@ -241,10 +237,10 @@ namespace Umbraco.Web.Editors "relationApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.GetById(0)) }, - { - "rteApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( - controller => controller.GetConfiguration()) - }, + // { + // "rteApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( + // controller => controller.GetConfiguration()) + // }, { "stylesheetApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.GetAll()) @@ -277,10 +273,10 @@ namespace Umbraco.Web.Editors "contentTreeBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.GetNodes("-1", null)) }, - { - "tagsDataBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( - controller => controller.GetTags("", "", null)) - }, + // { + // "tagsDataBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( + // controller => controller.GetTags("", "", null)) + // }, //TODO reintroduce // { // "examineMgmtBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( @@ -294,10 +290,11 @@ namespace Umbraco.Web.Editors "templateQueryApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.PostTemplateQuery(null)) }, - { - "codeFileApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( - controller => controller.GetByPath("", "")) - }, + //TODO Reintroduce + // { + // "codeFileApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( + // controller => controller.GetByPath("", "")) + // }, { "publishedStatusBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.GetPublishedStatusUrl()) @@ -332,10 +329,10 @@ namespace Umbraco.Web.Editors "logViewerApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.GetNumberOfErrors(null, null)) }, - { - "webProfilingBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( - controller => controller.GetStatus()) - }, + // { + // "webProfilingBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( + // controller => controller.GetStatus()) + // }, { "tinyMceApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( controller => controller.UploadImage()) diff --git a/src/Umbraco.Web/Profiling/WebProfilingController.cs b/src/Umbraco.Web/Profiling/WebProfilingController.cs deleted file mode 100644 index d8f71b5c85..0000000000 --- a/src/Umbraco.Web/Profiling/WebProfilingController.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Configuration; -using Umbraco.Core.Hosting; -using Umbraco.Core.Logging; -using Umbraco.Core.Mapping; -using Umbraco.Core.Persistence; -using Umbraco.Core.Services; -using Umbraco.Core.Strings; -using Umbraco.Web.Editors; -using Umbraco.Web.Routing; -using Umbraco.Web.WebApi.Filters; - -namespace Umbraco.Web.Profiling -{ - /// - /// The API controller used to display the state of the web profiler - /// - [UmbracoApplicationAuthorize(Core.Constants.Applications.Settings)] - public class WebProfilingController : UmbracoAuthorizedJsonController - { - private readonly IHostingEnvironment _hosting; - - public WebProfilingController( - IGlobalSettings globalSettings, - IUmbracoContextAccessor umbracoContextAccessor, - ISqlContext sqlContext, - ServiceContext services, - AppCaches appCaches, - IProfilingLogger logger, - IRuntimeState runtimeState, - IShortStringHelper shortStringHelper, - UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider, - IHostingEnvironment hosting) - : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, shortStringHelper, umbracoMapper, publishedUrlProvider) - { - _hosting = hosting; - } - - public object GetStatus() - { - return new - { - Enabled = _hosting.IsDebugMode - }; - } - }} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index c747d5f19b..1a85afc609 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -193,7 +193,6 @@ - @@ -250,7 +249,6 @@ - @@ -276,7 +274,6 @@ - @@ -355,7 +352,6 @@ - @@ -365,11 +361,9 @@ - -