From b29b46bbc70fe081473505326cb5332696d830b0 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 20 Aug 2019 10:38:15 +0200 Subject: [PATCH] Add policy to allow internal lightning node for non-admins (#975) Partially related to #204 (but no actual management and accounting of funds in different stores occurs) --- BTCPayServer/Controllers/StoresController.LightningLike.cs | 2 +- BTCPayServer/Controllers/StoresController.cs | 6 +++++- BTCPayServer/HostedServices/CssThemeManager.cs | 3 +++ BTCPayServer/Services/PoliciesSettings.cs | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.LightningLike.cs b/BTCPayServer/Controllers/StoresController.LightningLike.cs index a5f998c8f..0c23c3a8b 100644 --- a/BTCPayServer/Controllers/StoresController.LightningLike.cs +++ b/BTCPayServer/Controllers/StoresController.LightningLike.cs @@ -178,7 +178,7 @@ namespace BTCPayServer.Controllers private bool CanUseInternalLightning() { - return (_BTCPayEnv.IsDevelopping || User.IsInRole(Roles.ServerAdmin)); + return (_BTCPayEnv.IsDevelopping || User.IsInRole(Roles.ServerAdmin) || _CssThemeManager.AllowLightningInternalNodeForAll); } } } diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 90834e3e4..288fc841c 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using BTCPayServer.Authentication; using BTCPayServer.Configuration; using BTCPayServer.Data; +using BTCPayServer.HostedServices; using BTCPayServer.Models; using BTCPayServer.Models.AppViewModels; using BTCPayServer.Models.StoreViewModels; @@ -58,7 +59,8 @@ namespace BTCPayServer.Controllers ChangellyClientProvider changellyClientProvider, IOptions mvcJsonOptions, IHostingEnvironment env, IHttpClientFactory httpClientFactory, - PaymentMethodHandlerDictionary paymentMethodHandlerDictionary) + PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, + CssThemeManager cssThemeManager) { _RateFactory = rateFactory; _Repo = repo; @@ -72,6 +74,7 @@ namespace BTCPayServer.Controllers _Env = env; _httpClientFactory = httpClientFactory; _paymentMethodHandlerDictionary = paymentMethodHandlerDictionary; + _CssThemeManager = cssThemeManager; _NetworkProvider = networkProvider; _ExplorerProvider = explorerProvider; _FeeRateProvider = feeRateProvider; @@ -95,6 +98,7 @@ namespace BTCPayServer.Controllers IHostingEnvironment _Env; private IHttpClientFactory _httpClientFactory; private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; + private readonly CssThemeManager _CssThemeManager; [TempData] public string StatusMessage diff --git a/BTCPayServer/HostedServices/CssThemeManager.cs b/BTCPayServer/HostedServices/CssThemeManager.cs index ddad80736..392305395 100644 --- a/BTCPayServer/HostedServices/CssThemeManager.cs +++ b/BTCPayServer/HostedServices/CssThemeManager.cs @@ -62,7 +62,10 @@ namespace BTCPayServer.HostedServices RootAppType = data.RootAppType; RootAppId = data.RootAppId; DomainToAppMapping = data.DomainToAppMapping; + AllowLightningInternalNodeForAll = data.AllowLightningInternalNodeForAll; } + + public bool AllowLightningInternalNodeForAll { get; set; } } public class ContentSecurityPolicyCssThemeManager : Attribute, IActionFilter, IOrderedFilter diff --git a/BTCPayServer/Services/PoliciesSettings.cs b/BTCPayServer/Services/PoliciesSettings.cs index 237b44b53..192a7be34 100644 --- a/BTCPayServer/Services/PoliciesSettings.cs +++ b/BTCPayServer/Services/PoliciesSettings.cs @@ -21,6 +21,8 @@ namespace BTCPayServer.Services [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] [Display(Name = "Discourage search engines from indexing this site")] public bool DiscourageSearchEngines { get; set; } + [Display(Name = "Allow non-admins to use the internal lightning node in their stores")] + public bool AllowLightningInternalNodeForAll { get; set; } [Display(Name = "Display app on website root")] public string RootAppId { get; set; }