From 176b10cf5d3236f80c199cce7ba840ca109e1883 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 16 Feb 2021 10:56:16 +0100 Subject: [PATCH] Added overloads to inject AppCaches + Fixed tests --- .../FilterAllowedOutgoingContentAttributeTests.cs | 12 +++++++----- .../Filters/FilterAllowedOutgoingContentAttribute.cs | 12 +++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs b/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs index 634d58b3fd..4f1beb6e8d 100644 --- a/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs @@ -6,6 +6,8 @@ using System.Net.Http.Headers; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; @@ -26,7 +28,7 @@ namespace Umbraco.Tests.Web.Controllers var entityServiceMock = new Mock(); var entityService = entityServiceMock.Object; - var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), userService, entityService); + var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), userService, entityService, AppCaches.Disabled); var val = new List() {new ContentItemBasic()}; var result = att.GetValueFromResponse( new ObjectContent(typeof (IEnumerable), @@ -46,7 +48,7 @@ namespace Umbraco.Tests.Web.Controllers var entityServiceMock = new Mock(); var entityService = entityServiceMock.Object; - var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), "MyList", userService, entityService); + var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), "MyList", userService, entityService, AppCaches.Disabled); var val = new List() { new ContentItemBasic() }; var container = new MyTestClass() {MyList = val}; @@ -68,7 +70,7 @@ namespace Umbraco.Tests.Web.Controllers var entityServiceMock = new Mock(); var entityService = entityServiceMock.Object; - var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), "DontFind", userService, entityService); + var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), "DontFind", userService, entityService, AppCaches.Disabled); var val = new List() { new ContentItemBasic() }; var container = new MyTestClass() { MyList = val }; @@ -96,7 +98,7 @@ namespace Umbraco.Tests.Web.Controllers .Returns(new[] { Mock.Of(entity => entity.Id == 5 && entity.Path == "-1,5") }); var entityService = entityServiceMock.Object; - var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), userService, entityService); + var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), userService, entityService, AppCaches.Disabled); var list = new List(); var path = ""; for (var i = 0; i < 10; i++) @@ -144,7 +146,7 @@ namespace Umbraco.Tests.Web.Controllers var entityServiceMock = new Mock(); var entityService = entityServiceMock.Object; - var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), userService, entityService); + var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), userService, entityService, AppCaches.Disabled); att.FilterBasedOnPermissions(list, user); Assert.AreEqual(3, list.Count); diff --git a/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs b/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs index 23512aa144..24fd60cd26 100644 --- a/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs @@ -44,6 +44,11 @@ namespace Umbraco.Web.WebApi.Filters { } + public FilterAllowedOutgoingContentAttribute(Type outgoingType, IUserService userService, IEntityService entityService, AppCaches appCaches) + : this(outgoingType, ActionBrowse.ActionLetter, string.Empty, userService, entityService, appCaches) + { + } + public FilterAllowedOutgoingContentAttribute(Type outgoingType, char permissionToCheck, IUserService userService, IEntityService entityService) : this(outgoingType, permissionToCheck, string.Empty, userService, entityService, Current.AppCaches) { @@ -54,6 +59,11 @@ namespace Umbraco.Web.WebApi.Filters { } + public FilterAllowedOutgoingContentAttribute(Type outgoingType, string propertyName, IUserService userService, IEntityService entityService, AppCaches appCaches) + : this(outgoingType, ActionBrowse.ActionLetter, propertyName, userService, entityService, appCaches) + { + } + private FilterAllowedOutgoingContentAttribute(Type outgoingType, char permissionToCheck, string propertyName, IUserService userService, IEntityService entityService, AppCaches appCaches) : base(outgoingType, propertyName) { @@ -106,7 +116,7 @@ namespace Umbraco.Web.WebApi.Filters if (nodePermission.Contains(_permissionToCheck.ToString(CultureInfo.InvariantCulture)) == false) { toRemove.Add(item); - } + } } foreach (var item in toRemove) {