From 5fda21373e7a277a5c7e93a135ed3848bf0ae988 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 16 Apr 2021 15:31:09 +0200 Subject: [PATCH 1/6] Move enabling toggle to store overview --- .../AltcoinTests/AltcoinTests.cs | 76 +++++++++-------- BTCPayServer.Tests/SeleniumTester.cs | 11 ++- BTCPayServer.Tests/TestAccount.cs | 2 +- .../StoresController.LightningLike.cs | 36 +++++++- .../Controllers/StoresController.Onchain.cs | 48 ++++++++--- BTCPayServer/Controllers/StoresController.cs | 5 +- .../Views/Stores/AddLightningNode.cshtml | 6 -- BTCPayServer/Views/Stores/ModifyWallet.cshtml | 8 -- BTCPayServer/Views/Stores/UpdateStore.cshtml | 83 ++++++++++++------- 9 files changed, 175 insertions(+), 100 deletions(-) diff --git a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs index dbb1d68fb..503db3668 100644 --- a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs +++ b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs @@ -50,13 +50,14 @@ namespace BTCPayServer.Tests tester.ActivateLightning(); await tester.StartAsync(); var user = tester.NewAccount(); - user.GrantAccess(true); - user.RegisterDerivationScheme("BTC"); + var cryptoCode = "BTC"; + await user.GrantAccessAsync(true); + user.RegisterDerivationScheme(cryptoCode); user.RegisterDerivationScheme("LTC"); - user.RegisterLightningNode("BTC", LightningConnectionType.CLightning); - var btcNetwork = tester.PayTester.Networks.GetNetwork("BTC"); - var invoice = user.BitPay.CreateInvoice( - new Invoice() + user.RegisterLightningNode(cryptoCode, LightningConnectionType.CLightning); + var btcNetwork = tester.PayTester.Networks.GetNetwork(cryptoCode); + var invoice = await user.BitPay.CreateInvoiceAsync( + new Invoice { Price = 1.5m, Currency = "USD", @@ -69,36 +70,43 @@ namespace BTCPayServer.Tests Assert.Equal(3, invoice.CryptoInfo.Length); var controller = user.GetController(); - var lightningVm = (LightningNodeViewModel)Assert.IsType(controller.AddLightningNode(user.StoreId, "BTC")).Model; + var lightningVm = (LightningNodeViewModel)Assert.IsType(controller.AddLightningNode(user.StoreId, cryptoCode)).Model; Assert.True(lightningVm.Enabled); - lightningVm.Enabled = false; - controller.AddLightningNode(user.StoreId, lightningVm, "save", "BTC").GetAwaiter().GetResult(); - lightningVm = (LightningNodeViewModel)Assert.IsType(controller.AddLightningNode(user.StoreId, "BTC")).Model; - Assert.False(lightningVm.Enabled); + var response = await controller.SetLightningNodeEnabled(user.StoreId, cryptoCode, false); + Assert.IsType(response); + + // Get enabled state from overview action + StoreViewModel storeModel; + response = controller.UpdateStore(); + storeModel = (StoreViewModel)Assert.IsType(response).Model; + var lnNode = storeModel.LightningNodes.Find(node => node.CryptoCode == cryptoCode); + Assert.NotNull(lnNode); + Assert.False(lnNode.Enabled); WalletSetupViewModel setupVm; var storeId = user.StoreId; - var cryptoCode = "BTC"; - var response = await controller.GenerateWallet(storeId, cryptoCode, WalletSetupMethod.GenerateOptions, new GenerateWalletRequest()); + response = await controller.GenerateWallet(storeId, cryptoCode, WalletSetupMethod.GenerateOptions, new GenerateWalletRequest()); Assert.IsType(response); - // Get setup view model from modify action - response = await controller.ModifyWallet(new WalletSetupViewModel { StoreId = storeId, CryptoCode = cryptoCode }); - setupVm = (WalletSetupViewModel)Assert.IsType(response).Model; - Assert.True(setupVm.Enabled); + // Get enabled state from overview action + response = controller.UpdateStore(); + storeModel = (StoreViewModel)Assert.IsType(response).Model; + var derivationScheme = storeModel.DerivationSchemes.Find(scheme => scheme.Crypto == cryptoCode); + Assert.NotNull(derivationScheme); + Assert.True(derivationScheme.Enabled); - // Only Enabling/Disabling the payment method must redirect to store page - setupVm.Enabled = false; - response = controller.UpdateWallet(setupVm).GetAwaiter().GetResult(); + // Disable wallet + response = controller.SetWalletEnabled(storeId, cryptoCode, false).GetAwaiter().GetResult(); Assert.IsType(response); + response = controller.UpdateStore(); + storeModel = (StoreViewModel)Assert.IsType(response).Model; + derivationScheme = storeModel.DerivationSchemes.Find(scheme => scheme.Crypto == cryptoCode); + Assert.NotNull(derivationScheme); + Assert.False(derivationScheme.Enabled); - response = await controller.ModifyWallet(new WalletSetupViewModel { StoreId = storeId, CryptoCode = cryptoCode }); - setupVm = (WalletSetupViewModel)Assert.IsType(response).Model; - Assert.False(setupVm.Enabled); + var oldScheme = derivationScheme.Value; - var oldScheme = setupVm.DerivationScheme; - - invoice = user.BitPay.CreateInvoice( + invoice = await user.BitPay.CreateInvoiceAsync( new Invoice { Price = 1.5m, @@ -113,7 +121,7 @@ namespace BTCPayServer.Tests Assert.Equal("LTC", invoice.CryptoInfo[0].CryptoCode); // Removing the derivation scheme, should redirect to store page - response = controller.ConfirmDeleteWallet(user.StoreId, "BTC").GetAwaiter().GetResult(); + response = controller.ConfirmDeleteWallet(user.StoreId, cryptoCode).GetAwaiter().GetResult(); Assert.IsType(response); // Setting it again should show the confirmation page @@ -172,8 +180,8 @@ namespace BTCPayServer.Tests Assert.Equal(expected.ToJson(), onchainBTC.ToJson()); // Let's check that the root hdkey and account key path are taken into account when making a PSBT - invoice = user.BitPay.CreateInvoice( - new Invoice() + invoice = await user.BitPay.CreateInvoiceAsync( + new Invoice { Price = 1.5m, Currency = "USD", @@ -184,7 +192,7 @@ namespace BTCPayServer.Tests }, Facade.Merchant); tester.ExplorerNode.Generate(1); - var invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo.First(c => c.CryptoCode == "BTC").Address, + var invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo.First(c => c.CryptoCode == cryptoCode).Address, tester.ExplorerNode.Network); tester.ExplorerNode.SendToAddress(invoiceAddress, Money.Coins(1m)); TestUtils.Eventually(() => @@ -196,9 +204,9 @@ namespace BTCPayServer.Tests var psbt = wallet.CreatePSBT(btcNetwork, onchainBTC, new WalletSendModel() { - Outputs = new List() + Outputs = new List { - new WalletSendModel.TransactionOutput() + new WalletSendModel.TransactionOutput { Amount = 0.5m, DestinationAddress = new Key().PubKey.GetAddress(ScriptPubKeyType.Legacy, btcNetwork.NBitcoinNetwork) @@ -304,7 +312,7 @@ namespace BTCPayServer.Tests var controller = tester.PayTester.GetController(null); var checkout = - (Models.InvoicingModels.PaymentModel)((JsonResult)controller.GetStatus(invoice.Id, null) + (Models.InvoicingModels.PaymentModel)((JsonResult)controller.GetStatus(invoice.Id) .GetAwaiter().GetResult()).Value; Assert.Single(checkout.AvailableCryptos); Assert.Equal("LTC", checkout.CryptoCode); @@ -321,7 +329,7 @@ namespace BTCPayServer.Tests { invoice = user.BitPay.GetInvoice(invoice.Id); Assert.Equal("paid", invoice.Status); - checkout = (Models.InvoicingModels.PaymentModel)((JsonResult)controller.GetStatus(invoice.Id, null) + checkout = (Models.InvoicingModels.PaymentModel)((JsonResult)controller.GetStatus(invoice.Id) .GetAwaiter().GetResult()).Value; Assert.Equal("paid", checkout.Status); }); diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index ed6fc00ca..2e2920e93 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -219,13 +219,18 @@ namespace BTCPayServer.Tests Driver.FindElement(By.Id("ConnectionString")).SendKeys(connectionString); } - var enabled = Driver.FindElement(By.Id("Enabled")); - if (!enabled.Selected) enabled.Click(); - Driver.FindElement(By.Id("test")).Click(); Assert.Contains("Connection to the Lightning node succeeded.", FindAlertMessage().Text); Driver.FindElement(By.Id("save")).Click(); + Assert.Contains($"{cryptoCode} Lightning node modified.", FindAlertMessage().Text); + + var enabled = Driver.FindElement(By.Id($"{cryptoCode}LightningEnabled")); + if (enabled.Text == "Enable") + { + enabled.Click(); + Assert.Contains($"{cryptoCode} Lightning payments are now enabled for this store.", FindAlertMessage().Text); + } } public void ClickOnAllSideMenus() diff --git a/BTCPayServer.Tests/TestAccount.cs b/BTCPayServer.Tests/TestAccount.cs index 9c062a26a..9ca8ce943 100644 --- a/BTCPayServer.Tests/TestAccount.cs +++ b/BTCPayServer.Tests/TestAccount.cs @@ -274,7 +274,7 @@ namespace BTCPayServer.Tests var nodeType = connectionString == LightningSupportedPaymentMethod.InternalNode ? LightningNodeType.Internal : LightningNodeType.Custom; await storeController.AddLightningNode(storeId ?? StoreId, - new LightningNodeViewModel { ConnectionString = connectionString, LightningNodeType = nodeType, SkipPortTest = true }, "save", "BTC"); + new LightningNodeViewModel { ConnectionString = connectionString, LightningNodeType = nodeType, SkipPortTest = true }, "save", cryptoCode); if (storeController.ModelState.ErrorCount != 0) Assert.False(true, storeController.ModelState.FirstOrDefault().Value.Errors[0].ErrorMessage); } diff --git a/BTCPayServer/Controllers/StoresController.LightningLike.cs b/BTCPayServer/Controllers/StoresController.LightningLike.cs index ed93635e9..74397c0ac 100644 --- a/BTCPayServer/Controllers/StoresController.LightningLike.cs +++ b/BTCPayServer/Controllers/StoresController.LightningLike.cs @@ -48,6 +48,8 @@ namespace BTCPayServer.Controllers } var paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike); + var lightning = GetExistingLightningSupportedPaymentMethod(vm.CryptoCode, store); + LightningSupportedPaymentMethod paymentMethod = null; if (vm.LightningNodeType == LightningNodeType.Internal) { @@ -96,7 +98,6 @@ namespace BTCPayServer.Controllers { case "save": var storeBlob = store.GetStoreBlob(); - storeBlob.SetExcluded(paymentMethodId, !vm.Enabled); storeBlob.Hints.Lightning = false; store.SetStoreBlob(storeBlob); store.SetSupportedPaymentMethod(paymentMethodId, paymentMethod); @@ -128,6 +129,38 @@ namespace BTCPayServer.Controllers } } + [HttpPost("{storeId}/lightning/{cryptoCode}/status")] + public async Task SetLightningNodeEnabled(string storeId, string cryptoCode, bool enabled) + { + var store = HttpContext.GetStoreData(); + if (store == null) + return NotFound(); + + var network = cryptoCode == null ? null : _ExplorerProvider.GetNetwork(cryptoCode); + if (network == null) + return NotFound(); + + var lightning = GetExistingLightningSupportedPaymentMethod(cryptoCode, store); + if (lightning == null) + return NotFound(); + + if (!User.IsInRole(Roles.ServerAdmin)) + { + TempData[WellKnownTempData.ErrorMessage] = $"Only the server admin can {(enabled ? "enable" : "disable")} the lightning node"; + } + else + { + var paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike); + var storeBlob = store.GetStoreBlob(); + storeBlob.SetExcluded(paymentMethodId, !enabled); + store.SetStoreBlob(storeBlob); + await _Repo.UpdateStore(store); + TempData[WellKnownTempData.SuccessMessage] = $"{network.CryptoCode} Lightning payments are now {(enabled ? "enabled" : "disabled")} for this store."; + } + + return RedirectToAction(nameof(UpdateStore), new { storeId }); + } + private bool CanUseInternalLightning() { return User.IsInRole(Roles.ServerAdmin) || _CssThemeManager.AllowLightningInternalNodeForAll; @@ -141,7 +174,6 @@ namespace BTCPayServer.Controllers vm.LightningNodeType = lightning.IsInternalNode ? LightningNodeType.Internal : LightningNodeType.Custom; vm.ConnectionString = lightning.GetDisplayableConnectionString(); } - vm.Enabled = !store.GetStoreBlob().IsExcluded(new PaymentMethodId(vm.CryptoCode, PaymentTypes.LightningLike)) && lightning != null; vm.CanUseInternalNode = CanUseInternalLightning(); } diff --git a/BTCPayServer/Controllers/StoresController.Onchain.cs b/BTCPayServer/Controllers/StoresController.Onchain.cs index fa0c66bca..13f651842 100644 --- a/BTCPayServer/Controllers/StoresController.Onchain.cs +++ b/BTCPayServer/Controllers/StoresController.Onchain.cs @@ -157,9 +157,7 @@ namespace BTCPayServer.Controllers var configChanged = oldConfig != vm.Config; PaymentMethodId paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike); var storeBlob = store.GetStoreBlob(); - var wasExcluded = storeBlob.GetExcludedPaymentMethods().Match(paymentMethodId); var willBeExcluded = !vm.Enabled; - var excludedChanged = willBeExcluded != wasExcluded; var showAddress = // Show addresses if: // - If the user is testing the hint address in confirmation screen @@ -188,17 +186,7 @@ namespace BTCPayServer.Controllers await _Repo.UpdateStore(store); _EventAggregator.Publish(new WalletChangedEvent {WalletId = new WalletId(vm.StoreId, vm.CryptoCode)}); - if (excludedChanged) - { - var label = willBeExcluded ? "disabled" : "enabled"; - TempData[WellKnownTempData.SuccessMessage] = - $"On-Chain payments for {network.CryptoCode} have been {label}."; - } - else - { - TempData[WellKnownTempData.SuccessMessage] = - $"Derivation settings for {network.CryptoCode} have been modified."; - } + TempData[WellKnownTempData.SuccessMessage] = $"Derivation settings for {network.CryptoCode} have been modified."; // This is success case when derivation scheme is added to the store return RedirectToAction(nameof(UpdateStore), new {storeId = vm.StoreId}); @@ -506,6 +494,40 @@ namespace BTCPayServer.Controllers }); } + [HttpPost("{storeId}/onchain/{cryptoCode}/status")] + public async Task SetWalletEnabled(string storeId, string cryptoCode, bool enabled) + { + var checkResult = IsAvailable(cryptoCode, out var store, out var network); + if (checkResult != null) + { + return checkResult; + } + + var derivation = GetExistingDerivationStrategy(cryptoCode, store); + if (derivation == null) + { + return NotFound(); + } + + var wallet = _WalletProvider.GetWallet(network); + if (wallet == null) + { + return NotFound(); + } + + var paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike); + var storeBlob = store.GetStoreBlob(); + storeBlob.SetExcluded(paymentMethodId, !enabled); + store.SetStoreBlob(storeBlob); + await _Repo.UpdateStore(store); + _EventAggregator.Publish(new WalletChangedEvent {WalletId = new WalletId(storeId, cryptoCode)}); + + TempData[WellKnownTempData.SuccessMessage] = + $"{network.CryptoCode} on-chain payments are now {(enabled ? "enabled" : "disabled")} for this store."; + + return RedirectToAction(nameof(UpdateStore), new {storeId}); + } + [HttpPost("{storeId}/onchain/{cryptoCode}/delete")] public async Task ConfirmDeleteWallet(string storeId, string cryptoCode) { diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index e2260ff94..83c174342 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -544,11 +544,12 @@ namespace BTCPayServer.Controllers break; case LightningPaymentType _: var lightning = lightningByCryptoCode.TryGet(paymentMethodId.CryptoCode); - vm.LightningNodes.Add(new StoreViewModel.LightningNode() + var isEnabled = !excludeFilters.Match(paymentMethodId) && lightning != null; + vm.LightningNodes.Add(new StoreViewModel.LightningNode { CryptoCode = paymentMethodId.CryptoCode, Address = lightning?.GetDisplayableConnectionString(), - Enabled = !excludeFilters.Match(paymentMethodId) && lightning != null + Enabled = isEnabled }); break; } diff --git a/BTCPayServer/Views/Stores/AddLightningNode.cshtml b/BTCPayServer/Views/Stores/AddLightningNode.cshtml index 949019e97..b5b162056 100644 --- a/BTCPayServer/Views/Stores/AddLightningNode.cshtml +++ b/BTCPayServer/Views/Stores/AddLightningNode.cshtml @@ -97,12 +97,6 @@ - - - -
- -
diff --git a/BTCPayServer/Views/Stores/ModifyWallet.cshtml b/BTCPayServer/Views/Stores/ModifyWallet.cshtml index 884094a1c..f36023902 100644 --- a/BTCPayServer/Views/Stores/ModifyWallet.cshtml +++ b/BTCPayServer/Views/Stores/ModifyWallet.cshtml @@ -48,14 +48,6 @@ Type @(Model.IsHotWallet ? "Hot wallet" : "Watch-only wallet") - - - Enabled - - - - - diff --git a/BTCPayServer/Views/Stores/UpdateStore.cshtml b/BTCPayServer/Views/Stores/UpdateStore.cshtml index 2aacebbd7..b9a90ec7f 100644 --- a/BTCPayServer/Views/Stores/UpdateStore.cshtml +++ b/BTCPayServer/Views/Stores/UpdateStore.cshtml @@ -42,30 +42,36 @@ } - @if (scheme.Enabled) - { - - - Enabled - - } - else - { - - - Disabled - - } +
+ + @if (scheme.Enabled) + { + + Enabled + + } + else + { + + Disabled + + } +
@if (isSetUp) { | - + Modify } else { - + Setup } @@ -107,27 +113,42 @@ { @scheme.Address } + + Public Node Info +
- @if (scheme.Enabled) - { - - - Enabled - - } - else - { - - - Disabled - - } +
+ + @if (scheme.Enabled) + { + + Enabled + + } + else + { + + Disabled + + } +
+ @if (isSetUp) { | } - + @(isSetUp ? "Modify" : "Setup")
From 85cf36ac4a6f311bab85ab6ef2837cd41077ad4f Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 20 Apr 2021 10:55:28 +0900 Subject: [PATCH 2/6] Update BTCPayServer.Tests/SeleniumTester.cs Co-authored-by: Zaxounette <51208677+Zaxounette@users.noreply.github.com> --- BTCPayServer.Tests/SeleniumTester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 2e2920e93..66dead23c 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -220,7 +220,7 @@ namespace BTCPayServer.Tests } Driver.FindElement(By.Id("test")).Click(); - Assert.Contains("Connection to the Lightning node succeeded.", FindAlertMessage().Text); + Assert.Contains("Connection to the Lightning node successful.", FindAlertMessage().Text); Driver.FindElement(By.Id("save")).Click(); Assert.Contains($"{cryptoCode} Lightning node modified.", FindAlertMessage().Text); From b2ff64733d3222c2d9cabd74389d2e97a3e659da Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 20 Apr 2021 10:55:36 +0900 Subject: [PATCH 3/6] Update BTCPayServer/Controllers/StoresController.Onchain.cs Co-authored-by: Zaxounette <51208677+Zaxounette@users.noreply.github.com> --- BTCPayServer/Controllers/StoresController.Onchain.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer/Controllers/StoresController.Onchain.cs b/BTCPayServer/Controllers/StoresController.Onchain.cs index 13f651842..08203f5f4 100644 --- a/BTCPayServer/Controllers/StoresController.Onchain.cs +++ b/BTCPayServer/Controllers/StoresController.Onchain.cs @@ -186,7 +186,7 @@ namespace BTCPayServer.Controllers await _Repo.UpdateStore(store); _EventAggregator.Publish(new WalletChangedEvent {WalletId = new WalletId(vm.StoreId, vm.CryptoCode)}); - TempData[WellKnownTempData.SuccessMessage] = $"Derivation settings for {network.CryptoCode} have been modified."; + TempData[WellKnownTempData.SuccessMessage] = $"Derivation settings for {network.CryptoCode} have been updated."; // This is success case when derivation scheme is added to the store return RedirectToAction(nameof(UpdateStore), new {storeId = vm.StoreId}); From 52be5746c6d729e29e157d1230518425c1f6c826 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 20 Apr 2021 10:55:41 +0900 Subject: [PATCH 4/6] Update BTCPayServer.Tests/SeleniumTester.cs Co-authored-by: Zaxounette <51208677+Zaxounette@users.noreply.github.com> --- BTCPayServer.Tests/SeleniumTester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 66dead23c..1414f0b0d 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -223,7 +223,7 @@ namespace BTCPayServer.Tests Assert.Contains("Connection to the Lightning node successful.", FindAlertMessage().Text); Driver.FindElement(By.Id("save")).Click(); - Assert.Contains($"{cryptoCode} Lightning node modified.", FindAlertMessage().Text); + Assert.Contains($"{cryptoCode} Lightning node updated.", FindAlertMessage().Text); var enabled = Driver.FindElement(By.Id($"{cryptoCode}LightningEnabled")); if (enabled.Text == "Enable") From aef06c7f610331867742f560e89570b897497ea9 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 20 Apr 2021 09:09:32 +0200 Subject: [PATCH 5/6] Wording updates Thanks @Zaxounette! --- BTCPayServer.Tests/SeleniumTests.cs | 2 +- BTCPayServer/Controllers/StoresController.LightningLike.cs | 4 ++-- BTCPayServer/Controllers/StoresController.Onchain.cs | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index d8eea140f..bd8e7a9f6 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -366,7 +366,7 @@ namespace BTCPayServer.Tests s.AddLightningNode(); s.Driver.AssertNoError(); var successAlert = s.FindAlertMessage(); - Assert.Contains("BTC Lightning node modified.", successAlert.Text); + Assert.Contains("BTC Lightning node updated.", successAlert.Text); Assert.False(s.Driver.PageSource.Contains(offchainHint), "Lightning hint should be dismissed at this point"); var storeUrl = s.Driver.Url; diff --git a/BTCPayServer/Controllers/StoresController.LightningLike.cs b/BTCPayServer/Controllers/StoresController.LightningLike.cs index 74397c0ac..8952ce75e 100644 --- a/BTCPayServer/Controllers/StoresController.LightningLike.cs +++ b/BTCPayServer/Controllers/StoresController.LightningLike.cs @@ -102,7 +102,7 @@ namespace BTCPayServer.Controllers store.SetStoreBlob(storeBlob); store.SetSupportedPaymentMethod(paymentMethodId, paymentMethod); await _Repo.UpdateStore(store); - TempData[WellKnownTempData.SuccessMessage] = $"{network.CryptoCode} Lightning node modified."; + TempData[WellKnownTempData.SuccessMessage] = $"{network.CryptoCode} Lightning node updated."; return RedirectToAction(nameof(UpdateStore), new { storeId }); case "test": @@ -115,7 +115,7 @@ namespace BTCPayServer.Controllers using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20)); await handler.TestConnection(info, cts.Token); } - TempData[WellKnownTempData.SuccessMessage] = $"Connection to the Lightning node succeeded. Your node address: {info}"; + TempData[WellKnownTempData.SuccessMessage] = $"Connection to the Lightning node successful. Your node address: {info}"; } catch (Exception ex) { diff --git a/BTCPayServer/Controllers/StoresController.Onchain.cs b/BTCPayServer/Controllers/StoresController.Onchain.cs index 08203f5f4..ede71dfef 100644 --- a/BTCPayServer/Controllers/StoresController.Onchain.cs +++ b/BTCPayServer/Controllers/StoresController.Onchain.cs @@ -377,8 +377,7 @@ namespace BTCPayServer.Controllers return checkResult; } - TempData[WellKnownTempData.SuccessMessage] = - $"Derivation settings for {network.CryptoCode} have been modified."; + TempData[WellKnownTempData.SuccessMessage] = $"Derivation settings for {network.CryptoCode} have been updated."; return RedirectToAction(nameof(UpdateStore), new {storeId}); } From 962c80fff87ad3ceda927ee719d7332c27936f4a Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 20 Apr 2021 09:10:23 +0200 Subject: [PATCH 6/6] Remove permission check Ensured via the controller, see https://github.com/btcpayserver/btcpayserver/pull/2469#discussion_r616289628 --- .../StoresController.LightningLike.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.LightningLike.cs b/BTCPayServer/Controllers/StoresController.LightningLike.cs index 8952ce75e..80b0fde50 100644 --- a/BTCPayServer/Controllers/StoresController.LightningLike.cs +++ b/BTCPayServer/Controllers/StoresController.LightningLike.cs @@ -144,19 +144,12 @@ namespace BTCPayServer.Controllers if (lightning == null) return NotFound(); - if (!User.IsInRole(Roles.ServerAdmin)) - { - TempData[WellKnownTempData.ErrorMessage] = $"Only the server admin can {(enabled ? "enable" : "disable")} the lightning node"; - } - else - { - var paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike); - var storeBlob = store.GetStoreBlob(); - storeBlob.SetExcluded(paymentMethodId, !enabled); - store.SetStoreBlob(storeBlob); - await _Repo.UpdateStore(store); - TempData[WellKnownTempData.SuccessMessage] = $"{network.CryptoCode} Lightning payments are now {(enabled ? "enabled" : "disabled")} for this store."; - } + var paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.LightningLike); + var storeBlob = store.GetStoreBlob(); + storeBlob.SetExcluded(paymentMethodId, !enabled); + store.SetStoreBlob(storeBlob); + await _Repo.UpdateStore(store); + TempData[WellKnownTempData.SuccessMessage] = $"{network.CryptoCode} Lightning payments are now {(enabled ? "enabled" : "disabled")} for this store."; return RedirectToAction(nameof(UpdateStore), new { storeId }); }