OnlyIfSupportAttribute should use PaymentMethodId (#6274)

This commit is contained in:
Nicolas Dorier
2024-10-04 16:58:24 +09:00
committed by GitHub
parent 5704919b3a
commit 5190c25be0
5 changed files with 11 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Threading.Tasks;
using BTCPayServer.Payments;
using BTCPayServer.Services.Invoices;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
@@ -8,22 +10,21 @@ namespace BTCPayServer.Filters
{
public class OnlyIfSupportAttribute : Attribute, IAsyncActionFilter
{
private readonly string _cryptoCode;
private readonly string _paymentMethodId;
public OnlyIfSupportAttribute(string cryptoCode)
public OnlyIfSupportAttribute(string paymentMethodId)
{
_cryptoCode = cryptoCode;
_paymentMethodId = paymentMethodId;
}
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var options = context.HttpContext.RequestServices.GetService<BTCPayNetworkProvider>();
if (options.GetNetwork(_cryptoCode) == null)
var handlers = context.HttpContext.RequestServices.GetService<PaymentMethodHandlerDictionary>();
if (!handlers.Support(PaymentMethodId.Parse(_paymentMethodId)))
{
context.Result = new NotFoundResult();
return;
}
await next();
}
}

View File

@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Services.Altcoins.Monero.RPC
{
[Route("[controller]")]
[OnlyIfSupportAttribute("XMR")]
[OnlyIfSupportAttribute("XMR-CHAIN")]
public class MoneroLikeDaemonCallbackController : Controller
{
private readonly EventAggregator _eventAggregator;

View File

@@ -29,7 +29,7 @@ using Microsoft.AspNetCore.Mvc.Rendering;
namespace BTCPayServer.Services.Altcoins.Monero.UI
{
[Route("stores/{storeId}/monerolike")]
[OnlyIfSupportAttribute("XMR")]
[OnlyIfSupportAttribute("XMR-CHAIN")]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]

View File

@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Services.Altcoins.Zcash.RPC
{
[Route("[controller]")]
[OnlyIfSupportAttribute("ZEC")]
[OnlyIfSupportAttribute("ZEC-CHAIN")]
public class ZcashLikeDaemonCallbackController : Controller
{
private readonly EventAggregator _eventAggregator;

View File

@@ -30,7 +30,7 @@ using Microsoft.AspNetCore.Mvc.Rendering;
namespace BTCPayServer.Services.Altcoins.Zcash.UI
{
[Route("stores/{storeId}/Zcashlike")]
[OnlyIfSupportAttribute("ZEC")]
[OnlyIfSupportAttribute("ZEC-CHAIN")]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]