Browse Source

Add IsAvailableToHost & HostFeatureValueProvider & HostFeatureManagementProvider.

pull/5259/head
maliming 6 years ago
parent
commit
70bfb0fafb
  1. 1
      framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs
  2. 30
      framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinition.cs
  3. 30
      framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs
  4. 3
      modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs
  5. 59
      modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs

1
framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs

@ -26,6 +26,7 @@ namespace Volo.Abp.Features
context.Services.Configure<AbpFeatureOptions>(options => context.Services.Configure<AbpFeatureOptions>(options =>
{ {
options.ValueProviders.Add<DefaultValueFeatureValueProvider>(); options.ValueProviders.Add<DefaultValueFeatureValueProvider>();
options.ValueProviders.Add<HostFeatureValueProvider>();
options.ValueProviders.Add<EditionFeatureValueProvider>(); options.ValueProviders.Add<EditionFeatureValueProvider>();
options.ValueProviders.Add<TenantFeatureValueProvider>(); options.ValueProviders.Add<TenantFeatureValueProvider>();
}); });

30
framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinition.cs

@ -51,6 +51,12 @@ namespace Volo.Abp.Features
/// </summary> /// </summary>
public bool IsVisibleToClients { get; set; } public bool IsVisibleToClients { get; set; }
/// <summary>
/// Can host use this feature.
/// Default: true.
/// </summary>
public bool IsAvailableToHost { get; set; }
/// <summary> /// <summary>
/// A list of allowed providers to get/set value of this feature. /// A list of allowed providers to get/set value of this feature.
/// An empty list indicates that all providers are allowed. /// An empty list indicates that all providers are allowed.
@ -93,7 +99,8 @@ namespace Volo.Abp.Features
ILocalizableString displayName = null, ILocalizableString displayName = null,
ILocalizableString description = null, ILocalizableString description = null,
IStringValueType valueType = null, IStringValueType valueType = null,
bool isVisibleToClients = true) bool isVisibleToClients = true,
bool isAvailableToHost = true)
{ {
Name = name; Name = name;
DefaultValue = defaultValue; DefaultValue = defaultValue;
@ -101,6 +108,7 @@ namespace Volo.Abp.Features
Description = description; Description = description;
ValueType = valueType; ValueType = valueType;
IsVisibleToClients = isVisibleToClients; IsVisibleToClients = isVisibleToClients;
IsAvailableToHost = isAvailableToHost;
Properties = new Dictionary<string, object>(); Properties = new Dictionary<string, object>();
AllowedProviders = new List<string>(); AllowedProviders = new List<string>();
@ -136,20 +144,22 @@ namespace Volo.Abp.Features
/// </summary> /// </summary>
/// <returns>Returns a newly created child feature</returns> /// <returns>Returns a newly created child feature</returns>
public FeatureDefinition CreateChild( public FeatureDefinition CreateChild(
string name, string name,
string defaultValue = null, string defaultValue = null,
ILocalizableString displayName = null, ILocalizableString displayName = null,
ILocalizableString description = null, ILocalizableString description = null,
IStringValueType valueType = null, IStringValueType valueType = null,
bool isVisibleToClients = true) bool isVisibleToClients = true,
bool isAvailableToHost = true)
{ {
var feature = new FeatureDefinition( var feature = new FeatureDefinition(
name, name,
defaultValue, defaultValue,
displayName, displayName,
description, description,
valueType, valueType,
isVisibleToClients) isVisibleToClients,
isAvailableToHost)
{ {
Parent = this Parent = this
}; };
@ -175,4 +185,4 @@ namespace Volo.Abp.Features
return $"[{nameof(FeatureDefinition)}: {Name}]"; return $"[{nameof(FeatureDefinition)}: {Name}]";
} }
} }
} }

30
framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs

@ -0,0 +1,30 @@
using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Features
{
public class HostFeatureValueProvider : FeatureValueProvider
{
public const string ProviderName = "H";
public override string Name => ProviderName;
protected ICurrentTenant CurrentTenant { get; }
public HostFeatureValueProvider(IFeatureStore featureStore, ICurrentTenant currentTenant)
: base(featureStore)
{
CurrentTenant = currentTenant;
}
public override async Task<string> GetOrNullAsync(FeatureDefinition feature)
{
if (CurrentTenant.Id.HasValue || !feature.IsAvailableToHost)
{
return null;
}
return await FeatureStore.GetOrNullAsync(feature.Name, Name, null);
}
}
}

3
modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs

@ -1,10 +1,8 @@
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.FeatureManagement.Localization; using Volo.Abp.FeatureManagement.Localization;
using Volo.Abp.Features; using Volo.Abp.Features;
using Volo.Abp.Localization;
using Volo.Abp.Localization.ExceptionHandling; using Volo.Abp.Localization.ExceptionHandling;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.FeatureManagement namespace Volo.Abp.FeatureManagement
{ {
@ -20,6 +18,7 @@ namespace Volo.Abp.FeatureManagement
Configure<FeatureManagementOptions>(options => Configure<FeatureManagementOptions>(options =>
{ {
options.Providers.Add<DefaultValueFeatureManagementProvider>(); options.Providers.Add<DefaultValueFeatureManagementProvider>();
options.Providers.Add<HostFeatureManagementProvider>();
options.Providers.Add<EditionFeatureManagementProvider>(); options.Providers.Add<EditionFeatureManagementProvider>();
//TODO: Should be moved to the Tenant Management module //TODO: Should be moved to the Tenant Management module

59
modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs

@ -0,0 +1,59 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.FeatureManagement
{
public class HostFeatureManagementProvider : FeatureManagementProvider, ITransientDependency
{
public override string Name => HostFeatureValueProvider.ProviderName;
protected ICurrentTenant CurrentTenant { get; }
public HostFeatureManagementProvider(
IFeatureManagementStore store,
ICurrentTenant currentTenant)
: base(store)
{
CurrentTenant = currentTenant;
}
public override async Task<string> GetOrNullAsync(FeatureDefinition feature, string providerKey)
{
if (IsHostSide(feature))
{
return await Store.GetOrNullAsync(feature.Name, Name, NormalizeProviderKey(providerKey));
}
return null;
}
public override async Task SetAsync(FeatureDefinition feature, string value, string providerKey)
{
if (IsHostSide(feature))
{
await Store.SetAsync(feature.Name, value, Name, NormalizeProviderKey(providerKey));
}
}
public override async Task ClearAsync(FeatureDefinition feature, string providerKey)
{
if (IsHostSide(feature))
{
await Store.DeleteAsync(feature.Name, Name, NormalizeProviderKey(providerKey));
}
}
protected override string NormalizeProviderKey(string providerKey)
{
return null;
}
//TODO: Should throw an ex when there is not in the host side?
protected virtual bool IsHostSide(FeatureDefinition feature)
{
return feature.IsAvailableToHost && CurrentTenant.Id == null;
}
}
}
Loading…
Cancel
Save