prevent app creation without wallet creation (#6255)

* prevent app creation without wallet creation

* resolve test failures

* resolve selenium test
This commit is contained in:
Chukwuleta Tobechi
2024-09-27 07:28:55 +01:00
committed by GitHub
parent 9ba4b030ed
commit 83fa8cbf0f
4 changed files with 24 additions and 1 deletions

View File

@@ -39,6 +39,8 @@ namespace BTCPayServer.Tests
await user.GrantAccessAsync(); await user.GrantAccessAsync();
var user2 = tester.NewAccount(); var user2 = tester.NewAccount();
await user2.GrantAccessAsync(); await user2.GrantAccessAsync();
await user.RegisterDerivationSchemeAsync("BTC");
await user2.RegisterDerivationSchemeAsync("BTC");
var apps = user.GetController<UIAppsController>(); var apps = user.GetController<UIAppsController>();
var apps2 = user2.GetController<UIAppsController>(); var apps2 = user2.GetController<UIAppsController>();
var crowdfund = user.GetController<UICrowdfundController>(); var crowdfund = user.GetController<UICrowdfundController>();

View File

@@ -1238,6 +1238,7 @@ namespace BTCPayServer.Tests
await s.StartAsync(); await s.StartAsync();
var userId = s.RegisterNewUser(true); var userId = s.RegisterNewUser(true);
s.CreateNewStore(); s.CreateNewStore();
s.GenerateWallet();
(_, string appId) = s.CreateApp("PointOfSale"); (_, string appId) = s.CreateApp("PointOfSale");
s.Driver.FindElement(By.Id("Title")).Clear(); s.Driver.FindElement(By.Id("Title")).Clear();
s.Driver.FindElement(By.Id("Title")).SendKeys("Tea shop"); s.Driver.FindElement(By.Id("Title")).SendKeys("Tea shop");
@@ -1249,7 +1250,8 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id("CodeTabButton")).Click(); s.Driver.FindElement(By.Id("CodeTabButton")).Click();
var template = s.Driver.FindElement(By.Id("TemplateConfig")).GetAttribute("value"); var template = s.Driver.FindElement(By.Id("TemplateConfig")).GetAttribute("value");
Assert.Contains("\"buyButtonText\": \"Take my money\"", template); Assert.Contains("\"buyButtonText\": \"Take my money\"", template);
Assert.Matches("\"categories\": \\[\n\\s+\"Drinks\"\n\\s+\\]", template); Assert.Matches("\"categories\": \\[\r?\n\\s*\"Drinks\"\\s*\\]", template);
s.ClickPagePrimary(); s.ClickPagePrimary();
Assert.Contains("App updated", s.FindAlertMessage().Text); Assert.Contains("App updated", s.FindAlertMessage().Text);

View File

@@ -1844,6 +1844,8 @@ namespace BTCPayServer.Tests
await user.GrantAccessAsync(); await user.GrantAccessAsync();
var user2 = tester.NewAccount(); var user2 = tester.NewAccount();
await user2.GrantAccessAsync(); await user2.GrantAccessAsync();
await user.RegisterDerivationSchemeAsync("BTC");
await user2.RegisterDerivationSchemeAsync("BTC");
var stores = user.GetController<UIStoresController>(); var stores = user.GetController<UIStoresController>();
var apps = user.GetController<UIAppsController>(); var apps = user.GetController<UIAppsController>();
var apps2 = user2.GetController<UIAppsController>(); var apps2 = user2.GetController<UIAppsController>();

View File

@@ -24,12 +24,14 @@ namespace BTCPayServer.Controllers
{ {
public UIAppsController( public UIAppsController(
UserManager<ApplicationUser> userManager, UserManager<ApplicationUser> userManager,
BTCPayNetworkProvider networkProvider,
StoreRepository storeRepository, StoreRepository storeRepository,
IFileService fileService, IFileService fileService,
AppService appService, AppService appService,
IHtmlHelper html) IHtmlHelper html)
{ {
_userManager = userManager; _userManager = userManager;
_networkProvider = networkProvider;
_storeRepository = storeRepository; _storeRepository = storeRepository;
_fileService = fileService; _fileService = fileService;
_appService = appService; _appService = appService;
@@ -37,6 +39,7 @@ namespace BTCPayServer.Controllers
} }
private readonly UserManager<ApplicationUser> _userManager; private readonly UserManager<ApplicationUser> _userManager;
private readonly BTCPayNetworkProvider _networkProvider;
private readonly StoreRepository _storeRepository; private readonly StoreRepository _storeRepository;
private readonly IFileService _fileService; private readonly IFileService _fileService;
private readonly AppService _appService; private readonly AppService _appService;
@@ -133,6 +136,20 @@ namespace BTCPayServer.Controllers
public async Task<IActionResult> CreateApp(string storeId, CreateAppViewModel vm) public async Task<IActionResult> CreateApp(string storeId, CreateAppViewModel vm)
{ {
var store = GetCurrentStore(); var store = GetCurrentStore();
if (store == null)
{
return NotFound();
}
if (!store.AnyPaymentMethodAvailable())
{
TempData.SetStatusMessageModel(new StatusMessageModel
{
Severity = StatusMessageModel.StatusSeverity.Error,
Html = $"To create a {vm.AppType} app, you need to <a href='{Url.Action(nameof(UIStoresController.SetupWallet), "UIStores", new { cryptoCode = _networkProvider.DefaultNetwork.CryptoCode, storeId })}' class='alert-link'>set up a wallet</a> first",
AllowDismiss = false
});
return View(vm);
}
vm.StoreId = store.Id; vm.StoreId = store.Id;
var type = _appService.GetAppType(vm.AppType ?? vm.SelectedAppType); var type = _appService.GetAppType(vm.AppType ?? vm.SelectedAppType);
if (type is null) if (type is null)