Fix typo, adds [CannotSuppressNotification]

This commit is contained in:
Shannon
2021-07-12 11:54:38 -06:00
parent cd20701929
commit dcae692407
9 changed files with 40 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Events
/// Supresses all notifications from being added/created until the result object is disposed.
/// </summary>
/// <returns></returns>
IDisposable Supress();
IDisposable Suppress();
/// <summary>
/// Publishes a cancelable notification to the notification subscribers

View File

@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Umbraco.Cms.Core.Notifications;
@@ -28,7 +29,7 @@ namespace Umbraco.Cms.Core.Events
throw new ArgumentNullException(nameof(notification));
}
if (_isSuppressed)
if (CanSuppress(notification) && _isSuppressed)
{
return false;
}
@@ -44,7 +45,7 @@ namespace Umbraco.Cms.Core.Events
throw new ArgumentNullException(nameof(notification));
}
if (_isSuppressed)
if (CanSuppress(notification) && _isSuppressed)
{
return false;
}
@@ -60,7 +61,7 @@ namespace Umbraco.Cms.Core.Events
throw new ArgumentNullException(nameof(notification));
}
if (_isSuppressed)
if (CanSuppress(notification) && _isSuppressed)
{
return;
}
@@ -86,7 +87,7 @@ namespace Umbraco.Cms.Core.Events
}
}
public IDisposable Supress()
public IDisposable Suppress()
{
lock(_locker)
{
@@ -98,6 +99,9 @@ namespace Umbraco.Cms.Core.Events
}
}
private bool CanSuppress(INotification notification)
=> notification.GetType().GetCustomAttribute<CannotSuppressNotificationAttribute>() == null;
private class Suppressor : IDisposable
{
private bool _disposedValue;

View File

@@ -0,0 +1,9 @@
using System;
namespace Umbraco.Cms.Core.Notifications
{
[AttributeUsage(AttributeTargets.Class)]
internal sealed class CannotSuppressNotificationAttribute : Attribute
{
}
}

View File

@@ -5,7 +5,9 @@ using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Notifications
{
[Obsolete("This is only used for the internal cache and will change, use saved notifications instead")]
[CannotSuppressNotification]
[EditorBrowsable(EditorBrowsableState.Never)]
public class ContentRefreshNotification : EntityRefreshNotification<IContent>
{

View File

@@ -5,6 +5,7 @@ using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Notifications
{
[CannotSuppressNotification]
[Obsolete("This is only used for the internal cache and will change, use tree change notifications instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public class MediaRefreshNotification : EntityRefreshNotification<IMedia>

View File

@@ -5,6 +5,7 @@ using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Notifications
{
[CannotSuppressNotification]
[Obsolete("This is only used for the internal cache and will change, use tree change notifications instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public class MemberRefreshNotification : EntityRefreshNotification<IMember>

View File

@@ -5,6 +5,7 @@ using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Notifications
{
[CannotSuppressNotification]
[Obsolete("This is only used for the internal cache and will change, use tree change notifications instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public class ScopedEntityRemoveNotification : ObjectNotification<IContentBase>

View File

@@ -42,7 +42,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services
private IUser CreateTestUser()
{
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
using IDisposable _ = scope.Notifications.Supress();
using IDisposable _ = scope.Notifications.Suppress();
var globalSettings = new GlobalSettings();
var user = new User(globalSettings)

View File

@@ -37,7 +37,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping
public void GivenScope_WhenNotificationsSuppressed_ThenNotificationsDoNotExecute()
{
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
using IDisposable _ = scope.Notifications.Supress();
using IDisposable _ = scope.Notifications.Suppress();
ContentType contentType = ContentTypeBuilder.CreateBasicContentType();
ContentTypeService.Save(contentType);
@@ -50,7 +50,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping
{
using (IScope parentScope = ScopeProvider.CreateScope(autoComplete: true))
{
using IDisposable _ = parentScope.Notifications.Supress();
using IDisposable _ = parentScope.Notifications.Suppress();
using (IScope childScope = ScopeProvider.CreateScope(autoComplete: true))
{
@@ -68,7 +68,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping
int asserted = 0;
using (IScope scope = ScopeProvider.CreateScope(autoComplete: true))
{
using IDisposable suppressed = scope.Notifications.Supress();
using IDisposable suppressed = scope.Notifications.Suppress();
MediaType mediaType = MediaTypeBuilder.CreateImageMediaType("test");
MediaTypeService.Save(mediaType);
@@ -83,6 +83,19 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping
Assert.AreEqual(asserted + 1, TestContext.CurrentContext.AssertCount);
}
[Test]
public void GivenSuppressedNotificationsOnParent_WhenChildSupresses_ThenExceptionIsThrown()
{
using (IScope parentScope = ScopeProvider.CreateScope(autoComplete: true))
using (IDisposable parentSuppressed = parentScope.Notifications.Suppress())
{
using (IScope childScope = ScopeProvider.CreateScope(autoComplete: true))
{
Assert.Throws<InvalidOperationException>(() => childScope.Notifications.Suppress());
}
}
}
private class TestContentNotificationHandler : INotificationHandler<ContentSavingNotification>
{
public void Handle(ContentSavingNotification notification)