From a6fe61d5084baa447088c6fd44916b9ee22ac4fd Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 23 Feb 2021 16:51:11 +0100 Subject: [PATCH 1/3] Fix missing view name --- BTCPayServer/Controllers/StoresController.Integrations.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/StoresController.Integrations.cs b/BTCPayServer/Controllers/StoresController.Integrations.cs index 6e342f572..ed75d161b 100644 --- a/BTCPayServer/Controllers/StoresController.Integrations.cs +++ b/BTCPayServer/Controllers/StoresController.Integrations.cs @@ -238,7 +238,7 @@ namespace BTCPayServer.Controllers public async Task NewWebhook(string storeId, EditWebhookViewModel viewModel) { if (!ModelState.IsValid) - return View(viewModel); + return View(nameof(ModifyWebhook), viewModel); var webhookId = await _Repo.CreateWebhook(CurrentStore.Id, viewModel.CreateBlob()); TempData[WellKnownTempData.SuccessMessage] = "The webhook has been created"; From 5e7836b29330a1dd5c09038ea5ee8ebc435c5e3a Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 23 Feb 2021 16:51:58 +0100 Subject: [PATCH 2/3] Controller cleanups --- .../StoresController.Integrations.cs | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.Integrations.cs b/BTCPayServer/Controllers/StoresController.Integrations.cs index ed75d161b..05b565280 100644 --- a/BTCPayServer/Controllers/StoresController.Integrations.cs +++ b/BTCPayServer/Controllers/StoresController.Integrations.cs @@ -166,7 +166,6 @@ namespace BTCPayServer.Controllers return NotFound(); } - [HttpGet] [Route("{storeId}/integrations")] [Route("{storeId}/integrations/shopify")] @@ -179,11 +178,10 @@ namespace BTCPayServer.Controllers return View("Integrations", vm); } - [HttpGet] - [Route("{storeId}/webhooks")] + [HttpGet("{storeId}/webhooks")] public async Task Webhooks() { - var webhooks = await this._Repo.GetWebhooks(CurrentStore.Id); + var webhooks = await _Repo.GetWebhooks(CurrentStore.Id); return View(nameof(Webhooks), new WebhooksViewModel() { Webhooks = webhooks.Select(w => new WebhooksViewModel.WebhookViewModel() @@ -193,11 +191,11 @@ namespace BTCPayServer.Controllers }).ToArray() }); } - [HttpGet] - [Route("{storeId}/webhooks/new")] + + [HttpGet("{storeId}/webhooks/new")] public IActionResult NewWebhook() { - return View(nameof(ModifyWebhook), new EditWebhookViewModel() + return View(nameof(ModifyWebhook), new EditWebhookViewModel { Active = true, Everything = true, @@ -206,14 +204,14 @@ namespace BTCPayServer.Controllers }); } - [HttpGet] - [Route("{storeId}/webhooks/{webhookId}/remove")] + [HttpGet("{storeId}/webhooks/{webhookId}/remove")] public async Task DeleteWebhook(string webhookId) { var webhook = await _Repo.GetWebhook(CurrentStore.Id, webhookId); if (webhook is null) return NotFound(); - return View("Confirm", new ConfirmModel() + + return View("Confirm", new ConfirmModel { Title = $"Delete a webhook", Description = "This webhook will be removed from this store, do you wish to continue?", @@ -221,36 +219,36 @@ namespace BTCPayServer.Controllers }); } - [HttpPost] - [Route("{storeId}/webhooks/{webhookId}/remove")] + [HttpPost("{storeId}/webhooks/{webhookId}/remove")] public async Task DeleteWebhookPost(string webhookId) { var webhook = await _Repo.GetWebhook(CurrentStore.Id, webhookId); if (webhook is null) return NotFound(); + await _Repo.DeleteWebhook(CurrentStore.Id, webhookId); TempData[WellKnownTempData.SuccessMessage] = "Webhook successfully deleted"; return RedirectToAction(nameof(Webhooks), new { storeId = CurrentStore.Id }); } - [HttpPost] - [Route("{storeId}/webhooks/new")] + [HttpPost("{storeId}/webhooks/new")] public async Task NewWebhook(string storeId, EditWebhookViewModel viewModel) { if (!ModelState.IsValid) return View(nameof(ModifyWebhook), viewModel); - var webhookId = await _Repo.CreateWebhook(CurrentStore.Id, viewModel.CreateBlob()); + await _Repo.CreateWebhook(CurrentStore.Id, viewModel.CreateBlob()); TempData[WellKnownTempData.SuccessMessage] = "The webhook has been created"; return RedirectToAction(nameof(Webhooks), new { storeId }); } - [HttpGet] - [Route("{storeId}/webhooks/{webhookId}")] + + [HttpGet("{storeId}/webhooks/{webhookId}")] public async Task ModifyWebhook(string webhookId) { var webhook = await _Repo.GetWebhook(CurrentStore.Id, webhookId); if (webhook is null) return NotFound(); + var blob = webhook.GetBlob(); var deliveries = await _Repo.GetWebhookDeliveries(CurrentStore.Id, webhookId, 20); return View(nameof(ModifyWebhook), new EditWebhookViewModel(blob) @@ -259,8 +257,8 @@ namespace BTCPayServer.Controllers .Select(s => new DeliveryViewModel(s)).ToList() }); } - [HttpPost] - [Route("{storeId}/webhooks/{webhookId}")] + + [HttpPost("{storeId}/webhooks/{webhookId}")] public async Task ModifyWebhook(string webhookId, EditWebhookViewModel viewModel) { var webhook = await _Repo.GetWebhook(CurrentStore.Id, webhookId); @@ -272,16 +270,17 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(Webhooks), new { storeId = CurrentStore.Id }); } - [HttpPost] - [Route("{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/redeliver")] + [HttpPost("{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/redeliver")] public async Task RedeliverWebhook(string webhookId, string deliveryId) { var delivery = await _Repo.GetWebhookDelivery(CurrentStore.Id, webhookId, deliveryId); if (delivery is null) return NotFound(); + var newDeliveryId = await WebhookNotificationManager.Redeliver(deliveryId); if (newDeliveryId is null) return NotFound(); + TempData[WellKnownTempData.SuccessMessage] = "Successfully planned a redelivery"; return RedirectToAction(nameof(ModifyWebhook), new @@ -290,18 +289,18 @@ namespace BTCPayServer.Controllers webhookId }); } - [HttpGet] - [Route("{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/request")] + + [HttpGet("{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/request")] public async Task WebhookDelivery(string webhookId, string deliveryId) { var delivery = await _Repo.GetWebhookDelivery(CurrentStore.Id, webhookId, deliveryId); if (delivery is null) return NotFound(); - return this.File(delivery.GetBlob().Request, "application/json"); + + return File(delivery.GetBlob().Request, "application/json"); } - [HttpPost] - [Route("{storeId}/integrations/shopify")] + [HttpPost("{storeId}/integrations/shopify")] public async Task Integrations([FromServices] IHttpClientFactory clientFactory, IntegrationsViewModel vm, string command = "", string exampleUrl = "") { From 4d5b2c40338f9e2e5df75950b8933c763ebdcbd5 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 23 Feb 2021 16:57:21 +0100 Subject: [PATCH 3/3] Make Selenium test more robust Fixes an issue similar to what we fixed in #2293. --- BTCPayServer.Tests/SeleniumTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 2bd6c6587..ab7da72a1 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -711,8 +711,9 @@ namespace BTCPayServer.Tests Logs.Tester.LogInformation("Let's see if we can delete store with some webhooks inside"); s.GoToStore(storeId); - s.Driver.ExecuteJavaScript("window.scrollBy(0,1000);"); - s.Driver.FindElement(By.Id("danger-zone-expander")).Click(); + // Open danger zone via JS, because if we click the link it triggers the toggle animation. + // This leads to Selenium trying to click the button while it is moving resulting in an error. + s.Driver.ExecuteJavaScript("document.getElementById('danger-zone').classList.add('show')"); s.Driver.FindElement(By.Id("delete-store")).Click(); s.Driver.FindElement(By.Id("continue")).Click(); s.FindAlertMessage();