Updated following PR review.
This commit is contained in:
+13
-2
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.BackOffice.Filters;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
@@ -95,10 +96,20 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.BackOffice.Filters
|
||||
.SetupGet(x => x.CurrentUser)
|
||||
.Returns(currentUserMock.Object);
|
||||
|
||||
var umbracoContextMock = new Mock<IUmbracoContext>();
|
||||
umbracoContextMock
|
||||
.SetupGet(x => x.Security)
|
||||
.Returns(webSecurityMock.Object);
|
||||
|
||||
var umbracoContextAccessorMock = new Mock<IUmbracoContextAccessor>();
|
||||
umbracoContextAccessorMock
|
||||
.SetupGet(x => x.UmbracoContext)
|
||||
.Returns(umbracoContextMock.Object);
|
||||
|
||||
var serviceProviderMock = new Mock<IServiceProvider>();
|
||||
serviceProviderMock
|
||||
.Setup(x => x.GetService(typeof(IWebSecurity)))
|
||||
.Returns(webSecurityMock.Object);
|
||||
.Setup(x => x.GetService(typeof(IUmbracoContextAccessor)))
|
||||
.Returns(umbracoContextAccessorMock.Object);
|
||||
|
||||
httpContext.RequestServices = serviceProviderMock.Object;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Filters
|
||||
{
|
||||
@@ -43,8 +42,8 @@ namespace Umbraco.Web.BackOffice.Filters
|
||||
throw new InvalidOperationException($"No argument found for the current action with the name: {_userIdParameter}");
|
||||
}
|
||||
|
||||
var webSecurityService = context.HttpContext.RequestServices.GetService<IWebSecurity>();
|
||||
var user = webSecurityService.CurrentUser;
|
||||
var umbracoContextAccessor = context.HttpContext.RequestServices.GetService<IUmbracoContextAccessor>();
|
||||
var user = umbracoContextAccessor.UmbracoContext.Security.CurrentUser;
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Umbraco.Web.BackOffice.Filters
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var modelState = context.ModelState;
|
||||
if (!context.ModelState.IsValid)
|
||||
if (!modelState.IsValid)
|
||||
{
|
||||
context.Result = new BadRequestObjectResult(modelState);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user