Skip to content

Commit

Permalink
Add RemoveDefault() extension method to fluent API for CMS webhook …
Browse files Browse the repository at this point in the history
…events (#15424)

* Add RemoveDefault extension method

* Move default webhook event types to single list
  • Loading branch information
ronaldbarendse authored Sep 26, 2024
1 parent 99125ef commit 8f26263
Showing 1 changed file with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ namespace Umbraco.Cms.Core.DependencyInjection;
/// </summary>
public static class WebhookEventCollectionBuilderCmsExtensions
{
private static readonly Type[] _defaultTypes =
[
typeof(ContentDeletedWebhookEvent),
typeof(ContentPublishedWebhookEvent),
typeof(ContentUnpublishedWebhookEvent),
typeof(MediaDeletedWebhookEvent),
typeof(MediaSavedWebhookEvent),
];

/// <summary>
/// Adds the default webhook events.
/// </summary>
Expand All @@ -21,12 +30,24 @@ public static class WebhookEventCollectionBuilderCmsExtensions
/// </remarks>
public static WebhookEventCollectionBuilderCms AddDefault(this WebhookEventCollectionBuilderCms builder)
{
builder.Builder
.Add<ContentDeletedWebhookEvent>()
.Add<ContentPublishedWebhookEvent>()
.Add<ContentUnpublishedWebhookEvent>()
.Add<MediaDeletedWebhookEvent>()
.Add<MediaSavedWebhookEvent>();
builder.Builder.Add(_defaultTypes);

return builder;
}

/// <summary>
/// Removes the default webhook events.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns>
/// The builder.
/// </returns>
public static WebhookEventCollectionBuilderCms RemoveDefault(this WebhookEventCollectionBuilderCms builder)
{
foreach (Type type in _defaultTypes)
{
builder.Builder.Remove(type);
}

return builder;
}
Expand Down

0 comments on commit 8f26263

Please sign in to comment.