mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Limit selection to one store
This commit is contained in:
committed by
Andrew Camilleri
parent
2b9cb4a257
commit
1bb35bf545
@@ -128,7 +128,7 @@ namespace BTCPayServer.Tests
|
|||||||
// No upfront store selection with only server settings
|
// No upfront store selection with only server settings
|
||||||
s.GoToUrl(authUrl);
|
s.GoToUrl(authUrl);
|
||||||
Assert.Contains(appidentifier, s.Driver.PageSource);
|
Assert.Contains(appidentifier, s.Driver.PageSource);
|
||||||
Assert.False(s.Driver.FindElement(By.Id("SpecificStores")).Displayed);
|
Assert.False(s.Driver.FindElement(By.Id("StoreId")).Displayed);
|
||||||
|
|
||||||
// Now with store settings
|
// Now with store settings
|
||||||
authUrl = BTCPayServerClient.GenerateAuthorizeUri(s.ServerUri,
|
authUrl = BTCPayServerClient.GenerateAuthorizeUri(s.ServerUri,
|
||||||
@@ -137,7 +137,7 @@ namespace BTCPayServer.Tests
|
|||||||
Assert.Contains(appidentifier, s.Driver.PageSource);
|
Assert.Contains(appidentifier, s.Driver.PageSource);
|
||||||
|
|
||||||
// Select a store
|
// Select a store
|
||||||
var select = new SelectElement(s.Driver.FindElement(By.Id("SpecificStores")));
|
var select = new SelectElement(s.Driver.FindElement(By.Id("StoreId")));
|
||||||
select.SelectByIndex(0);
|
select.SelectByIndex(0);
|
||||||
s.Driver.FindElement(By.Id("continue")).Click();
|
s.Driver.FindElement(By.Id("continue")).Click();
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ namespace BTCPayServer.Tests
|
|||||||
Assert.DoesNotContain("kukksappname", s.Driver.PageSource);
|
Assert.DoesNotContain("kukksappname", s.Driver.PageSource);
|
||||||
|
|
||||||
// Select a store
|
// Select a store
|
||||||
select = new SelectElement(s.Driver.FindElement(By.Id("SpecificStores")));
|
select = new SelectElement(s.Driver.FindElement(By.Id("StoreId")));
|
||||||
select.SelectByIndex(0);
|
select.SelectByIndex(0);
|
||||||
s.Driver.FindElement(By.Id("continue")).Click();
|
s.Driver.FindElement(By.Id("continue")).Click();
|
||||||
|
|
||||||
|
|||||||
@@ -300,7 +300,6 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
private void AdjustVMForAuthorization(AuthorizeApiKeysViewModel vm)
|
private void AdjustVMForAuthorization(AuthorizeApiKeysViewModel vm)
|
||||||
{
|
{
|
||||||
var storeIds = vm.SpecificStores.ToArray();
|
|
||||||
var permissions = vm.Permissions?.Split(';') ?? Array.Empty<string>();
|
var permissions = vm.Permissions?.Split(';') ?? Array.Empty<string>();
|
||||||
var permissionsWithStoreIDs = new List<string>();
|
var permissionsWithStoreIDs = new List<string>();
|
||||||
|
|
||||||
@@ -310,16 +309,13 @@ namespace BTCPayServer.Controllers
|
|||||||
// so that permission for a specific store is parsed correctly
|
// so that permission for a specific store is parsed correctly
|
||||||
foreach (var permission in permissions)
|
foreach (var permission in permissions)
|
||||||
{
|
{
|
||||||
if (!Policies.IsStorePolicy(permission) || storeIds.Length == 0)
|
if (!Policies.IsStorePolicy(permission) || string.IsNullOrEmpty(vm.StoreId))
|
||||||
{
|
{
|
||||||
permissionsWithStoreIDs.Add(permission);
|
permissionsWithStoreIDs.Add(permission);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var t in storeIds)
|
permissionsWithStoreIDs.Add($"{permission}:{vm.StoreId}");
|
||||||
{
|
|
||||||
permissionsWithStoreIDs.Add($"{permission}:{t}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,7 +577,7 @@ namespace BTCPayServer.Controllers
|
|||||||
public string Permissions { get; set; }
|
public string Permissions { get; set; }
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
public bool NeedsStorePermission { get; set; }
|
public bool NeedsStorePermission { get; set; }
|
||||||
public List<string> SpecificStores { get; set; } = new ();
|
public string StoreId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ApiKeysViewModel
|
public class ApiKeysViewModel
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
@{
|
@{
|
||||||
var displayName = Model.ApplicationName ?? Model.ApplicationIdentifier;
|
var displayName = Model.ApplicationName ?? Model.ApplicationIdentifier;
|
||||||
|
var store = string.IsNullOrEmpty(Model.StoreId) ? null : Model.Stores.FirstOrDefault(s => s.Id == Model.StoreId);
|
||||||
var permissions = Permission.ToPermissions(Model.Permissions.Split(';')).GroupBy(permission => permission.Policy);
|
var permissions = Permission.ToPermissions(Model.Permissions.Split(';')).GroupBy(permission => permission.Policy);
|
||||||
ViewData["Title"] = $"Authorize {displayName ?? "Application"}";
|
ViewData["Title"] = $"Authorize {displayName ?? "Application"}";
|
||||||
Layout = "_LayoutWizard";
|
Layout = "_LayoutWizard";
|
||||||
}
|
}
|
||||||
|
|
||||||
@section Navbar {
|
@section Navbar {
|
||||||
@if (Model.NeedsStorePermission && Model.SpecificStores.Any())
|
@if (Model.NeedsStorePermission && store != null)
|
||||||
{
|
{
|
||||||
<form method="post" asp-action="AuthorizeAPIKey" class="back">
|
<form method="post" asp-action="AuthorizeAPIKey" class="back">
|
||||||
<input type="hidden" asp-for="RedirectUrl" value="@Model.RedirectUrl"/>
|
<input type="hidden" asp-for="RedirectUrl" value="@Model.RedirectUrl"/>
|
||||||
@@ -45,7 +46,7 @@
|
|||||||
</header>
|
</header>
|
||||||
<div asp-validation-summary="All" class="text-danger"></div>
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
|
||||||
@if (Model.NeedsStorePermission && !Model.SpecificStores.Any())
|
@if (Model.NeedsStorePermission && store == null)
|
||||||
{
|
{
|
||||||
@if (!Model.Stores.Any())
|
@if (!Model.Stores.Any())
|
||||||
{
|
{
|
||||||
@@ -57,9 +58,9 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="SpecificStores" class="form-label">Select the stores to grant permission for</label>
|
<label asp-for="StoreId" class="form-label">Select the store to grant permission for</label>
|
||||||
<select asp-for="SpecificStores" class="form-select" asp-items="@(new SelectList(Model.Stores, nameof(StoreData.Id), nameof(StoreData.StoreName)))" required></select>
|
<select asp-for="StoreId" class="form-select" asp-items="@(new SelectList(Model.Stores, nameof(StoreData.Id), nameof(StoreData.StoreName)))" required></select>
|
||||||
<span asp-validation-for="SpecificStores" class="text-danger"></span>
|
<span asp-validation-for="StoreId" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex gap-3">
|
<div class="d-flex gap-3">
|
||||||
<button class="btn btn-primary" name="command" id="continue" type="submit" value="SelectStores">Continue</button>
|
<button class="btn btn-primary" name="command" id="continue" type="submit" value="SelectStores">Continue</button>
|
||||||
@@ -69,7 +70,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<select hidden asp-for="SpecificStores" class="form-select" asp-items="@(new SelectList(Model.Stores, nameof(StoreData.Id), nameof(StoreData.StoreName)))"></select>
|
<input type="hidden" asp-for="StoreId" class="form-select"/>
|
||||||
|
|
||||||
@if (Model.RedirectUrl != null)
|
@if (Model.RedirectUrl != null)
|
||||||
{
|
{
|
||||||
@@ -94,15 +95,12 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Model.NeedsStorePermission && Model.SpecificStores.Any())
|
if (Model.NeedsStorePermission)
|
||||||
{
|
{
|
||||||
<p class="mb-2">Store-based permissions will be applied for:</p>
|
<p class="mb-2">
|
||||||
<ul class="mb-4 ps-3">
|
Store-based permissions will be applied for
|
||||||
@foreach (var storeId in Model.SpecificStores)
|
<strong>@store.StoreName</strong>
|
||||||
{
|
</p>
|
||||||
<li>@Model.Stores.First(s => s.Id == storeId).StoreName</li>
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
}
|
}
|
||||||
<div class="list-group list-group-flush mt-3">
|
<div class="list-group list-group-flush mt-3">
|
||||||
@for (var i = 0; i < Model.PermissionValues.Count; i++)
|
@for (var i = 0; i < Model.PermissionValues.Count; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user