diff --git a/BTCPayServer.Client/Permissions.cs b/BTCPayServer.Client/Permissions.cs index 8087a620f..d8faa3bd7 100644 --- a/BTCPayServer.Client/Permissions.cs +++ b/BTCPayServer.Client/Permissions.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Globalization; using System.Linq; using System.Linq.Expressions; +using System.Text.RegularExpressions; namespace BTCPayServer.Client { @@ -16,7 +18,7 @@ namespace BTCPayServer.Client public const string CanUseLightningNodeInStore = "btcpay.store.canuselightningnode"; public const string CanModifyServerSettings = "btcpay.server.canmodifyserversettings"; public const string CanModifyStoreSettings = "btcpay.store.canmodifystoresettings"; - public const string CanModifyStoreWebhooks = "btcpay.store.webhooks.canmodifywebhooks"; + public const string CanModifyWebhooks = "btcpay.store.webhooks.canmodifywebhooks"; public const string CanModifyStoreSettingsUnscoped = "btcpay.store.canmodifystoresettings:"; public const string CanViewStoreSettings = "btcpay.store.canviewstoresettings"; public const string CanViewReports = "btcpay.store.canviewreports"; @@ -48,7 +50,7 @@ namespace BTCPayServer.Client yield return CanViewInvoices; yield return CanCreateInvoice; yield return CanModifyInvoices; - yield return CanModifyStoreWebhooks; + yield return CanModifyWebhooks; yield return CanModifyServerSettings; yield return CanModifyStoreSettings; yield return CanViewStoreSettings; @@ -104,6 +106,16 @@ namespace BTCPayServer.Client { return policy.StartsWith("btcpay.user", StringComparison.OrdinalIgnoreCase); } + + private static readonly CultureInfo _culture = new (CultureInfo.InvariantCulture.Name); + public static string DisplayName(string policy) + { + var p = policy.Split("."); + if (p.Length < 3 || p[0] != "btcpay") return policy; + var constName = typeof(Policies).GetFields().Select(f => f.Name).FirstOrDefault(f => f.Equals(p[^1], StringComparison.OrdinalIgnoreCase)); + var perm = string.IsNullOrEmpty(constName) ? string.Join(' ', p[2..]) : Regex.Replace(constName, "([A-Z])", " $1", RegexOptions.Compiled).Trim(); + return $"{_culture.TextInfo.ToTitleCase(p[1])}: {_culture.TextInfo.ToTitleCase(perm)}"; + } } public class PermissionSet @@ -247,7 +259,7 @@ namespace BTCPayServer.Client Policies.CanManagePullPayments, Policies.CanModifyInvoices, Policies.CanViewStoreSettings, - Policies.CanModifyStoreWebhooks, + Policies.CanModifyWebhooks, Policies.CanModifyPaymentRequests, Policies.CanManagePayouts, Policies.CanUseLightningNodeInStore); diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs index 2e4b518dc..ca3ebedaf 100644 --- a/BTCPayServer.Tests/GreenfieldAPITests.cs +++ b/BTCPayServer.Tests/GreenfieldAPITests.cs @@ -1711,7 +1711,7 @@ namespace BTCPayServer.Tests var user = tester.NewAccount(); user.GrantAccess(); user.RegisterDerivationScheme("BTC"); - var clientProfile = await user.CreateClient(Policies.CanModifyStoreWebhooks, Policies.CanCreateInvoice); + var clientProfile = await user.CreateClient(Policies.CanModifyWebhooks, Policies.CanCreateInvoice); var hook = await clientProfile.CreateWebhook(user.StoreId, new CreateStoreWebhookRequest() { Url = fakeServer.ServerUri.AbsoluteUri, diff --git a/BTCPayServer.Tests/TestAccount.cs b/BTCPayServer.Tests/TestAccount.cs index eba7b92e8..90889ff8e 100644 --- a/BTCPayServer.Tests/TestAccount.cs +++ b/BTCPayServer.Tests/TestAccount.cs @@ -527,7 +527,7 @@ retry: { var server = new FakeServer(); await server.Start(); - var client = await CreateClient(Policies.CanModifyStoreWebhooks); + var client = await CreateClient(Policies.CanModifyWebhooks); var wh = await client.CreateWebhook(StoreId, new CreateStoreWebhookRequest() { AutomaticRedelivery = false, diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoreWebhooksController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoreWebhooksController.cs index 3d9387dd7..f5d7f15fa 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoreWebhooksController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoreWebhooksController.cs @@ -24,7 +24,7 @@ namespace BTCPayServer.Controllers.Greenfield { [ApiController] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield, - Policy = Policies.CanModifyStoreWebhooks)] + Policy = Policies.CanModifyWebhooks)] [EnableCors(CorsPolicies.All)] public class GreenfieldStoreWebhooksController : ControllerBase { diff --git a/BTCPayServer/Controllers/UIManageController.APIKeys.cs b/BTCPayServer/Controllers/UIManageController.APIKeys.cs index b4d257635..92f182ab7 100644 --- a/BTCPayServer/Controllers/UIManageController.APIKeys.cs +++ b/BTCPayServer/Controllers/UIManageController.APIKeys.cs @@ -513,8 +513,8 @@ namespace BTCPayServer.Controllers {Policies.CanDeleteUser, ("Delete user", "Allows deleting the user to whom it is assigned. Admin users can delete any user without this permission.")}, {Policies.CanModifyStoreSettings, ("Modify your stores", "Allows managing invoices on all your stores and modify their settings.")}, {$"{Policies.CanModifyStoreSettings}:", ("Manage selected stores", "Allows managing invoices on the selected stores and modify their settings.")}, - {Policies.CanModifyStoreWebhooks, ("Modify stores webhooks", "Allows modifying the webhooks of all your stores.")}, - {$"{Policies.CanModifyStoreWebhooks}:", ("Modify selected stores' webhooks", "Allows modifying the webhooks of the selected stores.")}, + {Policies.CanModifyWebhooks, ("Modify stores webhooks", "Allows modifying the webhooks of all your stores.")}, + {$"{Policies.CanModifyWebhooks}:", ("Modify selected stores' webhooks", "Allows modifying the webhooks of the selected stores.")}, {Policies.CanViewStoreSettings, ("View your stores", "Allows viewing stores settings.")}, {$"{Policies.CanViewStoreSettings}:", ("View your stores", "Allows viewing the selected stores' settings.")}, {Policies.CanViewReports, ("View your reports", "Allows viewing reports.")}, diff --git a/BTCPayServer/Views/Shared/ListRoles.cshtml b/BTCPayServer/Views/Shared/ListRoles.cshtml index a29881910..ceb2e552c 100644 --- a/BTCPayServer/Views/Shared/ListRoles.cshtml +++ b/BTCPayServer/Views/Shared/ListRoles.cshtml @@ -96,7 +96,7 @@ { @foreach (var policy in role.Permissions) { - @policy + @Policies.DisplayName(policy) } }