Files
Umbraco-CMS/src/Umbraco.Core/Webhooks/WebhookEventContentBase.cs
Nikolaj Geisle 8755703845 V13: Implement webook as i entity (#15267)
* Add webhook service to service context

* Refactor webhooks to implement IEntity

---------

Co-authored-by: Zeegaan <nge@umbraco.dk>
2023-11-21 14:38:47 +01:00

49 lines
1.6 KiB
C#

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;
namespace Umbraco.Cms.Core.Webhooks;
public abstract class WebhookEventContentBase<TNotification, TEntity> : WebhookEventBase<TNotification>
where TNotification : INotification
where TEntity : IContentBase
{
protected WebhookEventContentBase(
IWebhookFiringService webhookFiringService,
IWebhookService webhookService,
IOptionsMonitor<WebhookSettings> webhookSettings,
IServerRoleAccessor serverRoleAccessor)
: base(webhookFiringService, webhookService, webhookSettings, serverRoleAccessor)
{
}
public override async Task ProcessWebhooks(TNotification notification, IEnumerable<IWebhook> webhooks, CancellationToken cancellationToken)
{
foreach (IWebhook webhook in webhooks)
{
if (!webhook.Enabled)
{
continue;
}
foreach (TEntity entity in GetEntitiesFromNotification(notification))
{
if (webhook.ContentTypeKeys.Any() && !webhook.ContentTypeKeys.Contains(entity.ContentType.Key))
{
continue;
}
await WebhookFiringService.FireAsync(webhook, Alias, ConvertEntityToRequestPayload(entity), cancellationToken);
}
}
}
protected abstract IEnumerable<TEntity> GetEntitiesFromNotification(TNotification notification);
protected abstract object? ConvertEntityToRequestPayload(TEntity entity);
}