From 75e6eb0bd910b5ba06fcaabbd419466f77560736 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 26 Nov 2020 17:02:07 +1100 Subject: [PATCH] Fixes async filters and cleans up some code --- .../Filters/ContentSaveValidationAttribute.cs | 16 ++++++---------- .../Filters/MediaItemSaveValidationAttribute.cs | 6 +++++- .../ValidateAngularAntiForgeryTokenAttribute.cs | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs index cefa8c7123..29ed0f5ba0 100644 --- a/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs @@ -33,13 +33,10 @@ namespace Umbraco.Web.BackOffice.Filters private sealed class ContentSaveValidationFilter : IAsyncActionFilter { private readonly IContentService _contentService; - private readonly IEntityService _entityService; private readonly IPropertyValidationService _propertyValidationService; - private readonly ContentPermissions _contentPermissions; private readonly IAuthorizationService _authorizationService; private readonly ILoggerFactory _loggerFactory; private readonly ILocalizedTextService _textService; - private readonly IUserService _userService; private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor; @@ -48,20 +45,14 @@ namespace Umbraco.Web.BackOffice.Filters IBackOfficeSecurityAccessor backofficeSecurityAccessor, ILocalizedTextService textService, IContentService contentService, - IUserService userService, - IEntityService entityService, IPropertyValidationService propertyValidationService, - ContentPermissions contentPermissions, IAuthorizationService authorizationService) { _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); _backofficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor)); _textService = textService ?? throw new ArgumentNullException(nameof(textService)); _contentService = contentService ?? throw new ArgumentNullException(nameof(contentService)); - _userService = userService ?? throw new ArgumentNullException(nameof(userService)); - _entityService = entityService ?? throw new ArgumentNullException(nameof(entityService)); _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService)); - _contentPermissions = contentPermissions; _authorizationService = authorizationService; } @@ -70,7 +61,12 @@ namespace Umbraco.Web.BackOffice.Filters // on executing... await OnActionExecutingAsync(context); - await next(); //need to pass the execution to next + if (context.Result == null) + { + //need to pass the execution to next if a result was not set + await next(); + } + // on executed... } diff --git a/src/Umbraco.Web.BackOffice/Filters/MediaItemSaveValidationAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/MediaItemSaveValidationAttribute.cs index b10043c73c..ebf21f345e 100644 --- a/src/Umbraco.Web.BackOffice/Filters/MediaItemSaveValidationAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/MediaItemSaveValidationAttribute.cs @@ -52,7 +52,11 @@ namespace Umbraco.Web.BackOffice.Filters // on executing... await OnActionExecutingAsync(context); - await next(); //need to pass the execution to next + if (context.Result == null) + { + //need to pass the execution to next if a result was not set + await next(); + } // on executed... } diff --git a/src/Umbraco.Web.BackOffice/Filters/ValidateAngularAntiForgeryTokenAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/ValidateAngularAntiForgeryTokenAttribute.cs index 556a84e0dc..f7fd174e03 100644 --- a/src/Umbraco.Web.BackOffice/Filters/ValidateAngularAntiForgeryTokenAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/ValidateAngularAntiForgeryTokenAttribute.cs @@ -53,13 +53,13 @@ namespace Umbraco.Web.BackOffice.Filters var cookieToken = _cookieManager.GetCookieValue(Constants.Web.CsrfValidationCookieName); var httpContext = context.HttpContext; - var validateResult = await ValidateHeaders(httpContext, cookieToken); - if (validateResult.Item1 == false) - { - httpContext.SetReasonPhrase(validateResult.Item2); - context.Result = new StatusCodeResult((int)HttpStatusCode.ExpectationFailed); - return; - } + var validateResult = await ValidateHeaders(httpContext, cookieToken); + if (validateResult.Item1 == false) + { + httpContext.SetReasonPhrase(validateResult.Item2); + context.Result = new StatusCodeResult((int)HttpStatusCode.ExpectationFailed); + return; + } await next(); }