Skip to content

Commit f14922b

Browse files
Adds name and description to webhooks (#18217)
* Model, service, test and migration updates to add name and description to webhook. * Update typed client models. * Fixed migration. * Front-end rendering and update of name and description. * Updated OpenApi.json * Reworked integration tests to avoid breaking change. * add name and description to editor header * remove name and description properties * render name as first column in the table * remove focus from url * remove required from name * add parentheses to align UX * add webhook paths * use edit path const in collection * add paths for root * remove unused * remove unused state --------- Co-authored-by: Mads Rasmussen <[email protected]>
1 parent 25a3788 commit f14922b

File tree

26 files changed

+342
-54
lines changed

26 files changed

+342
-54
lines changed

src/Umbraco.Cms.Api.Management/Factories/WebhookPresentationFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public WebhookResponseModel CreateResponseModel(IWebhook webhook)
2929
var target = new WebhookResponseModel
3030
{
3131
Events = webhook.Events.Select(Create).ToArray(),
32+
Name = webhook.Name,
33+
Description = webhook.Description,
3234
Url = webhook.Url,
3335
Enabled = webhook.Enabled,
3436
Id = webhook.Key,
@@ -44,6 +46,8 @@ public IWebhook CreateWebhook(CreateWebhookRequestModel webhookRequestModel)
4446
var target = new Webhook(webhookRequestModel.Url, webhookRequestModel.Enabled, webhookRequestModel.ContentTypeKeys, webhookRequestModel.Events, webhookRequestModel.Headers)
4547
{
4648
Key = webhookRequestModel.Id ?? Guid.NewGuid(),
49+
Name = webhookRequestModel.Name,
50+
Description = webhookRequestModel.Description,
4751
};
4852
return target;
4953
}
@@ -53,6 +57,8 @@ public IWebhook CreateWebhook(UpdateWebhookRequestModel webhookRequestModel, Gui
5357
var target = new Webhook(webhookRequestModel.Url, webhookRequestModel.Enabled, webhookRequestModel.ContentTypeKeys, webhookRequestModel.Events, webhookRequestModel.Headers)
5458
{
5559
Key = existingWebhookkey,
60+
Name = webhookRequestModel.Name,
61+
Description = webhookRequestModel.Description,
5662
};
5763
return target;
5864
}

src/Umbraco.Cms.Api.Management/Mapping/Item/ItemTypeMapDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private static void Map(IUserGroup source, UserGroupItemResponseModel target, Ma
120120
// Umbraco.Code.MapAll
121121
private static void Map(IWebhook source, WebhookItemResponseModel target, MapperContext context)
122122
{
123-
target.Name = string.Empty; //source.Name;
123+
target.Name = source.Name ?? source.Url;
124124
target.Url = source.Url;
125125
target.Enabled = source.Enabled;
126126
target.Events = string.Join(",", source.Events);

src/Umbraco.Cms.Api.Management/OpenApi.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35940,6 +35940,14 @@
3594035940
"enabled": {
3594135941
"type": "boolean"
3594235942
},
35943+
"name": {
35944+
"type": "string",
35945+
"nullable": true
35946+
},
35947+
"description": {
35948+
"type": "string",
35949+
"nullable": true
35950+
},
3594335951
"url": {
3594435952
"minLength": 1,
3594535953
"type": "string"
@@ -45448,6 +45456,14 @@
4544845456
"enabled": {
4544945457
"type": "boolean"
4545045458
},
45459+
"name": {
45460+
"type": "string",
45461+
"nullable": true
45462+
},
45463+
"description": {
45464+
"type": "string",
45465+
"nullable": true
45466+
},
4545145467
"url": {
4545245468
"minLength": 1,
4545345469
"type": "string"
@@ -46339,6 +46355,14 @@
4633946355
"enabled": {
4634046356
"type": "boolean"
4634146357
},
46358+
"name": {
46359+
"type": "string",
46360+
"nullable": true
46361+
},
46362+
"description": {
46363+
"type": "string",
46364+
"nullable": true
46365+
},
4634246366
"url": {
4634346367
"minLength": 1,
4634446368
"type": "string"

src/Umbraco.Cms.Api.Management/ViewModels/Webhook/WebhookModelBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public class WebhookModelBase
66
{
77
public bool Enabled { get; set; } = true;
88

9+
public string? Name { get; set; }
10+
11+
public string? Description { get; set; }
12+
913
[Required]
1014
public string Url { get; set; } = string.Empty;
1115

src/Umbraco.Core/Models/IWebhook.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
using Umbraco.Cms.Core.Models.Entities;
1+
using Umbraco.Cms.Core.Models.Entities;
22

33
namespace Umbraco.Cms.Core.Models;
44

55
public interface IWebhook : IEntity
66
{
7+
// TODO (V16): Remove the default implementations from this interface.
8+
string? Name
9+
{
10+
get { return null; }
11+
set { }
12+
}
13+
14+
string? Description
15+
{
16+
get { return null; }
17+
set { }
18+
}
19+
720
string Url { get; set; }
821

922
string[] Events { get; set; }

src/Umbraco.Core/Models/Webhook.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Umbraco.Cms.Core.Models.Entities;
1+
using Umbraco.Cms.Core.Models.Entities;
22
using Umbraco.Extensions;
33

44
namespace Umbraco.Cms.Core.Models;
@@ -24,6 +24,8 @@ private static readonly DelegateEqualityComparer<IDictionary<string, string>>
2424
(enumerable, translations) => enumerable.UnsortedSequenceEqual(translations),
2525
enumerable => enumerable.GetHashCode());
2626

27+
private string? _name;
28+
private string? _description;
2729
private string _url;
2830
private string[] _events;
2931
private Guid[] _contentTypeKeys;
@@ -39,6 +41,18 @@ public Webhook(string url, bool? enabled = null, Guid[]? entityKeys = null, stri
3941
_enabled = enabled ?? false;
4042
}
4143

44+
public string? Name
45+
{
46+
get => _name;
47+
set => SetPropertyValueAndDetectChanges(value, ref _name!, nameof(Name));
48+
}
49+
50+
public string? Description
51+
{
52+
get => _description;
53+
set => SetPropertyValueAndDetectChanges(value, ref _description!, nameof(Description));
54+
}
55+
4256
public string Url
4357
{
4458
get => _url;

src/Umbraco.Core/Services/WebhookService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public async Task<Attempt<IWebhook, WebhookOperationStatus>> UpdateAsync(IWebhoo
8888
currentWebhook.Enabled = webhook.Enabled;
8989
currentWebhook.ContentTypeKeys = webhook.ContentTypeKeys;
9090
currentWebhook.Events = webhook.Events;
91+
currentWebhook.Name = webhook.Name;
92+
currentWebhook.Description = webhook.Description;
9193
currentWebhook.Url = webhook.Url;
9294
currentWebhook.Headers = webhook.Headers;
9395

src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ protected virtual void DefinePlan()
104104
To<V_15_0_0.ConvertBlockGridEditorProperties>("{9D3CE7D4-4884-41D4-98E8-302EB6CB0CF6}");
105105
To<V_15_0_0.ConvertRichTextEditorProperties>("{37875E80-5CDD-42FF-A21A-7D4E3E23E0ED}");
106106
To<V_15_0_0.ConvertLocalLinks>("{42E44F9E-7262-4269-922D-7310CB48E724}");
107+
108+
// To 15.1.0
107109
To<V_15_1_0.RebuildCacheMigration>("{7B51B4DE-5574-4484-993E-05D12D9ED703}");
108110
To<V_15_1_0.FixConvertLocalLinks>("{F3D3EF46-1B1F-47DB-B437-7D573EEDEB98}");
111+
112+
// To 15.3.0
113+
To<V_15_3_0.AddNameAndDescriptionToWebhooks>("{7B11F01E-EE33-4B0B-81A1-F78F834CA45B}");
109114
}
110115
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Microsoft.Extensions.Logging;
2+
using Umbraco.Cms.Core;
3+
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
4+
using Umbraco.Extensions;
5+
6+
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_15_3_0;
7+
8+
public class AddNameAndDescriptionToWebhooks : MigrationBase
9+
{
10+
private readonly ILogger<AddNameAndDescriptionToWebhooks> _logger;
11+
12+
public AddNameAndDescriptionToWebhooks(IMigrationContext context, ILogger<AddNameAndDescriptionToWebhooks> logger)
13+
: base(context)
14+
{
15+
_logger = logger;
16+
}
17+
18+
protected override void Migrate()
19+
{
20+
Logger.LogDebug("Adding name and description columns to webhooks.");
21+
22+
if (TableExists(Constants.DatabaseSchema.Tables.Webhook))
23+
{
24+
var columns = Context.SqlContext.SqlSyntax.GetColumnsInSchema(Context.Database).ToList();
25+
26+
AddColumn(columns, "name");
27+
AddColumn(columns, "description");
28+
}
29+
else
30+
{
31+
Logger.LogWarning($"Table {Constants.DatabaseSchema.Tables.Webhook} does not exist so the addition of the name and description by columnss in migration {nameof(AddNameAndDescriptionToWebhooks)} cannot be completed.");
32+
}
33+
}
34+
35+
private void AddColumn(List<Persistence.SqlSyntax.ColumnInfo> columns, string column)
36+
{
37+
if (columns
38+
.SingleOrDefault(x => x.TableName == Constants.DatabaseSchema.Tables.Webhook && x.ColumnName == column) is null)
39+
{
40+
AddColumn<WebhookDto>(Constants.DatabaseSchema.Tables.Webhook, column);
41+
}
42+
}
43+
}

src/Umbraco.Infrastructure/Persistence/Dtos/WebhookDto.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using NPoco;
1+
using NPoco;
22
using Umbraco.Cms.Core;
33
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
44

@@ -18,6 +18,15 @@ internal class WebhookDto
1818
[NullSetting(NullSetting = NullSettings.NotNull)]
1919
public Guid Key { get; set; }
2020

21+
[Column(Name = "name")]
22+
[NullSetting(NullSetting = NullSettings.Null)]
23+
public string? Name { get; set; }
24+
25+
[Column(Name = "description")]
26+
[SpecialDbType(SpecialDbTypes.NVARCHARMAX)]
27+
[NullSetting(NullSetting = NullSettings.Null)]
28+
public string? Description { get; set; }
29+
2130
[Column(Name = "url")]
2231
[SpecialDbType(SpecialDbTypes.NVARCHARMAX)]
2332
[NullSetting(NullSetting = NullSettings.NotNull)]

0 commit comments

Comments
 (0)