Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fluent API for adding webhook events and add document type events #15345

Merged
merged 15 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.ContentApps;
using Umbraco.Cms.Core.Dashboards;
using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.DynamicRoot.Origin;
using Umbraco.Cms.Core.DynamicRoot.QuerySteps;
using Umbraco.Cms.Core.Editors;
using Umbraco.Cms.Core.HealthChecks;
using Umbraco.Cms.Core.HealthChecks.NotificationMethods;
Expand All @@ -15,8 +17,6 @@
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Sections;
using Umbraco.Cms.Core.Snippets;
using Umbraco.Cms.Core.DynamicRoot.QuerySteps;
using Umbraco.Cms.Core.DynamicRoot.Origin;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Core.Tour;
using Umbraco.Cms.Core.Trees;
Expand Down 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().AddCoreWebhooks();
builder.WebhookEvents().AddCms(true);
}

/// <summary>
Expand Down
18 changes: 5 additions & 13 deletions src/Umbraco.Core/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE for more details.

using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using Umbraco.Cms.Core;
Expand Down Expand Up @@ -132,9 +133,7 @@ public static bool IsEnumerable(this Type type)
/// <c>true</c> if [is of generic type] [the specified type]; otherwise, <c>false</c>.
/// </returns>
public static bool IsOfGenericType(this Type type, Type genericType)
{
return type.TryGetGenericArguments(genericType, out Type[]? args);
}
=> type.TryGetGenericArguments(genericType, out _);

/// <summary>
/// Will find the generic type of the 'type' parameter passed in that is equal to the 'genericType' parameter passed in
Expand All @@ -143,17 +142,10 @@ public static bool IsOfGenericType(this Type type, Type genericType)
/// <param name="genericType"></param>
/// <param name="genericArgType"></param>
/// <returns></returns>
public static bool TryGetGenericArguments(this Type type, Type genericType, out Type[]? genericArgType)
public static bool TryGetGenericArguments(this Type type, Type genericType, [NotNullWhen(true)] out Type[]? genericArgType)
{
if (type == null)
{
throw new ArgumentNullException("type");
}

if (genericType == null)
{
throw new ArgumentNullException("genericType");
}
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(genericType);

if (genericType.IsGenericType == false)
{
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
@@ -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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[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.ContentType;

[WebhookEvent("Member Type Saved")]
public class MemberTypeSavedWebhookEvent : WebhookEventBase<MemberTypeSavedNotification>
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.Notifications;
using Umbraco.Cms.Core.Services;
Expand Down

This file was deleted.

Loading
Loading