From 3897c568aef28ee2b8013032a3cdd49f7384f383 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 22 Nov 2023 14:38:16 +0000 Subject: [PATCH] Refined the Content webhooks mostly to remove Messages & State properties --- .../Events/Content/ContentCopiedWebhookEvent.cs | 12 +++++++++++- .../ContentDeletedVersionsWebhookEvent.cs | 12 +++++++++++- .../ContentEmptiedRecycleBinWebhookEvent.cs | 3 +-- .../ContentMovedToRecycleBinWebhookEvent.cs | 3 +++ .../Events/Content/ContentMovedWebhookEvent.cs | 4 +++- .../Events/Content/ContentRolledBack.cs | 2 +- .../Events/Content/ContentSortedWebhookEvent.cs | 17 ++++++++++------- 7 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Core/Webhooks/Events/Content/ContentCopiedWebhookEvent.cs b/src/Umbraco.Core/Webhooks/Events/Content/ContentCopiedWebhookEvent.cs index d8840f4b9779..3d6f0163d70b 100644 --- a/src/Umbraco.Core/Webhooks/Events/Content/ContentCopiedWebhookEvent.cs +++ b/src/Umbraco.Core/Webhooks/Events/Content/ContentCopiedWebhookEvent.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Sync; @@ -24,4 +23,15 @@ public ContentCopiedWebhookEvent( } public override string Alias => Constants.WebhookEvents.Aliases.ContentCopied; + + public override object? ConvertNotificationToRequestPayload(ContentCopiedNotification notification) + { + return new + { + notification.Copy, + notification.Original, + notification.ParentId, + notification.RelateToOriginal + }; + } } diff --git a/src/Umbraco.Core/Webhooks/Events/Content/ContentDeletedVersionsWebhookEvent.cs b/src/Umbraco.Core/Webhooks/Events/Content/ContentDeletedVersionsWebhookEvent.cs index 98ec8465a2a8..c543bfe3cad7 100644 --- a/src/Umbraco.Core/Webhooks/Events/Content/ContentDeletedVersionsWebhookEvent.cs +++ b/src/Umbraco.Core/Webhooks/Events/Content/ContentDeletedVersionsWebhookEvent.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Sync; @@ -24,4 +23,15 @@ public ContentDeletedVersionsWebhookEvent( } public override string Alias => Constants.WebhookEvents.Aliases.ContentDeletedVersions; + + public override object? ConvertNotificationToRequestPayload(ContentDeletedVersionsNotification notification) + { + return new + { + notification.Id, + notification.DeletePriorVersions, + notification.SpecificVersion, + notification.DateToRetain + }; + } } diff --git a/src/Umbraco.Core/Webhooks/Events/Content/ContentEmptiedRecycleBinWebhookEvent.cs b/src/Umbraco.Core/Webhooks/Events/Content/ContentEmptiedRecycleBinWebhookEvent.cs index a8fc666694fc..8670d23c49e5 100644 --- a/src/Umbraco.Core/Webhooks/Events/Content/ContentEmptiedRecycleBinWebhookEvent.cs +++ b/src/Umbraco.Core/Webhooks/Events/Content/ContentEmptiedRecycleBinWebhookEvent.cs @@ -2,7 +2,6 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DeliveryApi; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Core.Services; @@ -10,7 +9,7 @@ namespace Umbraco.Cms.Core.Webhooks.Events.Content; -[WebhookEvent("Content Emptied Recycle Bin", Constants.WebhookEvents.Types.Content)] +[WebhookEvent("Content Recycle Bin Emptied", Constants.WebhookEvents.Types.Content)] public class ContentEmptiedRecycleBinWebhookEvent : WebhookEventContentBase { private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; diff --git a/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedToRecycleBinWebhookEvent.cs b/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedToRecycleBinWebhookEvent.cs index dad704fef0ec..6ed74d8c66e4 100644 --- a/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedToRecycleBinWebhookEvent.cs +++ b/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedToRecycleBinWebhookEvent.cs @@ -23,4 +23,7 @@ public ContentMovedToRecycleBinWebhookEvent( } public override string Alias => Constants.WebhookEvents.Aliases.ContentMovedToRecycleBin; + + public override object? ConvertNotificationToRequestPayload(ContentMovedToRecycleBinNotification notification) + => notification.MoveInfoCollection; } diff --git a/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedWebhookEvent.cs b/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedWebhookEvent.cs index fa1eb9dec6d6..46d487c499e0 100644 --- a/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedWebhookEvent.cs +++ b/src/Umbraco.Core/Webhooks/Events/Content/ContentMovedWebhookEvent.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Sync; @@ -24,4 +23,7 @@ public ContentMovedWebhookEvent( } public override string Alias => Constants.WebhookEvents.Aliases.ContentMoved; + + public override object? ConvertNotificationToRequestPayload(ContentMovedNotification notification) + => notification.MoveInfoCollection; } diff --git a/src/Umbraco.Core/Webhooks/Events/Content/ContentRolledBack.cs b/src/Umbraco.Core/Webhooks/Events/Content/ContentRolledBack.cs index 55064912b971..f38ff571f908 100644 --- a/src/Umbraco.Core/Webhooks/Events/Content/ContentRolledBack.cs +++ b/src/Umbraco.Core/Webhooks/Events/Content/ContentRolledBack.cs @@ -45,7 +45,7 @@ protected override IEnumerable GetEntitiesFromNotification(ContentRoll return null; } - // Get preview/saved version of content as a rollback + // Get preview/saved version of content for a rollback IPublishedContent? publishedContent = publishedSnapshot.Content.GetById(true, entity.Key); return publishedContent is null ? null : _apiContentBuilder.Build(publishedContent); } diff --git a/src/Umbraco.Core/Webhooks/Events/Content/ContentSortedWebhookEvent.cs b/src/Umbraco.Core/Webhooks/Events/Content/ContentSortedWebhookEvent.cs index bd706aef0b6d..d2a95028e2fd 100644 --- a/src/Umbraco.Core/Webhooks/Events/Content/ContentSortedWebhookEvent.cs +++ b/src/Umbraco.Core/Webhooks/Events/Content/ContentSortedWebhookEvent.cs @@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Webhooks.Events.Content; [WebhookEvent("Content Sorted", Constants.WebhookEvents.Types.Content)] -public class ContentSortedWebhookEvent : WebhookEventContentBase +public class ContentSortedWebhookEvent : WebhookEventBase { private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; private readonly IApiContentBuilder _apiContentBuilder; @@ -35,16 +35,19 @@ public ContentSortedWebhookEvent( public override string Alias => Constants.WebhookEvents.Aliases.ContentSorted; - protected override IEnumerable GetEntitiesFromNotification(ContentSortedNotification notification) => notification.SortedEntities; - - protected override object? ConvertEntityToRequestPayload(IContent entity) + public override object? ConvertNotificationToRequestPayload(ContentSortedNotification notification) { if (_publishedSnapshotAccessor.TryGetPublishedSnapshot(out IPublishedSnapshot? publishedSnapshot) is false || publishedSnapshot!.Content is null) { return null; } - - IPublishedContent? publishedContent = publishedSnapshot.Content.GetById(entity.Key); - return publishedContent is null ? null : _apiContentBuilder.Build(publishedContent); + var sortedEntities = new List(); + foreach (var entity in notification.SortedEntities) + { + IPublishedContent? publishedContent = publishedSnapshot.Content.GetById(entity.Key); + object? payload = publishedContent is null ? null : _apiContentBuilder.Build(publishedContent); + sortedEntities.Add(payload); + } + return sortedEntities; } }