Fixes up issue with UsePlugins and where it's executed

This commit is contained in:
Shannon
2020-12-16 16:31:23 +11:00
parent ce508d08ec
commit 47e98bfdc6
3 changed files with 32 additions and 36 deletions

View File

@@ -1,14 +1,7 @@
using System;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using SixLabors.ImageSharp.Web.DependencyInjection;
using Umbraco.Core;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Web.BackOffice.Middleware;
using Umbraco.Web.BackOffice.Plugins;
using Umbraco.Web.BackOffice.Routing;
using Umbraco.Web.Common.Security;
@@ -19,7 +12,6 @@ namespace Umbraco.Extensions
/// </summary>
public static class BackOfficeApplicationBuilderExtensions
{
app.UseUmbracoPlugins();
public static IApplicationBuilder UseUmbracoBackOffice(this IApplicationBuilder app)
{
// NOTE: This method will have been called after UseRouting, UseAuthentication, UseAuthorization
@@ -50,30 +42,6 @@ namespace Umbraco.Extensions
return app;
}
public static IApplicationBuilder UseUmbracoPlugins(this IApplicationBuilder app)
{
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostingEnvironment>();
var umbracoPluginSettings = app.ApplicationServices.GetRequiredService<IOptions<UmbracoPluginSettings>>();
var pluginFolder = hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins);
// Ensure the plugin folder exists
Directory.CreateDirectory(pluginFolder);
var fileProvider = new UmbracoPluginPhysicalFileProvider(
pluginFolder,
umbracoPluginSettings);
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = Constants.SystemDirectories.AppPlugins
});
return app;
}
public static IApplicationBuilder UseUmbracoPreview(this IApplicationBuilder app)
{
// TODO: I'm unsure this middleware will execute before the endpoint, we'll have to see
@@ -87,6 +55,7 @@ namespace Umbraco.Extensions
return app;
}
private static IApplicationBuilder UseBackOfficeUserManagerAuditing(this IApplicationBuilder app)
{
var auditer = app.ApplicationServices.GetRequiredService<BackOfficeUserManagerAuditer>();

View File

@@ -1,16 +1,20 @@
using System;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Serilog.Context;
using SixLabors.ImageSharp.Web.DependencyInjection;
using Smidge;
using Smidge.Nuglify;
using StackExchange.Profiling;
using Umbraco.Core;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Infrastructure.Logging.Serilog.Enrichers;
using Umbraco.Web.Common.Middleware;
using Umbraco.Web.Common.Plugins;
using Umbraco.Web.PublishedCache.NuCache;
namespace Umbraco.Extensions
@@ -44,6 +48,7 @@ namespace Umbraco.Extensions
// TODO: Since we are dependent on these we need to register them but what happens when we call this multiple times since we are dependent on this for UseUmbracoBackOffice too?
app.UseImageSharp();
app.UseStaticFiles();
app.UseUmbracoPlugins();
// UseRouting adds endpoint routing middleware, this means that middlewares registered after this one
// will execute after endpoint routing. The ordering of everything is quite important here, see
@@ -177,6 +182,29 @@ namespace Umbraco.Extensions
return app;
}
public static IApplicationBuilder UseUmbracoPlugins(this IApplicationBuilder app)
{
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostingEnvironment>();
var umbracoPluginSettings = app.ApplicationServices.GetRequiredService<IOptions<UmbracoPluginSettings>>();
var pluginFolder = hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins);
// Ensure the plugin folder exists
Directory.CreateDirectory(pluginFolder);
var fileProvider = new UmbracoPluginPhysicalFileProvider(
pluginFolder,
umbracoPluginSettings);
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = Constants.SystemDirectories.AppPlugins
});
return app;
}
/// <summary>
/// Ensures the runtime is shutdown when the application is shutting down
/// </summary>

View File

@@ -1,14 +1,13 @@
// Copyright (c) Umbraco.
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.IO;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders.Physical;
using Microsoft.Extensions.Options;
using Umbraco.Core;
using Umbraco.Core.Configuration.Models;
namespace Umbraco.Web.BackOffice.Plugins
namespace Umbraco.Web.Common.Plugins
{
/// <summary>
/// Looks up files using the on-disk file system and check file extensions are on a allow list
@@ -41,7 +40,7 @@ namespace Umbraco.Web.BackOffice.Plugins
public new IFileInfo GetFileInfo(string subpath)
{
var extension = Path.GetExtension(subpath);
var subPathInclAppPluginsFolder = Path.Combine(Constants.SystemDirectories.AppPlugins, subpath);
var subPathInclAppPluginsFolder = Path.Combine(Core.Constants.SystemDirectories.AppPlugins, subpath);
if (!_options.Value.BrowsableFileExtensions.Contains(extension))
{
return new NotFoundFileInfo(subPathInclAppPluginsFolder);