From ae7ad9f667c53757ba8c988d97c4d43b0cf06878 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 12 Apr 2019 14:54:59 +0900 Subject: [PATCH] Filter the apps by the user id --- BTCPayServer/Controllers/HomeController.cs | 2 +- BTCPayServer/Controllers/ServerController.cs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Controllers/HomeController.cs b/BTCPayServer/Controllers/HomeController.cs index c255199b4..f48b20611 100644 --- a/BTCPayServer/Controllers/HomeController.cs +++ b/BTCPayServer/Controllers/HomeController.cs @@ -27,7 +27,7 @@ namespace BTCPayServer.Controllers public async Task 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)); diff --git a/BTCPayServer/Controllers/ServerController.cs b/BTCPayServer/Controllers/ServerController.cs index f4ab44835..c3ffc13e0 100644 --- a/BTCPayServer/Controllers/ServerController.cs +++ b/BTCPayServer/Controllers/ServerController.cs @@ -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(app.AppType); + else + settings.RootAppType = null; } } else