-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Webhooks administration from Backoffice #15050
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
Merged
Merged
Changes from all commits
Commits
Show all changes
103 commits
Select commit
Hold shift + click to select a range
727f3fe
Create webhook models
Zeegaan 3fa9d5f
Define interfaces for service and repository
Zeegaan c511fa3
Create Webhook dto and corresponding factory
Zeegaan b97abb4
implement WebhookRepository.cs
Zeegaan f683405
Remove entity name from models, as that should be resolved in mapping…
Zeegaan ccec84d
Add new table to schema creator
Zeegaan b427570
Register repo for DI
Zeegaan a2a9065
Remove more mentions of entityname
Zeegaan 039c330
Refactor repository to guids
Zeegaan aab96de
Implement WebhookService
Zeegaan 54ac9c5
Use scopes in service
Zeegaan db6ed7c
Start creating tests for service
Zeegaan 11fd1e6
Refactor delete to use Id and not entire entity
Zeegaan 6aa3f2b
Rework Webhooks to be able to have multiple entity keys
Zeegaan 4d90483
Implement GetAll functionality
Zeegaan e457600
Implement webhook controller
Zeegaan e24cf0e
Imeplement get all events action
Zeegaan 8f3fc3b
Add equalityComparer deletegate to Webhook
Zeegaan e04ec6b
Add datacontract attirbutes to properties
Zeegaan b0e7ddb
Implement backoffice webhooks tree
Zeegaan bef79a1
Implement first webhooks menu
Zeegaan 5097145
Make WebHookController authorized
Zeegaan adbf506
Update to have tabs with webhooks and logs
Zeegaan 7e34939
Enable create overlay
Zeegaan 4646115
Push to entityKeys array
Zeegaan d4faf6f
Fix up pagination
Zeegaan e245db5
Implement delete functionality
Zeegaan cdbda08
remove pagination
Zeegaan 6430cbf
add log view
Zeegaan 296e775
Fix create to be able to select more than one content type
Zeegaan be86890
implement type name resolving for content
Zeegaan 9401547
Refactor to use less duplication
Zeegaan 6576519
Implement update functionality in frontend
Zeegaan 44adc7f
Rename database table
Zeegaan dd6e06c
Make multiple events possible
Zeegaan 07b8565
create new event picker
Zeegaan a075ea6
Refactor to actually add new database table with proper name
Zeegaan 35fd634
Make it possible to select multiple events
Zeegaan 85b39d2
Fix updating current items
Zeegaan 3323958
Fix up update functionality after db rework
Zeegaan 682451b
Add webhook icon
Zeegaan 0d4a3e7
Switch to match heartcore icons
Zeegaan d059c10
Refactor to use bases instead of Enum
Zeegaan c7c8562
Refactor to make IWebhookEvent to Collection, so it can be injected i…
Zeegaan 6ba193f
Fix up frontend to match new models
Zeegaan 05c395d
Fix integration tests
Zeegaan 8be6258
Remove obsolete entity key from webhookdto
Zeegaan 65ba2a5
Introduce constants instead of hard coded strings
Zeegaan 9800145
Start implementation of firing mechanism
Zeegaan bd52ba8
Add new GetByEventName method
Zeegaan be29bd2
Add 1 to many list on WebhookDto
Zeegaan 4d5e01a
Implement new repository pattern
Zeegaan 8fc0079
Implement GetByEventName
Zeegaan ba501ef
Fix up repository to use all async
Zeegaan 818be73
Refactor events to fire
Zeegaan 2e9184d
Refactor WebhookEvents to be more DRY
Zeegaan 1c77eb2
Add custom header
Zeegaan 4859dd3
Start implementing log repository
Zeegaan 4bd4aa1
Implement GetPaged
Zeegaan 8d7fc22
Implement WebhookLogService
Zeegaan 4fd4b6a
Implement GetLogs
Zeegaan 9501346
Add url to webhook log
Zeegaan ece9bbb
Implement log overview
Zeegaan 2ef7042
Formatting
Zeegaan e67ab16
Implement details view
Zeegaan 8fda54a
Refactor to get actual retry count
Zeegaan 49250c7
Refactor firing to fire only when Enabled
Zeegaan 24a5fa7
Add Status code to detailed view
Zeegaan 3f7de88
Add configuration to disable webhooks entirely
Zeegaan 8ceab7b
Implement custom headers frontend
Zeegaan cf962a9
Implement persistence of custom headers
Zeegaan 50765f3
Refactor retry service to also retry on non success status codes.
Zeegaan e3221fd
Refactor registration of Webhooks, to also register as NotificationHa…
Zeegaan b706373
Merge remote-tracking branch 'origin/v13/dev' into v12/feature/webhooks
Zeegaan 6078d66
Add webhooks migration
Zeegaan 9339f49
Add key for adding webhook headers
Zeegaan cd751a6
Fix up test
Zeegaan 28b1a8a
Change event icon to flag
Zeegaan 2c41744
Remember event, when editing what events you have chosen
Zeegaan 7f648ce
Refactor reflection to check if INotificationAsyncHandler instead
Zeegaan f6ace10
Formatting
Zeegaan d40a6f9
Refactor webhook model to no longer derive from EntityBase
Zeegaan 66da03e
Rename entityKeys to content keys
Zeegaan 866ecb7
Rename controller to lowercase H
Zeegaan f46ee0d
Add null check before trying to access selectedEvents
Zeegaan ad7c680
Add configuration for maximum number of retries
Zeegaan 2005500
Add index to date
Zeegaan 90a268b
Add webhook Key to logs
Zeegaan 090fea6
Check for SchedulingPublisher before sending webhooks
Zeegaan 4f0c4a4
rename requestObject to payload
Zeegaan c62f6cb
Refactor event to send appropriate payloads
Zeegaan bb8ce08
Refactor logging to happen for every try.
Zeegaan 40e3aa2
Order date by descending
Zeegaan 05388b5
Add todo
Zeegaan db163b4
Change firing service to use String not ByteContent
Zeegaan ba2a8a6
Update Headers to Interface instead of concrete implementation
Zeegaan a8516da
Dont return if a table exists already
Zeegaan c6f248f
Rename updateModel to webhook
Zeegaan c0c816a
Annotate WebhookController.cs with PluginController attribute
Zeegaan 6493ac9
Add danish translations
Zeegaan 6407d77
Do not check if fail
Zeegaan ad5e730
Dont filter when selecting custom items
Zeegaan ba81ddb
Remove delay from WebhookFiringService
Zeegaan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System.ComponentModel; | ||
|
|
||
| namespace Umbraco.Cms.Core.Configuration.Models; | ||
|
|
||
| [UmbracoOptions(Constants.Configuration.ConfigWebhook)] | ||
| public class WebhookSettings | ||
| { | ||
| private const bool StaticEnabled = true; | ||
| private const int StaticMaximumRetries = 5; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether webhooks are enabled. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// By default, webhooks are enabled. | ||
| /// If this option is set to <c>false</c> webhooks will no longer send web-requests. | ||
| /// </para> | ||
| /// </remarks> | ||
| [DefaultValue(StaticEnabled)] | ||
| public bool Enabled { get; set; } = StaticEnabled; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating the maximum number of retries for all webhooks. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// By default, maximum number of retries is 5. | ||
| /// If this option is set to <c>0</c> webhooks will no longer retry. | ||
| /// </para> | ||
| /// </remarks> | ||
| [DefaultValue(StaticMaximumRetries)] | ||
| public int MaximumRetries { get; set; } = StaticMaximumRetries; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| namespace Umbraco.Cms.Core; | ||
|
|
||
| public static partial class Constants | ||
| { | ||
| public static class WebhookEvents | ||
| { | ||
| /// <summary> | ||
| /// Webhook event name for content publish. | ||
| /// </summary> | ||
| public const string ContentPublish = "ContentPublish"; | ||
|
|
||
| /// <summary> | ||
| /// Webhook event name for content delete. | ||
| /// </summary> | ||
| public const string ContentDelete = "ContentDelete"; | ||
|
|
||
| /// <summary> | ||
| /// Webhook event name for content unpublish. | ||
| /// </summary> | ||
| public const string ContentUnpublish = "ContentUnpublish"; | ||
|
|
||
| /// <summary> | ||
| /// Webhook event name for media delete. | ||
| /// </summary> | ||
| public const string MediaDelete = "MediaDelete"; | ||
|
|
||
| /// <summary> | ||
| /// Webhook event name for media save. | ||
| /// </summary> | ||
| public const string MediaSave = "MediaSave"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Umbraco.Cms.Core.Models; | ||
|
|
||
| internal class DefaultPayloadModel | ||
| { | ||
| public Guid Id { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| namespace Umbraco.Cms.Core.Models; | ||
|
|
||
| public class Webhook | ||
| { | ||
| public Webhook(string url, bool? enabled = null, Guid[]? entityKeys = null, string[]? events = null, IDictionary<string, string>? headers = null) | ||
| { | ||
| Url = url; | ||
| Headers = headers ?? new Dictionary<string, string>(); | ||
| Events = events ?? Array.Empty<string>(); | ||
| ContentTypeKeys = entityKeys ?? Array.Empty<Guid>(); | ||
| Enabled = enabled ?? false; | ||
| } | ||
|
|
||
| public int Id { get; set; } | ||
|
|
||
| public Guid Key { get; set; } | ||
|
|
||
| public string Url { get; set; } | ||
|
|
||
| public string[] Events { get; set; } | ||
|
|
||
| public Guid[] ContentTypeKeys {get; set; } | ||
|
|
||
| public bool Enabled { get; set; } | ||
|
|
||
| public IDictionary<string, string> Headers { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| namespace Umbraco.Cms.Core.Models; | ||
|
|
||
| public class WebhookLog | ||
| { | ||
| public int Id { get; set; } | ||
|
|
||
| public Guid WebhookKey { get; set; } | ||
|
|
||
| public Guid Key { get; set; } | ||
|
|
||
| public string Url { get; set; } = string.Empty; | ||
|
|
||
| public string StatusCode { get; set; } = string.Empty; | ||
|
|
||
| public DateTime Date { get; set; } | ||
|
|
||
| public string EventName { get; set; } = string.Empty; | ||
|
|
||
| public int RetryCount { get; set; } | ||
|
|
||
| public string RequestHeaders { get; set; } = string.Empty; | ||
|
|
||
| public string? RequestBody { get; set; } = string.Empty; | ||
|
|
||
| public string ResponseHeaders { get; set; } = string.Empty; | ||
|
|
||
| public string ResponseBody { get; set; } = string.Empty; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| namespace Umbraco.Cms.Core.Models; | ||
|
|
||
| public class WebhookResponseModel | ||
| { | ||
| public HttpResponseMessage? HttpResponseMessage { get; set; } | ||
|
|
||
| public int RetryCount { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| namespace Umbraco.Cms.Core; | ||
|
|
||
| public static class PaginationHelper | ||
| { | ||
| public static void ConvertSkipTakeToPaging(int skip, int take, out long pageNumber, out int pageSize) | ||
| { | ||
| if (skip % take != 0) | ||
| { | ||
| throw new ArgumentException("Invalid skip/take, Skip must be a multiple of take - i.e. skip = 10, take = 5"); | ||
| } | ||
|
|
||
| pageSize = take; | ||
| pageNumber = skip / take; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Umbraco.Core/Persistence/Repositories/IWebhookLogRepository.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Webhooks; | ||
|
|
||
| namespace Umbraco.Cms.Core.Persistence.Repositories; | ||
|
|
||
| public interface IWebhookLogRepository | ||
| { | ||
| Task CreateAsync(WebhookLog log); | ||
|
|
||
| Task<PagedModel<WebhookLog>> GetPagedAsync(int skip, int take); | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/Umbraco.Core/Persistence/Repositories/IWebhookRepository.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using Umbraco.Cms.Core.Models; | ||
|
|
||
| namespace Umbraco.Cms.Core.Persistence.Repositories; | ||
|
|
||
| public interface IWebhookRepository | ||
| { | ||
| /// <summary> | ||
| /// Gets all of the webhooks in the current database. | ||
| /// </summary> | ||
| /// <param name="skip">Number of entries to skip.</param> | ||
| /// <param name="take">Number of entries to take.</param> | ||
| /// <returns>A paged model of <see cref="Webhook" /> objects.</returns> | ||
| Task<PagedModel<Webhook>> GetAllAsync(int skip, int take); | ||
|
|
||
| /// <summary> | ||
| /// Gets all of the webhooks in the current database. | ||
| /// </summary> | ||
| /// <param name="webhook">The webhook you want to create.</param> | ||
| /// <returns>The created <see cref="Webhook" /> webhook</returns> | ||
| Task<Webhook> CreateAsync(Webhook webhook); | ||
|
|
||
| /// <summary> | ||
| /// Gets a webhook by key | ||
| /// </summary> | ||
| /// <param name="key">The key of the webhook which will be retrieved.</param> | ||
| /// <returns>The <see cref="Webhook" /> webhook with the given key.</returns> | ||
| Task<Webhook?> GetAsync(Guid key); | ||
|
|
||
| /// <summary> | ||
| /// Gets a webhook by key | ||
| /// </summary> | ||
| /// <param name="eventName">The key of the webhook which will be retrieved.</param> | ||
| /// <returns>The <see cref="Webhook" /> webhook with the given key.</returns> | ||
| Task<PagedModel<Webhook>> GetByEventNameAsync(string eventName); | ||
|
|
||
| /// <summary> | ||
| /// Gets a webhook by key | ||
| /// </summary> | ||
| /// <param name="webhook">The webhook to be deleted.</param> | ||
| /// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns> | ||
| Task DeleteAsync(Webhook webhook); | ||
|
|
||
| /// <summary> | ||
| /// Updates a given webhook | ||
| /// </summary> | ||
| /// <param name="webhook">The webhook to be updated.</param> | ||
| /// <returns>The updated <see cref="Webhook" /> webhook.</returns> | ||
| Task UpdateAsync(Webhook webhook); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using Umbraco.Cms.Core.Models; | ||
|
|
||
| namespace Umbraco.Cms.Core.Services; | ||
|
|
||
| public interface IWebHookService | ||
| { | ||
| Task<Webhook> CreateAsync(Webhook webhook); | ||
|
|
||
| Task UpdateAsync(Webhook webhook); | ||
|
|
||
| Task DeleteAsync(Guid key); | ||
|
|
||
| Task<Webhook?> GetAsync(Guid key); | ||
|
|
||
| Task<PagedModel<Webhook>> GetAllAsync(int skip, int take); | ||
|
|
||
| Task<IEnumerable<Webhook>> GetByEventNameAsync(string eventName); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Umbraco.Cms.Core.Models; | ||
|
|
||
| namespace Umbraco.Cms.Core.Services; | ||
|
|
||
| public interface IWebhookFiringService | ||
| { | ||
| Task FireAsync(Webhook webhook, string eventName, object? payload, CancellationToken cancellationToken); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Webhooks; | ||
|
|
||
| namespace Umbraco.Cms.Core.Services; | ||
|
|
||
| public interface IWebhookLogFactory | ||
| { | ||
| Task<WebhookLog> CreateAsync(string eventName, WebhookResponseModel responseModel, Webhook webhook, CancellationToken cancellationToken); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to keep this in singular form @Zeegaan ?
So
Webhooklike we have User, Folder, Template... although Packages are plural. Maybe we should have aPackageconstant instead and eventually obsolete thePackagesconstant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, sounds correct to me! 😁
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Zeegaan does it require VS2022 17.8.0 preview to run
v13/devbranch?I tried to enable .NET 8 preview
https://anthonygiretti.com/2023/06/10/net-8-why-net-8-preview-doesnt-show-up-in-visual-studio-2022/
but it seems to return these warnings.
so not sure if the static assets are built correct as I get this error on startup:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using VS personally (Rider 😍) But yes presumably you'd have to use a preview of VS, when using the dotnet 8 rc-2 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://dotnetthoughts.net/working-with-dotnet8-projects-in-vs2022/
Yes, I think it requires the latest VS2022 preview to run for now:
dotnet/core#8790
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just edited in VS 2022, but ran via command line next to it: