mirror of https://github.com/abpframework/abp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
33 lines
1.0 KiB
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Volo.Abp.Authorization.Permissions;
|
|
|
|
namespace Volo.Abp.Features
|
|
{
|
|
public class RequireFeaturesPermissionStateProvider : IPermissionStateProvider
|
|
{
|
|
private readonly string[] _featureNames;
|
|
private readonly bool _requiresAll;
|
|
|
|
public RequireFeaturesPermissionStateProvider(params string[] featureNames)
|
|
: this(true, featureNames)
|
|
{
|
|
|
|
}
|
|
|
|
public RequireFeaturesPermissionStateProvider(bool requiresAll, params string[] featureNames)
|
|
{
|
|
Check.NotNullOrEmpty(featureNames, nameof(featureNames));
|
|
|
|
_requiresAll = requiresAll;
|
|
_featureNames = featureNames;
|
|
}
|
|
|
|
public async Task<bool> IsEnabledAsync(PermissionStateContext context)
|
|
{
|
|
var feature = context.ServiceProvider.GetRequiredService<IFeatureChecker>();
|
|
return await feature.IsEnabledAsync(_requiresAll, _featureNames);
|
|
}
|
|
}
|
|
}
|