Browse Source

Add RequireGlobalFeatures/FeaturesPermissionStateProvider.

pull/8543/head
maliming 6 years ago
parent
commit
352e65d7f8
  1. 1
      framework/src/Volo.Abp.Features/Volo.Abp.Features.csproj
  2. 4
      framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs
  3. 14
      framework/src/Volo.Abp.Features/Volo/Abp/Features/PermissionDefinitionExtensions.cs
  4. 25
      framework/src/Volo.Abp.Features/Volo/Abp/Features/RequireFeaturesPermissionStateProvider.cs
  5. 1
      framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj
  6. 4
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeaturesModule.cs
  7. 14
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureDefinitionExtensions.cs
  8. 24
      framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequireGlobalFeaturesPermissionStateProvider.cs

1
framework/src/Volo.Abp.Features/Volo.Abp.Features.csproj

@ -23,6 +23,7 @@
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" />
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" />
<ProjectReference Include="..\Volo.Abp.Validation\Volo.Abp.Validation.csproj" />
<ProjectReference Include="..\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" />
</ItemGroup>
</Project>

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

@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using Volo.Abp.Authorization;
using Volo.Abp.Features.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Localization.ExceptionHandling;
@ -14,7 +15,8 @@ namespace Volo.Abp.Features
[DependsOn(
typeof(AbpLocalizationModule),
typeof(AbpMultiTenancyModule),
typeof(AbpValidationModule)
typeof(AbpValidationModule),
typeof(AbpAuthorizationModule)
)]
public class AbpFeaturesModule : AbpModule
{

14
framework/src/Volo.Abp.Features/Volo/Abp/Features/PermissionDefinitionExtensions.cs

@ -0,0 +1,14 @@
using Volo.Abp.Authorization.Permissions;
namespace Volo.Abp.Features
{
public static class FeatureDefinitionExtensions
{
public static void RequireFeatures(this PermissionDefinition permissionDefinition, params string[] features)
{
Check.NotNullOrEmpty(features, nameof(features));
permissionDefinition.AddStateProvider(new RequireFeaturesPermissionStateProvider(features));
}
}
}

25
framework/src/Volo.Abp.Features/Volo/Abp/Features/RequireFeaturesPermissionStateProvider.cs

@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Authorization.Permissions;
namespace Volo.Abp.Features
{
public class RequireFeaturesPermissionStateProvider : IPermissionStateProvider
{
private readonly List<string> _requireFeatures = new List<string>();
public RequireFeaturesPermissionStateProvider(params string[] requireFeatures)
{
Check.NotNullOrEmpty(requireFeatures, nameof(requireFeatures));
_requireFeatures.AddRange(requireFeatures);
}
public async Task<bool> IsEnabledAsync(PermissionStateContext context)
{
var feature = context.ServiceProvider.GetRequiredService<IFeatureChecker>();
return await feature.IsEnabledAsync(true, _requireFeatures.ToArray());
}
}
}

1
framework/src/Volo.Abp.GlobalFeatures/Volo.Abp.GlobalFeatures.csproj

@ -23,6 +23,7 @@
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" />
<ProjectReference Include="..\Volo.Abp.VirtualFileSystem\Volo.Abp.VirtualFileSystem.csproj" />
<ProjectReference Include="..\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" />
</ItemGroup>
</Project>

4
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/AbpGlobalFeaturesModule.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Authorization;
using Volo.Abp.GlobalFeatures.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Localization.ExceptionHandling;
@ -9,7 +10,8 @@ namespace Volo.Abp.GlobalFeatures
{
[DependsOn(
typeof(AbpLocalizationModule),
typeof(AbpVirtualFileSystemModule)
typeof(AbpVirtualFileSystemModule),
typeof(AbpAuthorizationModule)
)]
public class AbpGlobalFeaturesModule : AbpModule
{

14
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureDefinitionExtensions.cs

@ -0,0 +1,14 @@
using Volo.Abp.Authorization.Permissions;
namespace Volo.Abp.GlobalFeatures
{
public static class GlobalFeatureDefinitionExtensions
{
public static void RequireGlobalFeatures(this PermissionDefinition permissionDefinition, params string[] globalFeatures)
{
Check.NotNullOrEmpty(globalFeatures, nameof(globalFeatures));
permissionDefinition.AddStateProvider(new RequireGlobalFeaturesPermissionStateProvider(globalFeatures));
}
}
}

24
framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/RequireGlobalFeaturesPermissionStateProvider.cs

@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
namespace Volo.Abp.GlobalFeatures
{
public class RequireGlobalFeaturesPermissionStateProvider : IPermissionStateProvider
{
private readonly List<string> _requireGlobalFeatures = new List<string>();
public RequireGlobalFeaturesPermissionStateProvider(params string[] requireGlobalFeatures)
{
Check.NotNullOrEmpty(requireGlobalFeatures, nameof(requireGlobalFeatures));
_requireGlobalFeatures.AddRange(requireGlobalFeatures);
}
public Task<bool> IsEnabledAsync(PermissionStateContext context)
{
return Task.FromResult(_requireGlobalFeatures.All(x => GlobalFeatureManager.Instance.IsEnabled(x)));
}
}
}
Loading…
Cancel
Save