mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Disable export to JSON
This commit is contained in:
@@ -530,21 +530,6 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
|
|
||||||
[BitpayAPIConstraint(false)]
|
|
||||||
public async Task<IActionResult> Export(string format, string searchTerm = null)
|
|
||||||
{
|
|
||||||
var model = new ExportInvoicesModel
|
|
||||||
{
|
|
||||||
Format = format,
|
|
||||||
Invoices = await ListInvoicesProcess(searchTerm, 0, int.MaxValue)
|
|
||||||
};
|
|
||||||
|
|
||||||
return Content(model.Process(), "application/" + format);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
|
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
|
||||||
[BitpayAPIConstraint(false)]
|
[BitpayAPIConstraint(false)]
|
||||||
|
|||||||
@@ -99,9 +99,17 @@ namespace BTCPayServer.Controllers
|
|||||||
vm.Confirmation = false;
|
vm.Confirmation = false;
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
var storeBlob = store.GetStoreBlob();
|
||||||
|
var wasExcluded = storeBlob.GetExcludedPaymentMethods().Match(paymentMethodId);
|
||||||
|
var willBeExcluded = !vm.Enabled;
|
||||||
|
|
||||||
var showAddress = (vm.Confirmation && !string.IsNullOrWhiteSpace(vm.HintAddress)) || // Testing hint address
|
var showAddress = // Show addresses if:
|
||||||
(!vm.Confirmation && strategy != null && exisingStrategy != strategy.DerivationStrategyBase.ToString()); // Checking addresses after setting xpub
|
// - If the user is testing the hint address in confirmation screen
|
||||||
|
(vm.Confirmation && !string.IsNullOrWhiteSpace(vm.HintAddress)) ||
|
||||||
|
// - The user is setting a new derivation scheme
|
||||||
|
(!vm.Confirmation && strategy != null && exisingStrategy != strategy.DerivationStrategyBase.ToString()) ||
|
||||||
|
// - The user is clicking on continue without changing anything
|
||||||
|
(!vm.Confirmation && willBeExcluded == wasExcluded);
|
||||||
|
|
||||||
if (!showAddress)
|
if (!showAddress)
|
||||||
{
|
{
|
||||||
@@ -110,9 +118,7 @@ namespace BTCPayServer.Controllers
|
|||||||
if (strategy != null)
|
if (strategy != null)
|
||||||
await wallet.TrackAsync(strategy.DerivationStrategyBase);
|
await wallet.TrackAsync(strategy.DerivationStrategyBase);
|
||||||
store.SetSupportedPaymentMethod(paymentMethodId, strategy);
|
store.SetSupportedPaymentMethod(paymentMethodId, strategy);
|
||||||
|
storeBlob.SetExcluded(paymentMethodId, willBeExcluded);
|
||||||
var storeBlob = store.GetStoreBlob();
|
|
||||||
storeBlob.SetExcluded(paymentMethodId, !vm.Enabled);
|
|
||||||
store.SetStoreBlob(storeBlob);
|
store.SetStoreBlob(storeBlob);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using BTCPayServer.Services.Invoices;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Models.InvoicingModels
|
|
||||||
{
|
|
||||||
public class ExportInvoicesModel
|
|
||||||
{
|
|
||||||
public InvoiceEntity[] Invoices { get; set; }
|
|
||||||
public string Format { get; set; }
|
|
||||||
|
|
||||||
public string Process()
|
|
||||||
{
|
|
||||||
if (String.Equals(Format, "json", StringComparison.OrdinalIgnoreCase))
|
|
||||||
return processJson();
|
|
||||||
else
|
|
||||||
throw new Exception("Export format not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
private string processJson()
|
|
||||||
{
|
|
||||||
foreach (var i in Invoices)
|
|
||||||
{
|
|
||||||
// removing error causing complex circular dependencies
|
|
||||||
i.Payments?.ForEach(a =>
|
|
||||||
{
|
|
||||||
a.Output = null;
|
|
||||||
a.Outpoint = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var serializerSett = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
|
|
||||||
var json = JsonConvert.SerializeObject(new { Invoices }, Formatting.Indented, serializerSett);
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,14 +38,6 @@
|
|||||||
<div class="row no-gutter" style="margin-bottom: 5px;">
|
<div class="row no-gutter" style="margin-bottom: 5px;">
|
||||||
<div class="col-lg-4">
|
<div class="col-lg-4">
|
||||||
<a asp-action="CreateInvoice" class="btn btn-primary" role="button"><span class="fa fa-plus"></span> Create a new invoice</a>
|
<a asp-action="CreateInvoice" class="btn btn-primary" role="button"><span class="fa fa-plus"></span> Create a new invoice</a>
|
||||||
|
|
||||||
<a class="btn btn-primary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
||||||
Export
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
|
|
||||||
<a asp-action="Export" asp-route-format="json" asp-route-searchTerm="@Model.SearchTerm" class="dropdown-item" target="_blank">JSON</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-8">
|
||||||
|
|||||||
Reference in New Issue
Block a user