mirror of https://github.com/abpframework/abp.git
7 changed files with 114 additions and 85 deletions
@ -1,12 +1,17 @@ |
|||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace Volo.Abp.Permissions |
namespace Volo.Abp.Permissions |
||||
{ |
{ |
||||
public interface IPermissionManagementProvider : ISingletonDependency //TODO: Create an abstract base class.
|
public interface IPermissionManagementProvider : ISingletonDependency |
||||
{ |
{ |
||||
string Name { get; } |
string Name { get; } |
||||
|
|
||||
Task<PermissionValueProviderGrantInfo> CheckAsync(string name, string providerName, string providerKey); |
Task<PermissionValueProviderGrantInfo> CheckAsync([NotNull] string name, [NotNull] string providerName, [NotNull] string providerKey); |
||||
|
|
||||
|
Task GrantAsync([NotNull] string name, [NotNull] string providerKey); |
||||
|
|
||||
|
Task RevokeAsync([NotNull] string name, [NotNull] string providerKey); |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Guids; |
||||
|
|
||||
|
namespace Volo.Abp.Permissions |
||||
|
{ |
||||
|
public abstract class PermissionManagementProvider : IPermissionManagementProvider |
||||
|
{ |
||||
|
public abstract string Name { get; } |
||||
|
|
||||
|
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
||||
|
|
||||
|
protected IGuidGenerator GuidGenerator { get; } |
||||
|
|
||||
|
protected PermissionManagementProvider( |
||||
|
IPermissionGrantRepository permissionGrantRepository, |
||||
|
IGuidGenerator guidGenerator) |
||||
|
{ |
||||
|
PermissionGrantRepository = permissionGrantRepository; |
||||
|
GuidGenerator = guidGenerator; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public abstract Task<PermissionValueProviderGrantInfo> CheckAsync(string name, string providerName, string providerKey); |
||||
|
|
||||
|
public virtual async Task GrantAsync(string name, string providerKey) |
||||
|
{ |
||||
|
var grant = await PermissionGrantRepository.FindAsync(name, Name, providerKey); |
||||
|
if (grant != null) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
await PermissionGrantRepository.InsertAsync( |
||||
|
new PermissionGrant( |
||||
|
GuidGenerator.Create(), |
||||
|
name, |
||||
|
Name, |
||||
|
providerKey |
||||
|
) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task RevokeAsync(string name, string providerKey) |
||||
|
{ |
||||
|
var grant = await PermissionGrantRepository.FindAsync(name, Name, providerKey); |
||||
|
if (grant == null) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
await PermissionGrantRepository.DeleteAsync(grant); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue