|
|
|
@ -1,7 +1,9 @@ |
|
|
|
using System.Security.Principal; |
|
|
|
using System; |
|
|
|
using System.Security.Principal; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Features; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
using Volo.Abp.Security.Claims; |
|
|
|
|
|
|
|
namespace Volo.Abp.FeatureManagement; |
|
|
|
@ -11,22 +13,58 @@ public class EditionFeatureManagementProvider : FeatureManagementProvider, ITran |
|
|
|
public override string Name => EditionFeatureValueProvider.ProviderName; |
|
|
|
|
|
|
|
protected ICurrentPrincipalAccessor PrincipalAccessor { get; } |
|
|
|
protected ITenantStore TenantStore { get; } |
|
|
|
protected ICurrentTenant CurrentTenant { get; } |
|
|
|
protected string CurrentCompatibleProviderName { get; set; } |
|
|
|
|
|
|
|
public EditionFeatureManagementProvider( |
|
|
|
IFeatureManagementStore store, |
|
|
|
ICurrentPrincipalAccessor principalAccessor) |
|
|
|
ICurrentPrincipalAccessor principalAccessor, |
|
|
|
ITenantStore tenantStore, |
|
|
|
ICurrentTenant currentTenant) |
|
|
|
: base(store) |
|
|
|
{ |
|
|
|
PrincipalAccessor = principalAccessor; |
|
|
|
TenantStore = tenantStore; |
|
|
|
CurrentTenant = currentTenant; |
|
|
|
} |
|
|
|
|
|
|
|
protected override Task<string> NormalizeProviderKeyAsync(string providerKey) |
|
|
|
public override bool Compatible(string providerName) |
|
|
|
{ |
|
|
|
if (providerKey != null) |
|
|
|
CurrentCompatibleProviderName = providerName; |
|
|
|
return providerName == TenantFeatureValueProvider.ProviderName || base.Compatible(providerName); |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task<string> NormalizeProviderKeyAsync(string providerKey) |
|
|
|
{ |
|
|
|
return (await FindEditionIdAsync(providerKey))?.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<Guid?> FindEditionIdAsync(string providerKey) |
|
|
|
{ |
|
|
|
if (Guid.TryParse(providerKey, out var parsedEditionOrTenantId)) |
|
|
|
{ |
|
|
|
if (CurrentCompatibleProviderName == TenantFeatureValueProvider.ProviderName) |
|
|
|
{ |
|
|
|
var tenant = await TenantStore.FindAsync(parsedEditionOrTenantId); |
|
|
|
if (tenant != null) |
|
|
|
{ |
|
|
|
return tenant?.EditionId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return parsedEditionOrTenantId; |
|
|
|
} |
|
|
|
|
|
|
|
if (CurrentTenant.Id.HasValue) |
|
|
|
{ |
|
|
|
return Task.FromResult(providerKey); |
|
|
|
var tenant = await TenantStore.FindAsync(CurrentTenant.GetId()); |
|
|
|
if (tenant != null) |
|
|
|
{ |
|
|
|
return tenant?.EditionId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return Task.FromResult(PrincipalAccessor.Principal?.FindEditionId()?.ToString("N")); |
|
|
|
return PrincipalAccessor.Principal?.FindEditionId(); |
|
|
|
} |
|
|
|
} |
|
|
|
|