From cd48adc7afcea68efad39b8808a5d745cec234f9 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 12 May 2020 20:28:40 +0200 Subject: [PATCH] AB6455 - Stub'ed WebSecurity, cleanup and fix issue with content root vs web root --- .../Configuration/Grid/GridConfig.cs | 8 +++---- .../Configuration/Grid/GridEditorsConfig.cs | 22 +++++++++---------- .../Security/WebSecurity.cs | 19 ++++++++-------- .../Config}/grid.editors.config.js | 0 .../Umbraco.Web.UI.NetCore.csproj | 1 + src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 1 - .../Controllers/SurfaceController.cs | 3 +++ 7 files changed, 28 insertions(+), 26 deletions(-) rename src/{Umbraco.Web.UI/config => Umbraco.Web.UI.NetCore/Config}/grid.editors.config.js (100%) diff --git a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridConfig.cs index 72c720e3d6..363dc7b048 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridConfig.cs @@ -1,7 +1,5 @@ -using System.IO; -using Umbraco.Core.Cache; +using Umbraco.Core.Cache; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; using Umbraco.Core.Serialization; @@ -10,9 +8,9 @@ namespace Umbraco.Core.Configuration.Grid { public class GridConfig : IGridConfig { - public GridConfig(AppCaches appCaches, IIOHelper ioHelper, IManifestParser manifestParser, IJsonSerializer jsonSerializer, IHostingEnvironment hostingEnvironment) + public GridConfig(AppCaches appCaches, IManifestParser manifestParser, IJsonSerializer jsonSerializer, IHostingEnvironment hostingEnvironment, ILogger logger) { - EditorsConfig = new GridEditorsConfig(appCaches, ioHelper, manifestParser, jsonSerializer, hostingEnvironment.IsDebugMode); + EditorsConfig = new GridEditorsConfig(appCaches, hostingEnvironment, manifestParser, jsonSerializer, logger); } public IGridEditorsConfig EditorsConfig { get; } diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs index 410c83ff1a..6cf985fecb 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.IO; -using Umbraco.Composing; using Umbraco.Core.Cache; -using Umbraco.Core.IO; +using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; using Umbraco.Core.PropertyEditors; @@ -14,18 +13,19 @@ namespace Umbraco.Core.Configuration.Grid internal class GridEditorsConfig : IGridEditorsConfig { private readonly AppCaches _appCaches; - private readonly IIOHelper _ioHelper; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IManifestParser _manifestParser; - private readonly bool _isDebug; - private readonly IJsonSerializer _jsonSerializer; - public GridEditorsConfig(AppCaches appCaches, IIOHelper ioHelper, IManifestParser manifestParser,IJsonSerializer jsonSerializer, bool isDebug) + private readonly IJsonSerializer _jsonSerializer; + private readonly ILogger _logger; + + public GridEditorsConfig(AppCaches appCaches, IHostingEnvironment hostingEnvironment, IManifestParser manifestParser,IJsonSerializer jsonSerializer, ILogger logger) { _appCaches = appCaches; - _ioHelper = ioHelper; + _hostingEnvironment = hostingEnvironment; _manifestParser = manifestParser; _jsonSerializer = jsonSerializer; - _isDebug = isDebug; + _logger = logger; } public IEnumerable Editors @@ -34,7 +34,7 @@ namespace Umbraco.Core.Configuration.Grid { List GetResult() { - var configFolder = new DirectoryInfo(_ioHelper.MapPath(Constants.SystemDirectories.Config)); + var configFolder = new DirectoryInfo(_hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Config)); var editors = new List(); var gridConfig = Path.Combine(configFolder.FullName, "grid.editors.config.js"); if (File.Exists(gridConfig)) @@ -47,7 +47,7 @@ namespace Umbraco.Core.Configuration.Grid } catch (Exception ex) { - Current.Logger.Error(ex, "Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", sourceString); + _logger.Error(ex, "Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", sourceString); } } @@ -61,7 +61,7 @@ namespace Umbraco.Core.Configuration.Grid } //cache the result if debugging is disabled - var result = _isDebug + var result = _hostingEnvironment.IsDebugMode ? GetResult() : _appCaches.RuntimeCache.GetCacheItem>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10)); diff --git a/src/Umbraco.Web.Common/Security/WebSecurity.cs b/src/Umbraco.Web.Common/Security/WebSecurity.cs index 5f54d2e9ee..e87720dc86 100644 --- a/src/Umbraco.Web.Common/Security/WebSecurity.cs +++ b/src/Umbraco.Web.Common/Security/WebSecurity.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Models.Membership; using Umbraco.Web.Security; @@ -11,46 +12,46 @@ namespace Umbraco.Web.Common.Security public class WebSecurity : IWebSecurity { - public IUser CurrentUser => throw new NotImplementedException(); + public IUser CurrentUser => new User(Current.Configs.Global()); public ValidateRequestAttempt AuthorizeRequest(bool throwExceptions = false) { - throw new NotImplementedException(); + return ValidateRequestAttempt.Success; } public void ClearCurrentLogin() { - throw new NotImplementedException(); + //throw new NotImplementedException(); } public Attempt GetUserId() { - throw new NotImplementedException(); + return Attempt.Succeed(-1); } public bool IsAuthenticated() { - throw new NotImplementedException(); + return true; } public double PerformLogin(int userId) { - throw new NotImplementedException(); + return 100; } public bool UserHasSectionAccess(string section, IUser user) { - throw new NotImplementedException(); + return true; } public bool ValidateCurrentUser() { - throw new NotImplementedException(); + return true; } public ValidateRequestAttempt ValidateCurrentUser(bool throwExceptions, bool requiresApproval = true) { - throw new NotImplementedException(); + return ValidateRequestAttempt.Success; } } } diff --git a/src/Umbraco.Web.UI/config/grid.editors.config.js b/src/Umbraco.Web.UI.NetCore/Config/grid.editors.config.js similarity index 100% rename from src/Umbraco.Web.UI/config/grid.editors.config.js rename to src/Umbraco.Web.UI.NetCore/Config/grid.editors.config.js 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 966cb9c86e..8e5df46c55 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -63,6 +63,7 @@ + diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 5e66765379..8c0b98787c 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -142,7 +142,6 @@ True Settings.settings - diff --git a/src/Umbraco.Web.Website/Controllers/SurfaceController.cs b/src/Umbraco.Web.Website/Controllers/SurfaceController.cs index 2f2984cf21..161fe1750f 100644 --- a/src/Umbraco.Web.Website/Controllers/SurfaceController.cs +++ b/src/Umbraco.Web.Website/Controllers/SurfaceController.cs @@ -15,6 +15,9 @@ namespace Umbraco.Web.Website.Controllers /// /// Provides a base class for front-end add-in controllers. /// + // TODO: Migrate MergeModelStateToChildAction and MergeParentContextViewData action filters + // [MergeModelStateToChildAction] + // [MergeParentContextViewData] public abstract class SurfaceController : PluginController { private readonly IPublishedUrlProvider _publishedUrlProvider;