mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-02-23 15:14:49 +01:00
Store Custom Roles (#4940)
This commit is contained in:
@@ -1,11 +1,40 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Data;
|
||||
|
||||
namespace BTCPayServer
|
||||
{
|
||||
public static class StoreExtensions
|
||||
{
|
||||
public static StoreRole? GetStoreRoleOfUser(this StoreData store, string userId)
|
||||
{
|
||||
return store.UserStores.FirstOrDefault(r => r.ApplicationUserId == userId)?.StoreRole;
|
||||
}
|
||||
|
||||
public static PermissionSet GetPermissionSet(this StoreRole storeRole, string storeId)
|
||||
{
|
||||
return new PermissionSet(storeRole.Permissions
|
||||
.Select(s => Permission.TryCreatePermission(s, storeId, out var permission) ? permission : null)
|
||||
.Where(s => s != null).ToArray());
|
||||
}
|
||||
|
||||
|
||||
public static PermissionSet GetPermissionSet(this StoreData store, string userId)
|
||||
{
|
||||
return store.GetStoreRoleOfUser(userId)?.GetPermissionSet(store.Id)?? new PermissionSet();
|
||||
}
|
||||
|
||||
public static bool HasPermission(this StoreData store, string userId, string permission)
|
||||
{
|
||||
return GetPermissionSet(store, userId).HasPermission(permission, store.Id);
|
||||
}
|
||||
|
||||
public static bool HasPermission(this PermissionSet permissionSet, string permission, string storeId)
|
||||
{
|
||||
return permissionSet.Contains(permission, storeId);
|
||||
}
|
||||
|
||||
public static DerivationSchemeSettings? GetDerivationSchemeSettings(this StoreData store, BTCPayNetworkProvider networkProvider, string cryptoCode)
|
||||
{
|
||||
var paymentMethod = store
|
||||
|
||||
Reference in New Issue
Block a user