mirror of https://github.com/abpframework/abp.git
7 changed files with 122 additions and 21 deletions
@ -1,9 +1,11 @@ |
|||||
namespace Volo.Abp.Permissions |
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Permissions |
||||
{ |
{ |
||||
public interface IPermissionDefinitionContext |
public interface IPermissionDefinitionContext |
||||
{ |
{ |
||||
PermissionDefinition GetOrNull(string name); |
PermissionDefinition GetOrNull([NotNull] string name); |
||||
|
|
||||
void Add(params PermissionDefinition[] definitions); |
PermissionDefinition Add([NotNull] string name); |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Permissions; |
||||
|
|
||||
|
namespace Volo.Abp.Session |
||||
|
{ |
||||
|
public class RolePermissionValueProvider : PermissionValueProvider |
||||
|
{ |
||||
|
public const string ProviderName = "Role"; |
||||
|
|
||||
|
public override string Name => ProviderName; |
||||
|
|
||||
|
protected ICurrentUser CurrentUser { get; } |
||||
|
|
||||
|
public RolePermissionValueProvider(IPermissionStore permissionStore, ICurrentUser currentUser) |
||||
|
: base(permissionStore) |
||||
|
{ |
||||
|
CurrentUser = currentUser; |
||||
|
} |
||||
|
|
||||
|
public override async Task<bool> IsGrantedAsync(PermissionDefinition permission) |
||||
|
{ |
||||
|
if (CurrentUser.Id == null || !CurrentUser.Roles.Any()) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
foreach (var role in CurrentUser.Roles) |
||||
|
{ |
||||
|
if (await PermissionStore.IsGrantedAsync(permission.Name, Name, role)) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue