Skip to content

Commit

Permalink
Use fluent API for adding webhook events and add document type events (
Browse files Browse the repository at this point in the history
…#15345)

* Move adding webhooks to extension methods

* Clean up WebhookEventCollectionBuilder

* Rename AddAllAvailableWebhooks to AddCmsWebhooks and internalize defaults

* Use fluent CmsWebhookEventCollectionBuilder for adding CMS specific webhook events

* Split media and media type webhook events

* Use fluent CmsUserWebhookEventCollectionBuilder for adding CMS user specific webhook events

* Rename extension methods and add onlyDefault parameter

* Remove duplicate UserForgotPasswordRequestedWebhookEvent

* Add document type webhook events and use fluent builders for content and content types

* Use fluent WebhookEventCollectionBuilderCmsMember for adding member/member group webhook events

* Use fluent WebhookEventCollectionBuilderCmsTemplate for template/partial view webhook events

* Use fluent WebhookEventCollectionBuilderCmsFile for file based webhook events (instead of only template/partial view)

* Move all webhook events to Umbraco.Cms.Core.Webhooks.Events namespace

* Reorder AddFile method and update documentation
  • Loading branch information
ronaldbarendse authored Dec 4, 2023
1 parent da56f16 commit c20d96c
Show file tree
Hide file tree
Showing 86 changed files with 1,023 additions and 403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ internal static void AddAllCoreCollectionBuilders(this IUmbracoBuilder builder)
builder.FilterHandlers().Add(() => builder.TypeLoader.GetTypes<IFilterHandler>());
builder.SortHandlers().Add(() => builder.TypeLoader.GetTypes<ISortHandler>());
builder.ContentIndexHandlers().Add(() => builder.TypeLoader.GetTypes<IContentIndexHandler>());
builder.WebhookEvents().AddDefaultWebhooks();
builder.WebhookEvents().AddCms(true);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Umbraco.Core/Umbraco.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions"/>
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" />
<PackageReference Include="System.Runtime.Caching" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Copied", Constants.WebhookEvents.Types.Content)]
public class ContentCopiedWebhookEvent : WebhookEventBase<ContentCopiedNotification>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.Extensions.Options;
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.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Template [Blueprint] Deleted", Constants.WebhookEvents.Types.Content)]
public class ContentDeletedBlueprintWebhookEvent : WebhookEventContentBase<ContentDeletedBlueprintNotification, IContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Versions Deleted", Constants.WebhookEvents.Types.Content)]
public class ContentDeletedVersionsWebhookEvent : WebhookEventBase<ContentDeletedVersionsNotification>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.Extensions.Options;
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.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Deleted", Constants.WebhookEvents.Types.Content)]
public class ContentDeletedWebhookEvent : WebhookEventContentBase<ContentDeletedNotification, IContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.Models;
Expand All @@ -7,7 +7,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Recycle Bin Emptied", Constants.WebhookEvents.Types.Content)]
public class ContentEmptiedRecycleBinWebhookEvent : WebhookEventContentBase<ContentEmptiedRecycleBinNotification, IContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Moved to Recycle Bin", Constants.WebhookEvents.Types.Content)]
public class ContentMovedToRecycleBinWebhookEvent : WebhookEventBase<ContentMovedToRecycleBinNotification>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Moved", Constants.WebhookEvents.Types.Content)]
public class ContentMovedWebhookEvent : WebhookEventBase<ContentMovedNotification>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.Models;
Expand All @@ -8,7 +8,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Published", Constants.WebhookEvents.Types.Content)]
public class ContentPublishedWebhookEvent : WebhookEventContentBase<ContentPublishedNotification, IContent>
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Webhooks/Events/Content/ContentRolledBack.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.Models;
Expand All @@ -8,7 +8,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Rolled Back", Constants.WebhookEvents.Types.Content)]
public class ContentRolledBackWebhookEvent : WebhookEventContentBase<ContentRolledBackNotification, IContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.Extensions.Options;
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.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Template [Blueprint] Saved", Constants.WebhookEvents.Types.Content)]
public class ContentSavedBlueprintWebhookEvent : WebhookEventContentBase<ContentSavedBlueprintNotification, IContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.Models;
Expand All @@ -8,7 +8,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Saved", Constants.WebhookEvents.Types.Content)]
public class ContentSavedWebhookEvent : WebhookEventContentBase<ContentSavedNotification, IContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.Models;
Expand All @@ -8,7 +8,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Sorted", Constants.WebhookEvents.Types.Content)]
public class ContentSortedWebhookEvent : WebhookEventBase<ContentSortedNotification>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.Extensions.Options;
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.Events.Content;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Content Unpublished", Constants.WebhookEvents.Types.Content)]
public class ContentUnpublishedWebhookEvent : WebhookEventContentBase<ContentUnpublishedNotification, IContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Document Type Changed")]
public class DocumentTypeChangedWebhookEvent : WebhookEventBase<ContentTypeChangedNotification>
{
public DocumentTypeChangedWebhookEvent(
IWebhookFiringService webhookFiringService,
IWebhookService webHookService,
IOptionsMonitor<WebhookSettings> webhookSettings,
IServerRoleAccessor serverRoleAccessor)
: base(webhookFiringService, webHookService, webhookSettings, serverRoleAccessor)
{
}

public override string Alias => "documentTypeChanged";

public override object? ConvertNotificationToRequestPayload(ContentTypeChangedNotification notification)
=> notification.Changes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Document Type Deleted")]
public class DocumentTypeDeletedWebhookEvent : WebhookEventBase<ContentTypeDeletedNotification>
{
public DocumentTypeDeletedWebhookEvent(
IWebhookFiringService webhookFiringService,
IWebhookService webHookService,
IOptionsMonitor<WebhookSettings> webhookSettings,
IServerRoleAccessor serverRoleAccessor)
: base(webhookFiringService, webHookService, webhookSettings, serverRoleAccessor)
{
}

public override string Alias => "documentTypeDeleted";

public override object? ConvertNotificationToRequestPayload(ContentTypeDeletedNotification notification)
=> notification.DeletedEntities;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Document Type Moved")]
public class DocumentTypeMovedWebhookEvent : WebhookEventBase<ContentTypeMovedNotification>
{
public DocumentTypeMovedWebhookEvent(
IWebhookFiringService webhookFiringService,
IWebhookService webHookService,
IOptionsMonitor<WebhookSettings> webhookSettings,
IServerRoleAccessor serverRoleAccessor)
: base(webhookFiringService, webHookService, webhookSettings, serverRoleAccessor)
{
}

public override string Alias => "documentTypeMoved";

public override object? ConvertNotificationToRequestPayload(ContentTypeMovedNotification notification)
=> notification.MoveInfoCollection;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Document Type Saved")]
public class DocumentTypeSavedWebhookEvent : WebhookEventBase<ContentTypeSavedNotification>
{
public DocumentTypeSavedWebhookEvent(
IWebhookFiringService webhookFiringService,
IWebhookService webHookService,
IOptionsMonitor<WebhookSettings> webhookSettings,
IServerRoleAccessor serverRoleAccessor)
: base(webhookFiringService, webHookService, webhookSettings, serverRoleAccessor)
{
}

public override string Alias => "documentTypeSaved";

public override object? ConvertNotificationToRequestPayload(ContentTypeSavedNotification notification)
=> notification.SavedEntities;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MediaType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Media Type Changed")]
public class MediaTypeChangedWebhookEvent : WebhookEventBase<MediaTypeChangedNotification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MediaType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Media Type Deleted")]
public class MediaTypeDeletedWebhookEvent : WebhookEventBase<MediaTypeDeletedNotification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MediaType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Media Type Moved")]
public class MediaTypeMovedWebhookEvent : WebhookEventBase<MediaTypeMovedNotification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MediaType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Media Type Saved")]
public class MediaTypeSavedWebhookEvent : WebhookEventBase<MediaTypeSavedNotification>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MemberType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Member Type Changed")]
public class MemberTypeChangedWebhookEvent : WebhookEventBase<MemberTypeChangedNotification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MemberType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Member Type Deleted")]
public class MemberTypeDeletedWebhookEvent : WebhookEventBase<MemberTypeDeletedNotification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MemberType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Member Type Moved")]
public class MemberTypeMovedWebhookEvent : WebhookEventBase<MemberTypeMovedNotification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events.MemberType;
namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Member Type Saved")]
public class MemberTypeSavedWebhookEvent : WebhookEventBase<MemberTypeSavedNotification>
Expand Down
Loading

0 comments on commit c20d96c

Please sign in to comment.