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;
private readonly TorServices _torServices;
BTCPayServerOptions _Options;
AppService _AppService;
ApplicationDbContextFactory _ContextFactory;
public ServerController(UserManager<ApplicationUser> 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<PoliciesSettings>()) ?? 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<AppType>(appData.AppType);
}
else
{
settings.RootAppType = null;
var app = ctx.Apps.SingleOrDefault(a => a.Id == settings.RootAppId);
if (app != null)
settings.RootAppType = Enum.Parse<AppType>(app.AppType);
}
}
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())
{
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<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())
{
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)
{