From d99131c899ba83a2b629cc6ef73e4fa1b7be1cf8 Mon Sep 17 00:00:00 2001 From: Brant DeBow Date: Thu, 3 Apr 2025 11:23:47 -0400 Subject: [PATCH] Added Webhook Integration Controller --- .../WebhookIntegrationController.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Api/AdminConsole/Controllers/WebhookIntegrationController.cs diff --git a/src/Api/AdminConsole/Controllers/WebhookIntegrationController.cs b/src/Api/AdminConsole/Controllers/WebhookIntegrationController.cs new file mode 100644 index 0000000000..c19d7381e0 --- /dev/null +++ b/src/Api/AdminConsole/Controllers/WebhookIntegrationController.cs @@ -0,0 +1,51 @@ +using Bit.Core.AdminConsole.Entities; +using Bit.Core.Context; +using Bit.Core.Enums; +using Bit.Core.Exceptions; +using Bit.Core.Repositories; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Bit.Api.AdminConsole.Controllers; + +[Route("organizations/{organizationId:guid}/integrations/webhook/")] +[Authorize("Application")] +public class WebhookIntegrationController( + ICurrentContext currentContext, + IOrganizationIntegrationRepository integrationRepository) : Controller +{ + [HttpGet("create")] + public async Task CreateAsync(Guid organizationId) + { + if (!await currentContext.OrganizationOwner(organizationId)) + { + throw new NotFoundException(); + } + + var integration = await integrationRepository.CreateAsync(new OrganizationIntegration + { + OrganizationId = organizationId, + Type = IntegrationType.Webhook, + Configuration = null + }); + return Ok(new { id = integration.Id }); + } + + [HttpDelete("{integrationId:guid}")] + [HttpPost("{integrationId:guid}/delete")] + public async Task DeleteAsync(Guid organizationId, Guid integrationId) + { + if (!await currentContext.OrganizationOwner(organizationId)) + { + throw new NotFoundException(); + } + + var integration = await integrationRepository.GetByIdAsync(integrationId); + if (integration is null) + { + throw new NotFoundException(); + } + + await integrationRepository.DeleteAsync(integration); + } +}