diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 84891a051..1a35d123f 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -925,7 +925,7 @@ namespace BTCPayServer.Tests private void AssertSearchInvoice(TestAccount acc, bool expected, string invoiceId, string filter, string storeId = null) { var result = - (InvoicesModel)((ViewResult)acc.GetController() + (InvoicesModel)((ViewResult)acc.GetController(storeId is not null) .ListInvoices(new InvoicesModel { SearchTerm = filter, StoreId = storeId }).Result).Model; Assert.Equal(expected, result.Invoices.Any(i => i.InvoiceId == invoiceId)); } diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index 925593c00..b4b2a21fe 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -799,17 +799,23 @@ namespace BTCPayServer.Controllers public async Task ListInvoices(InvoicesModel? model = null) { model = this.ParseListQuery(model ?? new InvoicesModel()); - var fs = new SearchString(model.SearchTerm); - var store = model.StoreId == null || fs.ContainsFilter("storeid") ? null : HttpContext.GetStoreData(); - var storeIds = store == null - ? fs.GetFilterArray("storeid") != null ? fs.GetFilterArray("storeid") : new List().ToArray() - : new[] { store.Id }; - - model.StoreIds = storeIds; + string? storeId = (model.StoreId ?? HttpContext.GetStoreData()?.Id); + var storeIds = new HashSet(); + if (fs.GetFilterArray("storeid") is string[] l) + { + foreach (var i in l) + storeIds.Add(i); + } + if (storeId is not null) + { + storeIds.Add(storeId); + model.StoreId = storeId; + } + model.StoreIds = storeIds.ToArray(); InvoiceQuery invoiceQuery = GetInvoiceQuery(model.SearchTerm, model.TimezoneOffset ?? 0); - invoiceQuery.StoreId = storeIds; + invoiceQuery.StoreId = model.StoreIds; var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery); invoiceQuery.Take = model.Count; invoiceQuery.Skip = model.Skip;