mirror of https://github.com/abpframework/abp.git
12 changed files with 141 additions and 68 deletions
@ -0,0 +1,32 @@ |
|||
using System.Security.Principal; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class EditionFeatureManagementProvider : FeatureManagementProvider, ITransientDependency |
|||
{ |
|||
public override string Name => EditionFeatureValueProvider.ProviderName; |
|||
|
|||
protected ICurrentPrincipalAccessor PrincipalAccessor { get; } |
|||
|
|||
public EditionFeatureManagementProvider( |
|||
IFeatureManagementStore store, |
|||
ICurrentPrincipalAccessor principalAccessor) |
|||
: base(store) |
|||
{ |
|||
PrincipalAccessor = principalAccessor; |
|||
} |
|||
|
|||
protected override string NormalizeProviderKey(string providerKey) |
|||
{ |
|||
if (providerKey != null) |
|||
{ |
|||
return providerKey; |
|||
} |
|||
|
|||
return PrincipalAccessor.Principal?.FindEditionId()?.ToString("N"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Features; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public static class EditionFeatureManagerExtensions |
|||
{ |
|||
public static Task<string> GetOrNullForEditionAsync(this IFeatureManager featureManager, [NotNull] string name, Guid editionId, bool fallback = true) |
|||
{ |
|||
return featureManager.GetOrNullAsync(name, EditionFeatureValueProvider.ProviderName, editionId.ToString("N"), fallback); |
|||
} |
|||
|
|||
public static Task<List<FeatureNameValue>> GetAllForEditionAsync(this IFeatureManager featureManager, Guid editionId, bool fallback = true) |
|||
{ |
|||
return featureManager.GetAllAsync(EditionFeatureValueProvider.ProviderName, editionId.ToString("N"), fallback); |
|||
} |
|||
|
|||
public static Task SetForEditionAsync(this IFeatureManager featureManager, Guid editionId, [NotNull] string name, [CanBeNull] string value, bool forceToSet = false) |
|||
{ |
|||
return featureManager.SetAsync(name, value, EditionFeatureValueProvider.ProviderName, editionId.ToString("N"), forceToSet); |
|||
} |
|||
} |
|||
} |
|||
@ -1,14 +1,31 @@ |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class TenantFeatureManagementProvider : FeatureManagementProvider |
|||
public class TenantFeatureManagementProvider : FeatureManagementProvider, ITransientDependency |
|||
{ |
|||
public override string Name => TenantFeatureValueProvider.ProviderName; |
|||
|
|||
public TenantFeatureManagementProvider(IFeatureManagementStore store) |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
|
|||
public TenantFeatureManagementProvider( |
|||
IFeatureManagementStore store, |
|||
ICurrentTenant currentTenant) |
|||
: base(store) |
|||
{ |
|||
CurrentTenant = currentTenant; |
|||
} |
|||
|
|||
protected override string NormalizeProviderKey(string providerKey) |
|||
{ |
|||
if (providerKey != null) |
|||
{ |
|||
return providerKey; |
|||
} |
|||
|
|||
return CurrentTenant.Id?.ToString("N"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Features; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class FeatureManager_Tests : FeatureManagementDomainTestBase |
|||
{ |
|||
private readonly IFeatureManager _featureManager; |
|||
|
|||
public FeatureManager_Tests() |
|||
{ |
|||
_featureManager = GetRequiredService<IFeatureManager>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Get_A_FeatureValue_For_A_Provider() |
|||
{ |
|||
(await _featureManager.GetOrNullForEditionAsync( |
|||
TestFeatureDefinitionProvider.BackupCount, |
|||
TestEditionIds.Enterprise |
|||
)).ShouldBe("5"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
using Volo.Abp.Features; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class EditionFeatureManagementProvider : FeatureManagementProvider |
|||
{ |
|||
public override string Name => EditionFeatureValueProvider.ProviderName; |
|||
|
|||
public EditionFeatureManagementProvider(IFeatureManagementStore store) |
|||
: base(store) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public static class TestEditionIds |
|||
{ |
|||
public static Guid Regular { get; } |
|||
public static Guid Enterprise { get; } |
|||
public static Guid Ultimate { get; } |
|||
|
|||
static TestEditionIds() |
|||
{ |
|||
Regular = Guid.Parse("532599ab-c0c0-4345-a04a-e322867b6e15"); |
|||
Enterprise = Guid.Parse("27e50758-1feb-436a-be4f-cae8519e0cb2"); |
|||
Ultimate = Guid.Parse("6ea78c22-be32-497e-aaba-a2332c564c5e"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public static class TestEditionNames |
|||
{ |
|||
public const string Regular = "Regular"; |
|||
public const string Enterprise = "Enterprise"; |
|||
public const string Ultimate = "Ultimate"; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue