using System.Threading.Tasks;
namespace Abp.Authorization
{
///
/// Most simple implementation of .
/// It checks one or more permissions if they are granted.
///
public class SimplePermissionDependency : IPermissionDependency
{
///
/// A list of permissions to be checked if they are granted.
///
public string[] Permissions { get; set; }
///
/// If this property is set to true, all of the must be granted.
/// If it's false, at least one of the must be granted.
/// Default: false.
///
public bool RequiresAll { get; set; }
///
/// Initializes a new instance of the class.
///
/// The permissions.
public SimplePermissionDependency(params string[] permissions)
{
Permissions = permissions;
}
///
/// Initializes a new instance of the class.
///
///
/// If this is set to true, all of the must be granted.
/// If it's false, at least one of the must be granted.
///
/// The permissions.
public SimplePermissionDependency(bool requiresAll, params string[] permissions)
: this(permissions)
{
RequiresAll = requiresAll;
}
///
public Task IsSatisfiedAsync(IPermissionDependencyContext context)
{
return context.User != null
? context.PermissionChecker.IsGrantedAsync(context.User, RequiresAll, Permissions)
: context.PermissionChecker.IsGrantedAsync(RequiresAll, Permissions);
}
}
}