mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Move GetAppDataIfOwner inside AppHelper
This commit is contained in:
@@ -138,19 +138,7 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
private async Task<AppData> GetOwnedApp(string appId, AppType? type = null)
|
private async Task<AppData> GetOwnedApp(string appId, AppType? type = null)
|
||||||
{
|
{
|
||||||
var userId = GetUserId();
|
return _AppsHelper.GetAppDataIfOwner(GetUserId(), appId, type);
|
||||||
using (var ctx = _ContextFactory.CreateContext())
|
|
||||||
{
|
|
||||||
var app = await ctx.UserStore
|
|
||||||
.Where(us => us.ApplicationUserId == userId && us.Role == StoreRoles.Owner)
|
|
||||||
.SelectMany(us => us.StoreData.Apps.Where(a => a.Id == appId))
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
if (app == null)
|
|
||||||
return null;
|
|
||||||
if (type != null && type.Value.ToString() != app.AppType)
|
|
||||||
return null;
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<StoreData[]> GetOwnedStores()
|
private async Task<StoreData[]> GetOwnedStores()
|
||||||
|
|||||||
@@ -181,5 +181,22 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
return _Currencies.GetCurrencyData(currency, useFallback);
|
return _Currencies.GetCurrencyData(currency, useFallback);
|
||||||
}
|
}
|
||||||
|
public async Task<AppData> GetAppDataIfOwner(string userId, string appId, AppType? type = null)
|
||||||
|
{
|
||||||
|
if (userId == null || appId == null)
|
||||||
|
return null;
|
||||||
|
using (var ctx = _ContextFactory.CreateContext())
|
||||||
|
{
|
||||||
|
var app = await ctx.UserStore
|
||||||
|
.Where(us => us.ApplicationUserId == userId && us.Role == StoreRoles.Owner)
|
||||||
|
.SelectMany(us => us.StoreData.Apps.Where(a => a.Id == appId))
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
if (app == null)
|
||||||
|
return null;
|
||||||
|
if (type != null && type.Value.ToString() != app.AppType)
|
||||||
|
return null;
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user