diff --git a/src/Umbraco.Cms.Api.Common/OpenApi/SubTypesSelector.cs b/src/Umbraco.Cms.Api.Common/OpenApi/SubTypesSelector.cs index c6e172f3f74b..947e7a8197ef 100644 --- a/src/Umbraco.Cms.Api.Common/OpenApi/SubTypesSelector.cs +++ b/src/Umbraco.Cms.Api.Common/OpenApi/SubTypesSelector.cs @@ -10,12 +10,12 @@ namespace Umbraco.Cms.Api.Common.OpenApi; public class SubTypesSelector : ISubTypesSelector { - private readonly IOptions _settings; private readonly IHostingEnvironment _hostingEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IEnumerable _subTypeHandlers; private readonly IUmbracoJsonTypeInfoResolver _umbracoJsonTypeInfoResolver; + [Obsolete("The settings parameter is not required anymore, use the other constructor instead. Scheduled for removal in Umbraco 17.")] public SubTypesSelector( IOptions settings, IHostingEnvironment hostingEnvironment, @@ -23,7 +23,18 @@ public SubTypesSelector( IEnumerable subTypeHandlers, IUmbracoJsonTypeInfoResolver umbracoJsonTypeInfoResolver) { - _settings = settings; + _hostingEnvironment = hostingEnvironment; + _httpContextAccessor = httpContextAccessor; + _subTypeHandlers = subTypeHandlers; + _umbracoJsonTypeInfoResolver = umbracoJsonTypeInfoResolver; + } + + public SubTypesSelector( + IHostingEnvironment hostingEnvironment, + IHttpContextAccessor httpContextAccessor, + IEnumerable subTypeHandlers, + IUmbracoJsonTypeInfoResolver umbracoJsonTypeInfoResolver) + { _hostingEnvironment = hostingEnvironment; _httpContextAccessor = httpContextAccessor; _subTypeHandlers = subTypeHandlers; @@ -32,7 +43,7 @@ public SubTypesSelector( public IEnumerable SubTypes(Type type) { - var backOfficePath = _settings.Value.GetBackOfficePath(_hostingEnvironment); + var backOfficePath = _hostingEnvironment.GetBackOfficePath(); var swaggerPath = $"{backOfficePath}/swagger"; if (_httpContextAccessor.HttpContext?.Request.Path.StartsWithSegments(swaggerPath) ?? false) diff --git a/src/Umbraco.Cms.Api.Common/OpenApi/SwaggerRouteTemplatePipelineFilter.cs b/src/Umbraco.Cms.Api.Common/OpenApi/SwaggerRouteTemplatePipelineFilter.cs index 9f05f57d5a5e..dba0e6f56d01 100644 --- a/src/Umbraco.Cms.Api.Common/OpenApi/SwaggerRouteTemplatePipelineFilter.cs +++ b/src/Umbraco.Cms.Api.Common/OpenApi/SwaggerRouteTemplatePipelineFilter.cs @@ -7,7 +7,7 @@ using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerUI; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Web.Common.ApplicationBuilder; using Umbraco.Extensions; using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; @@ -30,24 +30,21 @@ private void PostPipelineAction(IApplicationBuilder applicationBuilder) IOptions swaggerGenOptions = applicationBuilder.ApplicationServices.GetRequiredService>(); applicationBuilder.UseSwagger(swaggerOptions => - { - swaggerOptions.RouteTemplate = SwaggerRouteTemplate(applicationBuilder); - }); + { + swaggerOptions.RouteTemplate = SwaggerRouteTemplate(applicationBuilder); + }); applicationBuilder.UseSwaggerUI(swaggerUiOptions => SwaggerUiConfiguration(swaggerUiOptions, swaggerGenOptions.Value, applicationBuilder)); } protected virtual bool SwaggerIsEnabled(IApplicationBuilder applicationBuilder) - { - IWebHostEnvironment webHostEnvironment = applicationBuilder.ApplicationServices.GetRequiredService(); - return webHostEnvironment.IsProduction() is false; - } + => applicationBuilder.ApplicationServices.GetRequiredService().IsProduction() is false; protected virtual string SwaggerRouteTemplate(IApplicationBuilder applicationBuilder) - => $"{GetUmbracoPath(applicationBuilder).TrimStart(Constants.CharArrays.ForwardSlash)}/swagger/{{documentName}}/swagger.json"; + => $"{GetBackOfficePath(applicationBuilder).TrimStart(Constants.CharArrays.ForwardSlash)}/swagger/{{documentName}}/swagger.json"; protected virtual string SwaggerUiRoutePrefix(IApplicationBuilder applicationBuilder) - => $"{GetUmbracoPath(applicationBuilder).TrimStart(Constants.CharArrays.ForwardSlash)}/swagger"; + => $"{GetBackOfficePath(applicationBuilder).TrimStart(Constants.CharArrays.ForwardSlash)}/swagger"; protected virtual void SwaggerUiConfiguration( SwaggerUIOptions swaggerUiOptions, @@ -56,8 +53,7 @@ protected virtual void SwaggerUiConfiguration( { swaggerUiOptions.RoutePrefix = SwaggerUiRoutePrefix(applicationBuilder); - foreach ((var name, OpenApiInfo? apiInfo) in swaggerGenOptions.SwaggerGeneratorOptions.SwaggerDocs - .OrderBy(x => x.Value.Title)) + foreach ((var name, OpenApiInfo? apiInfo) in swaggerGenOptions.SwaggerGeneratorOptions.SwaggerDocs.OrderBy(x => x.Value.Title)) { swaggerUiOptions.SwaggerEndpoint($"{name}/swagger.json", $"{apiInfo.Title}"); } @@ -70,11 +66,6 @@ protected virtual void SwaggerUiConfiguration( swaggerUiOptions.OAuthUsePkce(); } - private string GetUmbracoPath(IApplicationBuilder applicationBuilder) - { - GlobalSettings settings = applicationBuilder.ApplicationServices.GetRequiredService>().Value; - IHostingEnvironment hostingEnvironment = applicationBuilder.ApplicationServices.GetRequiredService(); - - return settings.GetBackOfficePath(hostingEnvironment); - } + private string GetBackOfficePath(IApplicationBuilder applicationBuilder) + => applicationBuilder.ApplicationServices.GetRequiredService().GetBackOfficePath(); } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs b/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs index c6ff576b93d3..0416e5c303dd 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs @@ -24,7 +24,7 @@ public class BackOfficeLoginModel public bool UserIsAlreadyLoggedIn { get; set; } } -[ApiExplorerSettings(IgnoreApi=true)] +[ApiExplorerSettings(IgnoreApi = true)] [Route(LoginPath)] public class BackOfficeLoginController : Controller { @@ -51,7 +51,7 @@ public async Task Index(CancellationToken cancellationToken, Back if (string.IsNullOrEmpty(model.UmbracoUrl)) { - model.UmbracoUrl = _hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath); + model.UmbracoUrl = _hostingEnvironment.GetBackOfficePath(); } if (string.IsNullOrEmpty(model.ReturnUrl)) diff --git a/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs b/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs index 870c4d3e1ede..7a3394ad5df3 100644 --- a/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs +++ b/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -6,9 +6,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Options; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.Hosting; using Umbraco.Extensions; using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; @@ -20,14 +19,10 @@ internal static IApplicationBuilder UseProblemDetailsExceptionHandling(this IApp => applicationBuilder.UseWhen( httpContext => { - GlobalSettings settings = httpContext.RequestServices - .GetRequiredService>().Value; - IHostingEnvironment hostingEnvironment = - httpContext.RequestServices.GetRequiredService(); - var officePath = settings.GetBackOfficePath(hostingEnvironment); + var backOfficePath = httpContext.RequestServices.GetRequiredService().GetBackOfficePath(); // Only use the API exception handler when we are requesting an API - return httpContext.Request.Path.Value?.StartsWith($"{officePath}{Constants.Web.ManagementApiPath}") ?? false; + return httpContext.Request.Path.Value?.StartsWith($"{backOfficePath}{Constants.Web.ManagementApiPath}") ?? false; }, innerBuilder => { @@ -58,14 +53,13 @@ internal static IApplicationBuilder UseEndpoints(this IApplicationBuilder applic applicationBuilder.UseEndpoints(endpoints => { - GlobalSettings settings = provider.GetRequiredService>().Value; - IHostingEnvironment hostingEnvironment = provider.GetRequiredService(); - var officePath = settings.GetBackOfficePath(hostingEnvironment); + var backOfficePath = provider.GetRequiredService().GetBackOfficePath(); + // Maps attribute routed controllers. endpoints.MapControllers(); // Serve contract - endpoints.MapGet($"{officePath}{Constants.Web.ManagementApiPath}openapi.json", async context => + endpoints.MapGet($"{backOfficePath}{Constants.Web.ManagementApiPath}openapi.json", async context => { await context.Response.SendFileAsync(new EmbeddedFileProvider(typeof(ManagementApiComposer).Assembly).GetFileInfo("OpenApi.json")); }); diff --git a/src/Umbraco.Cms.Api.Management/Routing/BackOfficeAreaRoutes.cs b/src/Umbraco.Cms.Api.Management/Routing/BackOfficeAreaRoutes.cs index ed246fd058a1..778dbf691f12 100644 --- a/src/Umbraco.Cms.Api.Management/Routing/BackOfficeAreaRoutes.cs +++ b/src/Umbraco.Cms.Api.Management/Routing/BackOfficeAreaRoutes.cs @@ -1,12 +1,8 @@ -using System.Text; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; -using Microsoft.Extensions.Options; using Umbraco.Cms.Api.Management.Controllers.Security; using Umbraco.Cms.Api.Management.ServerEvents; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Web.Common.Routing; using Umbraco.Extensions; @@ -14,53 +10,28 @@ namespace Umbraco.Cms.Api.Management.Routing; /// -/// Creates routes for the back office area +/// Creates routes for the back office area. /// public sealed class BackOfficeAreaRoutes : IAreaRoutes { private readonly IRuntimeState _runtimeState; - private readonly string _umbracoPathSegment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public BackOfficeAreaRoutes( - IOptions globalSettings, - IHostingEnvironment hostingEnvironment, - IRuntimeState runtimeState) - { - _runtimeState = runtimeState; - _umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment); - } + public BackOfficeAreaRoutes(IRuntimeState runtimeState) + => _runtimeState = runtimeState; - [Obsolete("Use non-obsolete constructor. Scheduled for removal in Umbraco 16.")] - public BackOfficeAreaRoutes( - IOptions globalSettings, - IHostingEnvironment hostingEnvironment, - IRuntimeState runtimeState, - UmbracoApiControllerTypeCollection apiControllers) - : this(globalSettings, hostingEnvironment, runtimeState) - { - } /// public void CreateRoutes(IEndpointRouteBuilder endpoints) { - - - switch (_runtimeState.Level) + if (_runtimeState.Level is RuntimeLevel.Install or RuntimeLevel.Upgrade or RuntimeLevel.Run) { - case RuntimeLevel.Install: - case RuntimeLevel.Upgrade: - case RuntimeLevel.Run: - MapMinimalBackOffice(endpoints); - endpoints.MapHub(_umbracoPathSegment + Constants.Web.BackofficeSignalRHub); - endpoints.MapHub(_umbracoPathSegment + Constants.Web.ServerEventSignalRHub); - break; - case RuntimeLevel.BootFailed: - case RuntimeLevel.Unknown: - case RuntimeLevel.Boot: - break; + MapMinimalBackOffice(endpoints); + + endpoints.MapHub(Constants.System.UmbracoPathSegment + Constants.Web.BackofficeSignalRHub); + endpoints.MapHub(Constants.System.UmbracoPathSegment + Constants.Web.ServerEventSignalRHub); } } @@ -70,7 +41,7 @@ public void CreateRoutes(IEndpointRouteBuilder endpoints) private void MapMinimalBackOffice(IEndpointRouteBuilder endpoints) { endpoints.MapUmbracoRoute( - _umbracoPathSegment, + Constants.System.UmbracoPathSegment, null!, string.Empty, "Index", @@ -82,7 +53,7 @@ private void MapMinimalBackOffice(IEndpointRouteBuilder endpoints) endpoints.MapControllerRoute( "catch-all-sections-to-client", - new StringBuilder(_umbracoPathSegment).Append("/{**slug}").ToString(), + $"{Constants.System.UmbracoPathSegment}/{{**slug}}", new { Controller = ControllerExtensions.GetControllerName(), diff --git a/src/Umbraco.Cms.Api.Management/Routing/PreviewRoutes.cs b/src/Umbraco.Cms.Api.Management/Routing/PreviewRoutes.cs index 6f190107754b..1327e1e14466 100644 --- a/src/Umbraco.Cms.Api.Management/Routing/PreviewRoutes.cs +++ b/src/Umbraco.Cms.Api.Management/Routing/PreviewRoutes.cs @@ -1,13 +1,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; -using Microsoft.Extensions.Options; using Umbraco.Cms.Api.Management.Preview; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Web.Common.Routing; -using Umbraco.Extensions; namespace Umbraco.Cms.Api.Management.Routing; @@ -17,36 +13,23 @@ namespace Umbraco.Cms.Api.Management.Routing; public sealed class PreviewRoutes : IAreaRoutes { private readonly IRuntimeState _runtimeState; - private readonly string _umbracoPathSegment; - public PreviewRoutes( - IOptions globalSettings, - IHostingEnvironment hostingEnvironment, - IRuntimeState runtimeState) - { - _runtimeState = runtimeState; - _umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment); - } + public PreviewRoutes(IRuntimeState runtimeState) + => _runtimeState = runtimeState; public void CreateRoutes(IEndpointRouteBuilder endpoints) { - switch (_runtimeState.Level) + if (_runtimeState.Level is RuntimeLevel.Install or RuntimeLevel.Upgrade or RuntimeLevel.Run) { - case RuntimeLevel.Install: - case RuntimeLevel.Upgrade: - case RuntimeLevel.Run: - endpoints.MapHub(GetPreviewHubRoute()); - break; - case RuntimeLevel.BootFailed: - case RuntimeLevel.Unknown: - case RuntimeLevel.Boot: - break; + endpoints.MapHub(GetPreviewHubRoute()); } } /// - /// Returns the path to the signalR hub used for preview + /// Gets the path to the SignalR hub used for preview. /// - /// Path to signalR hub - public string GetPreviewHubRoute() => $"/{_umbracoPathSegment}/{nameof(PreviewHub)}"; + /// + /// The path to the SignalR hub used for preview. + /// + public string GetPreviewHubRoute() => $"/{Constants.System.UmbracoPathSegment}/{nameof(PreviewHub)}"; } diff --git a/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoLogin/Index.cshtml b/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoLogin/Index.cshtml index 90bf8d3598e5..8b4c1f328b11 100644 --- a/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoLogin/Index.cshtml +++ b/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoLogin/Index.cshtml @@ -1,4 +1,3 @@ -@using Microsoft.AspNetCore.Mvc.TagHelpers @using Microsoft.Extensions.Options; @using Umbraco.Cms.Api.Management.Controllers.Security @using Umbraco.Cms.Api.Management.Extensions @@ -11,10 +10,10 @@ @using Umbraco.Cms.Core.Serialization @using Umbraco.Cms.Web.Common.Hosting @using Umbraco.Extensions +@inject IOptions GlobalSettings @inject IOptions SecuritySettings @inject IEmailSender EmailSender @inject IHostingEnvironment HostingEnvironment -@inject IOptions GlobalSettings @inject IProfilerHtml ProfilerHtml @inject IBackOfficeExternalLoginProviders ExternalLogins @inject IBackOfficePathGenerator BackOfficePathGenerator @@ -22,7 +21,7 @@ @inject IJsonSerializer JsonSerializer @{ bool.TryParse(Context.Request.Query["umbDebug"], out var isDebug); - var backOfficePath = GlobalSettings.Value.GetBackOfficePath(HostingEnvironment); + var backOfficePath = HostingEnvironment.GetBackOfficePath(); var loginLogoImage = Url.RouteUrl(BackOfficeGraphicsController.LoginLogoRouteName, new {Version= "1"}); var loginLogoImageAlternative = Url.RouteUrl(BackOfficeGraphicsController.LoginLogoAlternativeRouteName, new {Version= "1"}); var loginBackgroundImage = Url.RouteUrl(BackOfficeGraphicsController.LoginBackGroundRouteName, new {Version= "1"}); @@ -37,7 +36,7 @@ - + diff --git a/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoWebsite/Maintenance.cshtml b/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoWebsite/Maintenance.cshtml index 94de5f3c5235..1d8ae6f01ef8 100644 --- a/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoWebsite/Maintenance.cshtml +++ b/src/Umbraco.Cms.StaticAssets/umbraco/UmbracoWebsite/Maintenance.cshtml @@ -1,12 +1,8 @@ -@using Microsoft.Extensions.Options -@using Umbraco.Cms.Core.Configuration.Models @using Umbraco.Cms.Core.Hosting @using Umbraco.Cms.Core.Routing -@using Umbraco.Extensions -@inject IHostingEnvironment hostingEnvironment -@inject IOptions globalSettings +@inject IHostingEnvironment HostingEnvironment @{ - var backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment); + var backOfficePath = HostingEnvironment.GetBackOfficePath(); } @@ -17,7 +13,7 @@ Website is Under Maintainance - +