From c55f1185e6f690a6b498fb725d18cbbf89d557ab Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 12 Apr 2019 14:43:07 +0900 Subject: [PATCH] Revert "Do not show all apps in Server settings policy" This reverts commit 1619666befd4bf8931a11a8c2927de4c5b1add86. --- BTCPayServer/Controllers/ServerController.cs | 34 ++++++++++---------- BTCPayServer/Services/Apps/AppService.cs | 12 +++---- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/BTCPayServer/Controllers/ServerController.cs b/BTCPayServer/Controllers/ServerController.cs index 45bd054a8..f4ab44835 100644 --- a/BTCPayServer/Controllers/ServerController.cs +++ b/BTCPayServer/Controllers/ServerController.cs @@ -44,7 +44,7 @@ namespace BTCPayServer.Controllers LightningConfigurationProvider _LnConfigProvider; private readonly TorServices _torServices; BTCPayServerOptions _Options; - AppService _AppService; + ApplicationDbContextFactory _ContextFactory; public ServerController(UserManager userManager, BTCPayServerOptions options, @@ -55,7 +55,7 @@ namespace BTCPayServer.Controllers LightningConfigurationProvider lnConfigProvider, TorServices torServices, StoreRepository storeRepository, - AppService appService) + ApplicationDbContextFactory contextFactory) { _Options = options; _UserManager = userManager; @@ -66,7 +66,7 @@ namespace BTCPayServer.Controllers _StoreRepository = storeRepository; _LnConfigProvider = lnConfigProvider; _torServices = torServices; - _AppService = appService; + _ContextFactory = contextFactory; } [Route("server/rates")] @@ -448,13 +448,17 @@ namespace BTCPayServer.Controllers { var data = (await _SettingsRepository.GetSettingAsync()) ?? new PoliciesSettings(); - var userId = _UserManager.GetUserId(base.User); - var selectList = (await _AppService.GetAllApps(userId)) - .Select(a => - new SelectListItem($"{a.AppType} - {a.AppName}", a.Id) + // load display app dropdown + using (var ctx = _ContextFactory.CreateContext()) + { + var selectList = ctx.Apps.Select(a => + new SelectListItem($"{a.AppType} - {a.Name}", a.Id) ).ToList(); - selectList.Insert(0, new SelectListItem("(None)", null)); - ViewBag.AppsList = new SelectList(selectList, "Value", "Text", data.RootAppId); + selectList.Insert(0, new SelectListItem("(None)", null)); + + ViewBag.AppsList = new SelectList(selectList, "Value", "Text", data.RootAppId); + } + return View(data); } [Route("server/policies")] @@ -463,15 +467,11 @@ namespace BTCPayServer.Controllers { if (!String.IsNullOrEmpty(settings.RootAppId)) { - var userId = _UserManager.GetUserId(base.User); - var appData = await _AppService.GetApp(settings.RootAppId, null); - if (appData != null) + using (var ctx = _ContextFactory.CreateContext()) { - settings.RootAppType = Enum.Parse(appData.AppType); - } - else - { - settings.RootAppType = null; + var app = ctx.Apps.SingleOrDefault(a => a.Id == settings.RootAppId); + if (app != null) + settings.RootAppType = Enum.Parse(app.AppType); } } else diff --git a/BTCPayServer/Services/Apps/AppService.cs b/BTCPayServer/Services/Apps/AppService.cs index c7b85bbdc..095084936 100644 --- a/BTCPayServer/Services/Apps/AppService.cs +++ b/BTCPayServer/Services/Apps/AppService.cs @@ -208,12 +208,12 @@ namespace BTCPayServer.Services.Apps } } - public async Task GetAllApps(string userId) + public async Task GetAllApps(string userId, bool allowNoUser = false) { using (var ctx = _ContextFactory.CreateContext()) { return await ctx.UserStore - .Where(us => us.ApplicationUserId == userId) + .Where(us => (allowNoUser && string.IsNullOrEmpty(userId)) || us.ApplicationUserId == userId) .Join(ctx.Apps, us => us.StoreDataId, app => app.StoreDataId, (us, app) => new ListAppsViewModel.ListAppViewModel() @@ -230,15 +230,13 @@ namespace BTCPayServer.Services.Apps } - public async Task GetApp(string appId, AppType? appType, bool includeStore = false) + public async Task GetApp(string appId, AppType appType, bool includeStore = false) { using (var ctx = _ContextFactory.CreateContext()) { var query = ctx.Apps - .Where(us => us.Id == appId); - - if (appType is AppType appTypeValue) - query = query.Where(us => us.AppType == appTypeValue.ToString()); + .Where(us => us.Id == appId && + us.AppType == appType.ToString()); if (includeStore) {