Moved BackOfficeNotificationsController to netcore

This commit is contained in:
Bjarke Berg
2020-05-22 07:26:46 +02:00
parent b5df81fca2
commit e4c8e2009c
4 changed files with 36 additions and 12 deletions

View File

@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Mvc;
using Umbraco.Web.WebApi.Filters;
namespace Umbraco.Web.Editors
{
/// <summary>
/// An abstract controller that automatically checks if any request is a non-GET and if the
/// resulting message is INotificationModel in which case it will append any Event Messages
/// currently in the request.
/// </summary>
[TypeFilter(typeof(AppendCurrentEventMessagesAttribute))]
public abstract class BackOfficeNotificationsController : UmbracoAuthorizedJsonController
{
}
}

View File

@@ -1,8 +1,8 @@
using System;
using System.Net.Http;
using System.Web.Http.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Umbraco.Core.Events;
using Umbraco.Web.Composing;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.WebApi.Filters
@@ -14,19 +14,28 @@ namespace Umbraco.Web.WebApi.Filters
/// </summary>
internal sealed class AppendCurrentEventMessagesAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext context)
{
if (context.Response == null) return;
if (context.Request.Method == HttpMethod.Get) return;
if (Current.UmbracoContext == null) return;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IEventMessagesFactory _eventMessagesFactory;
var obj = context.Response.Content as ObjectContent;
if (obj == null) return;
public AppendCurrentEventMessagesAttribute(IUmbracoContextAccessor umbracoContextAccessor, IEventMessagesFactory eventMessagesFactory)
{
_umbracoContextAccessor = umbracoContextAccessor;
_eventMessagesFactory = eventMessagesFactory;
}
public override void OnActionExecuted(ActionExecutedContext context)
{
if (context.HttpContext.Response == null) return;
if (context.HttpContext.Request.Method.Equals(HttpMethod.Get.ToString(), StringComparison.InvariantCultureIgnoreCase)) return;
var umbracoContext = _umbracoContextAccessor.UmbracoContext;
if (umbracoContext == null) return;
if(!(context.Result is ObjectResult obj)) return;
var notifications = obj.Value as INotificationModel;
if (notifications == null) return;
var msgs = Current.EventMessages;
var msgs = _eventMessagesFactory.GetOrDefault();
if (msgs == null) return;
foreach (var eventMessage in msgs.GetAll())

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Web.Editors
/// resulting message is INotificationModel in which case it will append any Event Messages
/// currently in the request.
/// </summary>
[AppendCurrentEventMessages]
//[AppendCurrentEventMessages] // Moved to netcore
[PrefixlessBodyModelValidator]
public abstract class BackOfficeNotificationsController : UmbracoAuthorizedJsonController
{

View File

@@ -390,7 +390,6 @@
<Compile Include="WebApi\AngularJsonOnlyConfigurationAttribute.cs" />
<Compile Include="Editors\Binders\MemberBinder.cs" />
<Compile Include="WebApi\Filters\AngularAntiForgeryHelper.cs" />
<Compile Include="WebApi\Filters\AppendCurrentEventMessagesAttribute.cs" />
<Compile Include="WebApi\Filters\ClearAngularAntiForgeryTokenAttribute.cs" />
<Compile Include="WebApi\Filters\DisableBrowserCacheAttribute.cs" />
<Compile Include="WebApi\Filters\EnableOverrideAuthorizationAttribute.cs" />