btcpayserver/BTCPayServer/Controllers/GreenField/GreenfieldTestApiKeyController.cs

80 lines
2.9 KiB
C#
Raw Normal View History

using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
2020-03-19 19:11:15 +09:00
using BTCPayServer.Client;
using BTCPayServer.Data;
using BTCPayServer.Security;
using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
2022-01-14 13:05:23 +09:00
namespace BTCPayServer.Controllers.Greenfield
{
/// <summary>
/// this controller serves as a testing endpoint for our api key unit tests
/// </summary>
[Route("api/test/apikey")]
[ApiController]
2020-03-23 14:23:23 +01:00
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[EnableCors(CorsPolicies.All)]
2022-01-07 12:17:59 +09:00
public class GreenfieldTestApiKeyController : ControllerBase
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly StoreRepository _storeRepository;
private readonly BTCPayServerClient _localBTCPayServerClient;
2022-01-07 12:17:59 +09:00
public GreenfieldTestApiKeyController(UserManager<ApplicationUser> userManager, StoreRepository storeRepository, BTCPayServerClient localBTCPayServerClient)
{
_userManager = userManager;
_storeRepository = storeRepository;
_localBTCPayServerClient = localBTCPayServerClient;
}
[HttpGet("me/id")]
2020-03-23 14:23:23 +01:00
[Authorize(Policy = Policies.CanViewProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public string GetCurrentUserId()
{
return _userManager.GetUserId(User);
}
[HttpGet("me")]
2020-03-23 14:23:23 +01:00
[Authorize(Policy = Policies.CanViewProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public async Task<ApplicationUser> GetCurrentUser()
{
return await _userManager.GetUserAsync(User);
}
[HttpGet("me/is-admin")]
2020-03-23 14:23:23 +01:00
[Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public bool AmIAnAdmin()
{
2019-10-12 20:35:30 +09:00
return true;
}
[HttpGet("me/stores")]
2020-03-23 14:23:23 +01:00
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public BTCPayServer.Client.Models.StoreData[] GetCurrentUserStores()
{
return this.HttpContext.GetStoresData().Select(Greenfield.GreenfieldStoresController.FromModel).ToArray();
}
2020-03-19 19:11:15 +09:00
[HttpGet("me/stores/{storeId}/can-view")]
[Authorize(Policy = Policies.CanViewStoreSettings,
2020-03-23 14:23:23 +01:00
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
2020-03-19 19:11:15 +09:00
public bool CanViewStore(string storeId)
{
return true;
}
[HttpGet("me/stores/{storeId}/can-edit")]
[Authorize(Policy = Policies.CanModifyStoreSettings,
2020-03-23 14:23:23 +01:00
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
2020-03-19 19:11:15 +09:00
public bool CanEditStore(string storeId)
{
return true;
}
}
}