V13: Add eventype to webhookevents (#15157)

* Refactor IWebhookEvent to contain event type.

* refactor frontend to filter on eventType.

* Display event names

* refactor to use eventNames

* remove npm from overview

* implement alias for WebhookEvents

* Implement [WebhookEvent] attribute

* Refactor IWebhookService to get by event alias and not name

* Rename parameter to fit method name

* to lower event type to avoid casing issues

* Apply suggestions from code review

Co-authored-by: Ronald Barendse <ronald@barend.se>

* Change event names from constants to hard coded. And give more friendly names

* Refactor to not use event names, where it was not intended

* Add renaming column migration

* display event alias in logs

* Update migration to check if old column is there

* Apply suggestions from code review

Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>

* add determineResource function to avoid duplicate code

---------

Co-authored-by: Zeegaan <nge@umbraco.dk>
Co-authored-by: Ronald Barendse <ronald@barend.se>
Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
This commit is contained in:
Nikolaj Geisle
2023-11-09 14:18:34 +01:00
committed by GitHub
parent 1fcb96288f
commit 7bde16b4ef
40 changed files with 329 additions and 145 deletions

View File

@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Events;
@@ -6,6 +6,7 @@ using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Webhooks;
@@ -14,26 +15,37 @@ public abstract class WebhookEventBase<TNotification> : IWebhookEvent, INotifica
{
private readonly IServerRoleAccessor _serverRoleAccessor;
/// <InheritDoc />
public abstract string Alias { get; }
public string EventName { get; set; }
public string EventType { get; }
protected IWebhookFiringService WebhookFiringService { get; }
protected IWebHookService WebHookService { get; }
protected WebhookSettings WebhookSettings { get; private set; }
protected WebhookEventBase(
IWebhookFiringService webhookFiringService,
IWebHookService webHookService,
IOptionsMonitor<WebhookSettings> webhookSettings,
IServerRoleAccessor serverRoleAccessor,
string eventName)
IServerRoleAccessor serverRoleAccessor)
{
EventName = eventName;
WebhookFiringService = webhookFiringService;
WebHookService = webHookService;
_serverRoleAccessor = serverRoleAccessor;
// assign properties based on the attribute, if it is found
WebhookEventAttribute? attribute = GetType().GetCustomAttribute<WebhookEventAttribute>(false);
EventType = attribute?.EventType ?? "Others";
EventName = attribute?.Name ?? Alias;
WebhookSettings = webhookSettings.CurrentValue;
webhookSettings.OnChange(x => WebhookSettings = x);
}
@@ -50,7 +62,7 @@ public abstract class WebhookEventBase<TNotification> : IWebhookEvent, INotifica
continue;
}
await WebhookFiringService.FireAsync(webhook, EventName, notification, cancellationToken);
await WebhookFiringService.FireAsync(webhook, Alias, notification, cancellationToken);
}
}
@@ -79,7 +91,7 @@ public abstract class WebhookEventBase<TNotification> : IWebhookEvent, INotifica
return;
}
IEnumerable<Webhook> webhooks = await WebHookService.GetByEventNameAsync(EventName);
IEnumerable<Webhook> webhooks = await WebHookService.GetByAliasAsync(Alias);
await ProcessWebhooks(notification, webhooks, cancellationToken);
}