Skip to content

Commit d13278a

Browse files
authored
V14: Webhook endpoint fixes (#16215)
* Update to use presentation factory * remove unused usings * Update delete endpoint to work * Remember to map key * Map key for updating webhooks
1 parent f9c0235 commit d13278a

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

src/Umbraco.Cms.Api.Management/Controllers/Webhook/CreateWebhookController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using Microsoft.AspNetCore.Authorization;
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
5+
using Umbraco.Cms.Api.Management.Factories;
56
using Umbraco.Cms.Api.Management.ViewModels.Webhook;
67
using Umbraco.Cms.Core;
7-
using Umbraco.Cms.Core.Mapping;
88
using Umbraco.Cms.Core.Models;
99
using Umbraco.Cms.Core.Services;
1010
using Umbraco.Cms.Core.Services.OperationStatus;
@@ -17,13 +17,13 @@ namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
1717
public class CreateWebhookController : WebhookControllerBase
1818
{
1919
private readonly IWebhookService _webhookService;
20-
private readonly IUmbracoMapper _umbracoMapper;
20+
private readonly IWebhookPresentationFactory _webhookPresentationFactory;
2121

2222
public CreateWebhookController(
23-
IWebhookService webhookService, IUmbracoMapper umbracoMapper)
23+
IWebhookService webhookService, IWebhookPresentationFactory webhookPresentationFactory)
2424
{
2525
_webhookService = webhookService;
26-
_umbracoMapper = umbracoMapper;
26+
_webhookPresentationFactory = webhookPresentationFactory;
2727
}
2828

2929
[HttpPost]
@@ -35,7 +35,7 @@ public async Task<IActionResult> Create(
3535
CancellationToken cancellationToken,
3636
CreateWebhookRequestModel createWebhookRequestModel)
3737
{
38-
IWebhook created = _umbracoMapper.Map<IWebhook>(createWebhookRequestModel)!;
38+
IWebhook created = _webhookPresentationFactory.CreateWebhook(createWebhookRequestModel);
3939

4040
Attempt<IWebhook, WebhookOperationStatus> result = await _webhookService.CreateAsync(created);
4141

src/Umbraco.Cms.Api.Management/Controllers/Webhook/DeleteWebhookController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public DeleteWebhookController(IWebhookService webhookService, IBackOfficeSecuri
2424
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
2525
}
2626

27-
[HttpDelete($"{{{nameof(id)}}}")]
27+
[HttpDelete("{id:guid}")]
2828
[MapToApiVersion("1.0")]
2929
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
3030
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]

src/Umbraco.Cms.Api.Management/Controllers/Webhook/UpdateWebhookController.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
using Microsoft.AspNetCore.Authorization;
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
5+
using Umbraco.Cms.Api.Management.Factories;
56
using Umbraco.Cms.Api.Management.ViewModels.Webhook;
67
using Umbraco.Cms.Core;
7-
using Umbraco.Cms.Core.Mapping;
88
using Umbraco.Cms.Core.Models;
9-
using Umbraco.Cms.Core.Security;
109
using Umbraco.Cms.Core.Services;
1110
using Umbraco.Cms.Core.Services.OperationStatus;
12-
using Umbraco.Cms.Core.Webhooks;
1311
using Umbraco.Cms.Web.Common.Authorization;
1412

1513
namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
@@ -19,14 +17,14 @@ namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
1917
public class UpdateWebhookController : WebhookControllerBase
2018
{
2119
private readonly IWebhookService _webhookService;
22-
private readonly IUmbracoMapper _umbracoMapper;
20+
private readonly IWebhookPresentationFactory _webhookPresentationFactory;
21+
2322

2423
public UpdateWebhookController(
25-
IWebhookService webhookService,
26-
IUmbracoMapper umbracoMapper)
24+
IWebhookService webhookService, IWebhookPresentationFactory webhookPresentationFactory)
2725
{
2826
_webhookService = webhookService;
29-
_umbracoMapper = umbracoMapper;
27+
_webhookPresentationFactory = webhookPresentationFactory;
3028
}
3129

3230
[HttpPut("{id:guid}")]
@@ -45,7 +43,7 @@ public async Task<IActionResult> Update(
4543
return WebhookNotFound();
4644
}
4745

48-
IWebhook updated = _umbracoMapper.Map(updateWebhookRequestModel, current);
46+
IWebhook updated = _webhookPresentationFactory.CreateWebhook(updateWebhookRequestModel, id);
4947

5048
Attempt<IWebhook, WebhookOperationStatus> result = await _webhookService.UpdateAsync(updated);
5149

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ public interface IWebhookPresentationFactory
1010

1111
IWebhook CreateWebhook(CreateWebhookRequestModel webhookRequestModel);
1212

13-
IWebhook CreateWebhook(UpdateWebhookRequestModel webhookRequestModel);
13+
IWebhook CreateWebhook(UpdateWebhookRequestModel webhookRequestModel, Guid existingWebhookKey);
1414
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ public WebhookResponseModel CreateResponseModel(IWebhook webhook)
2828

2929
public IWebhook CreateWebhook(CreateWebhookRequestModel webhookRequestModel)
3030
{
31-
var target = new Webhook(webhookRequestModel.Url, webhookRequestModel.Enabled, webhookRequestModel.ContentTypeKeys, webhookRequestModel.Events, webhookRequestModel.Headers);
31+
var target = new Webhook(webhookRequestModel.Url, webhookRequestModel.Enabled, webhookRequestModel.ContentTypeKeys, webhookRequestModel.Events, webhookRequestModel.Headers)
32+
{
33+
Key = webhookRequestModel.Id ?? Guid.NewGuid(),
34+
};
3235
return target;
3336
}
3437

35-
public IWebhook CreateWebhook(UpdateWebhookRequestModel webhookRequestModel)
38+
public IWebhook CreateWebhook(UpdateWebhookRequestModel webhookRequestModel, Guid existingWebhookkey)
3639
{
37-
var target = new Webhook(webhookRequestModel.Url, webhookRequestModel.Enabled, webhookRequestModel.ContentTypeKeys, webhookRequestModel.Events, webhookRequestModel.Headers);
40+
var target = new Webhook(webhookRequestModel.Url, webhookRequestModel.Enabled, webhookRequestModel.ContentTypeKeys, webhookRequestModel.Events, webhookRequestModel.Headers)
41+
{
42+
Key = existingWebhookkey,
43+
};
3844
return target;
3945
}
4046

0 commit comments

Comments
 (0)