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

@@ -21,7 +21,7 @@ public class WebhookLogServiceTests : UmbracoIntegrationTest
var createdWebhookLog = await WebhookLogService.CreateAsync(new WebhookLog
{
Date = DateTime.UtcNow,
EventName = Constants.WebhookEvents.ContentPublish,
EventAlias = Constants.WebhookEvents.Aliases.ContentPublish,
RequestBody = "Test Request Body",
ResponseBody = "Test response body",
StatusCode = "200",
@@ -39,7 +39,7 @@ public class WebhookLogServiceTests : UmbracoIntegrationTest
Assert.AreEqual(1, webhookLogsPaged.Items.Count());
var webHookLog = webhookLogsPaged.Items.First();
Assert.AreEqual(createdWebhookLog.Date.ToString(CultureInfo.InvariantCulture), webHookLog.Date.ToString(CultureInfo.InvariantCulture));
Assert.AreEqual(createdWebhookLog.EventName, webHookLog.EventName);
Assert.AreEqual(createdWebhookLog.EventAlias, webHookLog.EventAlias);
Assert.AreEqual(createdWebhookLog.RequestBody, webHookLog.RequestBody);
Assert.AreEqual(createdWebhookLog.ResponseBody, webHookLog.ResponseBody);
Assert.AreEqual(createdWebhookLog.StatusCode, webHookLog.StatusCode);

View File

@@ -14,11 +14,11 @@ public class WebhookServiceTests : UmbracoIntegrationTest
private IWebHookService WebhookService => GetRequiredService<IWebHookService>();
[Test]
[TestCase("https://example.com", Constants.WebhookEvents.ContentPublish, "00000000-0000-0000-0000-010000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.ContentDelete, "00000000-0000-0000-0000-000200000000")]
[TestCase("https://example.com", Constants.WebhookEvents.ContentUnpublish, "00000000-0000-0000-0000-300000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.MediaDelete, "00000000-0000-0000-0000-000004000000")]
[TestCase("https://example.com", Constants.WebhookEvents.MediaSave, "00000000-0000-0000-0000-000000500000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentPublish, "00000000-0000-0000-0000-010000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentDelete, "00000000-0000-0000-0000-000200000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentUnpublish, "00000000-0000-0000-0000-300000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.MediaDelete, "00000000-0000-0000-0000-000004000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.MediaSave, "00000000-0000-0000-0000-000000500000")]
public async Task Can_Create_And_Get(string url, string webhookEvent, Guid key)
{
var createdWebhook = await WebhookService.CreateAsync(new Webhook(url, true, new[] { key }, new[] { webhookEvent }));
@@ -37,9 +37,9 @@ public class WebhookServiceTests : UmbracoIntegrationTest
[Test]
public async Task Can_Get_All()
{
var createdWebhookOne = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.ContentPublish }));
var createdWebhookTwo = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.ContentDelete }));
var createdWebhookThree = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.ContentUnpublish }));
var createdWebhookOne = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
var createdWebhookTwo = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.Aliases.ContentDelete }));
var createdWebhookThree = await WebhookService.CreateAsync(new Webhook("https://example.com", true, new[] { Guid.NewGuid() }, new[] { Constants.WebhookEvents.Aliases.ContentUnpublish }));
var webhooks = await WebhookService.GetAllAsync(0, int.MaxValue);
Assert.Multiple(() =>
@@ -52,11 +52,11 @@ public class WebhookServiceTests : UmbracoIntegrationTest
}
[Test]
[TestCase("https://example.com", Constants.WebhookEvents.ContentPublish, "00000000-0000-0000-0000-010000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.ContentDelete, "00000000-0000-0000-0000-000200000000")]
[TestCase("https://example.com", Constants.WebhookEvents.ContentUnpublish, "00000000-0000-0000-0000-300000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.MediaDelete, "00000000-0000-0000-0000-000004000000")]
[TestCase("https://example.com", Constants.WebhookEvents.MediaSave, "00000000-0000-0000-0000-000000500000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentPublish, "00000000-0000-0000-0000-010000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentDelete, "00000000-0000-0000-0000-000200000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.ContentUnpublish, "00000000-0000-0000-0000-300000000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.MediaDelete, "00000000-0000-0000-0000-000004000000")]
[TestCase("https://example.com", Constants.WebhookEvents.Aliases.MediaSave, "00000000-0000-0000-0000-000000500000")]
public async Task Can_Delete(string url, string webhookEvent, Guid key)
{
var createdWebhook = await WebhookService.CreateAsync(new Webhook(url, true, new[] { key }, new[] { webhookEvent }));
@@ -71,7 +71,7 @@ public class WebhookServiceTests : UmbracoIntegrationTest
[Test]
public async Task Can_Create_With_No_EntityKeys()
{
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.ContentPublish }));
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
var webhook = await WebhookService.GetAsync(createdWebhook.Key);
Assert.IsNotNull(webhook);
@@ -81,24 +81,24 @@ public class WebhookServiceTests : UmbracoIntegrationTest
[Test]
public async Task Can_Update()
{
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.ContentPublish }));
createdWebhook.Events = new[] { Constants.WebhookEvents.ContentDelete };
var createdWebhook = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
createdWebhook.Events = new[] { Constants.WebhookEvents.Aliases.ContentDelete };
await WebhookService.UpdateAsync(createdWebhook);
var updatedWebhook = await WebhookService.GetAsync(createdWebhook.Key);
Assert.IsNotNull(updatedWebhook);
Assert.AreEqual(1, updatedWebhook.Events.Length);
Assert.IsTrue(updatedWebhook.Events.Contains(Constants.WebhookEvents.ContentDelete));
Assert.IsTrue(updatedWebhook.Events.Contains(Constants.WebhookEvents.Aliases.ContentDelete));
}
[Test]
public async Task Can_Get_By_EventName()
{
var webhook1 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.ContentPublish }));
var webhook2 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.ContentUnpublish }));
var webhook3 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.ContentUnpublish }));
var webhook1 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentPublish }));
var webhook2 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentUnpublish }));
var webhook3 = await WebhookService.CreateAsync(new Webhook("https://example.com", events: new[] { Constants.WebhookEvents.Aliases.ContentUnpublish }));
var result = await WebhookService.GetByEventNameAsync(Constants.WebhookEvents.ContentUnpublish);
var result = await WebhookService.GetByAliasAsync(Constants.WebhookEvents.Aliases.ContentUnpublish);
Assert.IsNotEmpty(result);
Assert.AreEqual(2, result.Count());