2022-08-04 12:07:59 +09:00
|
|
|
#nullable enable
|
2023-07-24 09:24:32 +09:00
|
|
|
using System.Collections.Generic;
|
2021-03-11 13:34:52 +01:00
|
|
|
using System.Linq;
|
2023-05-26 16:49:32 +02:00
|
|
|
using BTCPayServer.Client;
|
2021-03-11 13:34:52 +01:00
|
|
|
using BTCPayServer.Data;
|
2024-04-04 16:31:04 +09:00
|
|
|
using BTCPayServer.Payments;
|
|
|
|
using BTCPayServer.Services.Invoices;
|
2021-03-11 13:34:52 +01:00
|
|
|
|
|
|
|
namespace BTCPayServer
|
|
|
|
{
|
|
|
|
public static class StoreExtensions
|
|
|
|
{
|
2023-05-26 16:49:32 +02:00
|
|
|
public static StoreRole? GetStoreRoleOfUser(this StoreData store, string userId)
|
|
|
|
{
|
2024-03-14 10:25:40 +01:00
|
|
|
return store.UserStores?.FirstOrDefault(r => r.ApplicationUserId == userId)?.StoreRole;
|
2023-05-26 16:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-05-01 10:22:07 +09:00
|
|
|
public static DerivationSchemeSettings? GetDerivationSchemeSettings(this StoreData store, PaymentMethodHandlerDictionary handlers, string cryptoCode, bool onlyEnabled = false)
|
2021-03-11 13:34:52 +01:00
|
|
|
{
|
2024-04-04 16:31:04 +09:00
|
|
|
var pmi = Payments.PaymentTypes.CHAIN.GetPaymentMethodId(cryptoCode);
|
2024-05-01 10:22:07 +09:00
|
|
|
return store.GetPaymentMethodConfig<DerivationSchemeSettings>(pmi, handlers, onlyEnabled);
|
2023-07-24 09:24:32 +09:00
|
|
|
}
|
2021-03-11 13:34:52 +01:00
|
|
|
}
|
|
|
|
}
|