Filter the apps by the user id

This commit is contained in:
nicolas.dorier 2019-04-12 14:54:59 +09:00
parent c55f1185e6
commit ae7ad9f667
2 changed files with 9 additions and 5 deletions

View file

@ -27,7 +27,7 @@ namespace BTCPayServer.Controllers
public async Task<IActionResult> Index()
{
if (_cachedServerSettings.RootAppType == Services.Apps.AppType.Crowdfund)
if (_cachedServerSettings.RootAppType is Services.Apps.AppType.Crowdfund)
{
var serviceProvider = HttpContext.RequestServices;
var controller = (AppsPublicController)serviceProvider.GetService(typeof(AppsPublicController));

View file

@ -451,11 +451,13 @@ namespace BTCPayServer.Controllers
// load display app dropdown
using (var ctx = _ContextFactory.CreateContext())
{
var selectList = ctx.Apps.Select(a =>
new SelectListItem($"{a.AppType} - {a.Name}", a.Id)
).ToList();
var userId = _UserManager.GetUserId(base.User);
var selectList = ctx.Users.Where(user => user.Id == userId)
.SelectMany(s => s.UserStores)
.Select(s => s.StoreData)
.SelectMany(s => s.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);
}
@ -472,6 +474,8 @@ namespace BTCPayServer.Controllers
var app = ctx.Apps.SingleOrDefault(a => a.Id == settings.RootAppId);
if (app != null)
settings.RootAppType = Enum.Parse<AppType>(app.AppType);
else
settings.RootAppType = null;
}
}
else