2021-02-15 18:50:16 +11:00
|
|
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Web.Common.Attributes;
|
2020-08-06 22:08:27 +10:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
namespace Umbraco.Cms.Web.Common.ApplicationModels;
|
2021-02-15 18:50:16 +11:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
// TODO: This should just exist in the back office project
|
2020-11-27 13:35:22 +01:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// An application model provider for all Umbraco Back Office controllers
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BackOfficeApplicationModelProvider : IApplicationModelProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly List<IActionModelConvention> _actionModelConventions = new()
|
2020-08-06 22:08:27 +10:00
|
|
|
{
|
2022-05-09 09:39:46 +02:00
|
|
|
new BackOfficeIdentityCultureConvention(),
|
|
|
|
|
};
|
2020-08-06 22:08:27 +10:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Will execute after <see cref="DefaultApplicationModelProvider" />
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Order => 0;
|
2020-08-06 22:08:27 +10:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void OnProvidersExecuted(ApplicationModelProviderContext context)
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-08-06 22:08:27 +10:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void OnProvidersExecuting(ApplicationModelProviderContext context)
|
|
|
|
|
{
|
|
|
|
|
foreach (ControllerModel controller in context.Result.Controllers)
|
2020-08-06 22:08:27 +10:00
|
|
|
{
|
2022-05-09 09:39:46 +02:00
|
|
|
if (!IsBackOfficeController(controller))
|
2020-08-06 22:08:27 +10:00
|
|
|
{
|
2022-05-09 09:39:46 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2020-08-06 22:08:27 +10:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
foreach (ActionModel action in controller.Actions)
|
|
|
|
|
{
|
|
|
|
|
foreach (IActionModelConvention convention in _actionModelConventions)
|
2020-08-06 22:08:27 +10:00
|
|
|
{
|
2022-05-09 09:39:46 +02:00
|
|
|
convention.Apply(action);
|
2020-08-06 22:08:27 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-09 09:39:46 +02:00
|
|
|
|
|
|
|
|
private bool IsBackOfficeController(ControllerModel controller)
|
|
|
|
|
=> controller.Attributes.OfType<IsBackOfficeAttribute>().Any();
|
2020-08-06 22:08:27 +10:00
|
|
|
}
|