Revert "Do not show all apps in Server settings policy"

This reverts commit 1619666bef.
This commit is contained in:
nicolas.dorier
2019-04-12 14:43:07 +09:00
parent 1619666bef
commit c55f1185e6
2 changed files with 22 additions and 24 deletions

View File

@@ -44,7 +44,7 @@ namespace BTCPayServer.Controllers
LightningConfigurationProvider _LnConfigProvider; LightningConfigurationProvider _LnConfigProvider;
private readonly TorServices _torServices; private readonly TorServices _torServices;
BTCPayServerOptions _Options; BTCPayServerOptions _Options;
AppService _AppService; ApplicationDbContextFactory _ContextFactory;
public ServerController(UserManager<ApplicationUser> userManager, public ServerController(UserManager<ApplicationUser> userManager,
BTCPayServerOptions options, BTCPayServerOptions options,
@@ -55,7 +55,7 @@ namespace BTCPayServer.Controllers
LightningConfigurationProvider lnConfigProvider, LightningConfigurationProvider lnConfigProvider,
TorServices torServices, TorServices torServices,
StoreRepository storeRepository, StoreRepository storeRepository,
AppService appService) ApplicationDbContextFactory contextFactory)
{ {
_Options = options; _Options = options;
_UserManager = userManager; _UserManager = userManager;
@@ -66,7 +66,7 @@ namespace BTCPayServer.Controllers
_StoreRepository = storeRepository; _StoreRepository = storeRepository;
_LnConfigProvider = lnConfigProvider; _LnConfigProvider = lnConfigProvider;
_torServices = torServices; _torServices = torServices;
_AppService = appService; _ContextFactory = contextFactory;
} }
[Route("server/rates")] [Route("server/rates")]
@@ -448,13 +448,17 @@ namespace BTCPayServer.Controllers
{ {
var data = (await _SettingsRepository.GetSettingAsync<PoliciesSettings>()) ?? new PoliciesSettings(); var data = (await _SettingsRepository.GetSettingAsync<PoliciesSettings>()) ?? new PoliciesSettings();
var userId = _UserManager.GetUserId(base.User); // load display app dropdown
var selectList = (await _AppService.GetAllApps(userId)) using (var ctx = _ContextFactory.CreateContext())
.Select(a => {
new SelectListItem($"{a.AppType} - {a.AppName}", a.Id) var selectList = ctx.Apps.Select(a =>
new SelectListItem($"{a.AppType} - {a.Name}", a.Id)
).ToList(); ).ToList();
selectList.Insert(0, new SelectListItem("(None)", null)); selectList.Insert(0, new SelectListItem("(None)", null));
ViewBag.AppsList = new SelectList(selectList, "Value", "Text", data.RootAppId);
ViewBag.AppsList = new SelectList(selectList, "Value", "Text", data.RootAppId);
}
return View(data); return View(data);
} }
[Route("server/policies")] [Route("server/policies")]
@@ -463,15 +467,11 @@ namespace BTCPayServer.Controllers
{ {
if (!String.IsNullOrEmpty(settings.RootAppId)) if (!String.IsNullOrEmpty(settings.RootAppId))
{ {
var userId = _UserManager.GetUserId(base.User); using (var ctx = _ContextFactory.CreateContext())
var appData = await _AppService.GetApp(settings.RootAppId, null);
if (appData != null)
{ {
settings.RootAppType = Enum.Parse<AppType>(appData.AppType); var app = ctx.Apps.SingleOrDefault(a => a.Id == settings.RootAppId);
} if (app != null)
else settings.RootAppType = Enum.Parse<AppType>(app.AppType);
{
settings.RootAppType = null;
} }
} }
else else

View File

@@ -208,12 +208,12 @@ namespace BTCPayServer.Services.Apps
} }
} }
public async Task<ListAppsViewModel.ListAppViewModel[]> GetAllApps(string userId) public async Task<ListAppsViewModel.ListAppViewModel[]> GetAllApps(string userId, bool allowNoUser = false)
{ {
using (var ctx = _ContextFactory.CreateContext()) using (var ctx = _ContextFactory.CreateContext())
{ {
return await ctx.UserStore 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, .Join(ctx.Apps, us => us.StoreDataId, app => app.StoreDataId,
(us, app) => (us, app) =>
new ListAppsViewModel.ListAppViewModel() new ListAppsViewModel.ListAppViewModel()
@@ -230,15 +230,13 @@ namespace BTCPayServer.Services.Apps
} }
public async Task<AppData> GetApp(string appId, AppType? appType, bool includeStore = false) public async Task<AppData> GetApp(string appId, AppType appType, bool includeStore = false)
{ {
using (var ctx = _ContextFactory.CreateContext()) using (var ctx = _ContextFactory.CreateContext())
{ {
var query = ctx.Apps var query = ctx.Apps
.Where(us => us.Id == appId); .Where(us => us.Id == appId &&
us.AppType == appType.ToString());
if (appType is AppType appTypeValue)
query = query.Where(us => us.AppType == appTypeValue.ToString());
if (includeStore) if (includeStore)
{ {