From f8db15dcc7fe8b7b2218474df5b4cffa9a54e52b Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Wed, 3 Mar 2021 09:02:29 +0100 Subject: [PATCH] Wire up notification handlers in a composer --- .../Compose/NotificationsComposer.cs | 49 ++++++++++++++++++- .../Compose/RelateOnCopyHandler.cs | 5 +- .../Compose/RelateOnTrashHandler.cs | 2 +- ...Handler.cs => UserNotificationsHandler.cs} | 6 +-- .../BlockEditorPropertyHandler.cs | 1 - ...ropertyEditorContentNotificationHandler.cs | 1 - .../FileUploadPropertyEditor.cs | 1 - .../ImageCropperPropertyEditor.cs | 1 - .../NestedContentPropertyHandler.cs | 1 - .../Routing/RedirectTrackingHandler.cs | 1 - 10 files changed, 54 insertions(+), 14 deletions(-) rename src/Umbraco.Infrastructure/Compose/{NotificationsHandler.cs => UserNotificationsHandler.cs} (97%) diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs index 21e473bb87..d5328929b2 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs @@ -1,5 +1,9 @@ -using Umbraco.Cms.Core.Composing; +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.Routing; +using Umbraco.Cms.Infrastructure.Services.Notifications; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Compose @@ -11,6 +15,49 @@ namespace Umbraco.Cms.Core.Compose base.Compose(builder); builder.Services.AddUnique(); + + // add handlers for sending user notifications (i.e. emails) + builder.Services.AddUnique(); + builder + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>() + .AddNotificationHandler, UserNotificationsHandler>(); + + // add handlers for building content relations + builder + .AddNotificationHandler, RelateOnCopyHandler>() + .AddNotificationHandler, RelateOnTrashHandler>() + .AddNotificationHandler, RelateOnTrashHandler>() + .AddNotificationHandler, RelateOnTrashHandler>() + .AddNotificationHandler, RelateOnTrashHandler>(); + + // add notification handlers for property editors + builder + .AddNotificationHandler, BlockEditorPropertyHandler>() + .AddNotificationHandler, BlockEditorPropertyHandler>() + .AddNotificationHandler, NestedContentPropertyHandler>() + .AddNotificationHandler, NestedContentPropertyHandler>() + .AddNotificationHandler, FileUploadPropertyEditor>() + .AddNotificationHandler, FileUploadPropertyEditor>() + .AddNotificationHandler, FileUploadPropertyEditor>() + .AddNotificationHandler, FileUploadPropertyEditor>() + .AddNotificationHandler, ImageCropperPropertyEditor>() + .AddNotificationHandler, ImageCropperPropertyEditor>() + .AddNotificationHandler, ImageCropperPropertyEditor>() + .AddNotificationHandler, ImageCropperPropertyEditor>(); + + // add notification handlers for redirect tracking + builder + .AddNotificationHandler, RedirectTrackingHandler>() + .AddNotificationHandler, RedirectTrackingHandler>() + .AddNotificationHandler, RedirectTrackingHandler>() + .AddNotificationHandler, RedirectTrackingHandler>(); } } } diff --git a/src/Umbraco.Infrastructure/Compose/RelateOnCopyHandler.cs b/src/Umbraco.Infrastructure/Compose/RelateOnCopyHandler.cs index a14b2e70b3..ff5b9f732a 100644 --- a/src/Umbraco.Infrastructure/Compose/RelateOnCopyHandler.cs +++ b/src/Umbraco.Infrastructure/Compose/RelateOnCopyHandler.cs @@ -1,12 +1,11 @@ -using Umbraco.Cms.Core; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Services.Notifications; -namespace Umbraco.Cms.Infrastructure.Compose +namespace Umbraco.Cms.Core.Compose { - // TODO: insert these notification handlers in core composition + // TODO: this should probably be moved to another namespace public class RelateOnCopyHandler : INotificationHandler> { private readonly IRelationService _relationService; diff --git a/src/Umbraco.Infrastructure/Compose/RelateOnTrashHandler.cs b/src/Umbraco.Infrastructure/Compose/RelateOnTrashHandler.cs index e1fcdb3bea..3157594b34 100644 --- a/src/Umbraco.Infrastructure/Compose/RelateOnTrashHandler.cs +++ b/src/Umbraco.Infrastructure/Compose/RelateOnTrashHandler.cs @@ -8,7 +8,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Core.Compose { - // TODO: insert these notification handlers in core composition + // TODO: this should probably be moved to another namespace // TODO: lots of duplicate code in this one, refactor public sealed class RelateOnTrashHandler : INotificationHandler>, diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsHandler.cs b/src/Umbraco.Infrastructure/Compose/UserNotificationsHandler.cs similarity index 97% rename from src/Umbraco.Infrastructure/Compose/NotificationsHandler.cs rename to src/Umbraco.Infrastructure/Compose/UserNotificationsHandler.cs index 205aece4d1..5c80f94806 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsHandler.cs +++ b/src/Umbraco.Infrastructure/Compose/UserNotificationsHandler.cs @@ -21,8 +21,8 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Core.Compose { - // TODO: insert these notification handlers in core composition - public sealed class NotificationsHandler : + // TODO: this should probably be moved to another namespace + public sealed class UserNotificationsHandler : INotificationHandler>, INotificationHandler>, INotificationHandler>, @@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Compose private readonly ActionCollection _actions; private readonly IContentService _contentService; - public NotificationsHandler(Notifier notifier, ActionCollection actions, IContentService contentService) + public UserNotificationsHandler(Notifier notifier, ActionCollection actions, IContentService contentService) { _notifier = notifier; _actions = actions; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyHandler.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyHandler.cs index 5ce37d7b75..e08ad47682 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyHandler.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyHandler.cs @@ -11,7 +11,6 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// A handler for Block editors used to bind to notifications /// - // TODO: insert these notification handlers in core composition public class BlockEditorPropertyHandler : ComplexPropertyEditorContentNotificationHandler { private readonly BlockListEditorDataConverter _converter = new BlockListEditorDataConverter(); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ComplexPropertyEditorContentNotificationHandler.cs b/src/Umbraco.Infrastructure/PropertyEditors/ComplexPropertyEditorContentNotificationHandler.cs index 29d23c1c33..c2d9ab20be 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ComplexPropertyEditorContentNotificationHandler.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ComplexPropertyEditorContentNotificationHandler.cs @@ -9,7 +9,6 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors { - // TODO: insert these notification handlers in core composition public abstract class ComplexPropertyEditorContentNotificationHandler : INotificationHandler>, INotificationHandler> diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs index 08308af246..6ad2d4c4ad 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs @@ -25,7 +25,6 @@ namespace Umbraco.Cms.Core.PropertyEditors "fileupload", Group = Constants.PropertyEditors.Groups.Media, Icon = "icon-download-alt")] - // TODO: insert these notification handlers in core composition public class FileUploadPropertyEditor : DataEditor, IMediaUrlGenerator, INotificationHandler>, INotificationHandler>, INotificationHandler>, INotificationHandler> diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs index 8c618c73e4..8df80b6775 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs @@ -32,7 +32,6 @@ namespace Umbraco.Cms.Core.PropertyEditors HideLabel = false, Group = Constants.PropertyEditors.Groups.Media, Icon = "icon-crop")] - // TODO: insert these notification handlers in core composition public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator, INotificationHandler>, INotificationHandler>, INotificationHandler>, INotificationHandler> diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs index 887c547778..f9944d12b2 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs @@ -8,7 +8,6 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// A handler for NestedContent used to bind to notifications /// - // TODO: insert these notification handlers in core composition public class NestedContentPropertyHandler : ComplexPropertyEditorContentNotificationHandler { protected override string EditorAlias => Constants.PropertyEditors.Aliases.NestedContent; diff --git a/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs b/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs index 2ff847d32f..6d8b9cccc7 100644 --- a/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs +++ b/src/Umbraco.Infrastructure/Routing/RedirectTrackingHandler.cs @@ -20,7 +20,6 @@ namespace Umbraco.Cms.Core.Routing /// strategy using rewriting rules probably /// /// recycle bin = moving to and from does nothing: to = the node is gone, where would we redirect? from = same - // TODO: insert these notification handlers in core composition public sealed class RedirectTrackingHandler : INotificationHandler>, INotificationHandler>,