|
|
|
@ -22,7 +22,7 @@ namespace Volo.Abp.Permissions
|
|
|
|
|
protected PermissionManagementOptions Options { get; }
|
|
|
|
|
|
|
|
|
|
private readonly Lazy<List<IPermissionManagementProvider>> _lazyProviders;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PermissionManager(
|
|
|
|
|
IPermissionDefinitionManager permissionDefinitionManager,
|
|
|
|
|
IPermissionGrantRepository permissionGrantRepository,
|
|
|
|
@ -44,66 +44,6 @@ namespace Volo.Abp.Permissions
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public async Task<bool> IsGrantedAsync(string providerName, string providerKey, string name)
|
|
|
|
|
//{
|
|
|
|
|
// Check.NotNull(providerName, nameof(providerName));
|
|
|
|
|
// Check.NotNull(providerKey, nameof(providerKey));
|
|
|
|
|
// Check.NotNull(name, nameof(name));
|
|
|
|
|
|
|
|
|
|
// return await PermissionGrantRepository.FindAsync(name, providerName, providerKey) != null;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public async Task<List<string>> GetAllGrantedAsync(string providerName, string providerKey)
|
|
|
|
|
//{
|
|
|
|
|
// Check.NotNull(providerName, nameof(providerName));
|
|
|
|
|
// Check.NotNull(providerKey, nameof(providerKey));
|
|
|
|
|
|
|
|
|
|
// return (await PermissionGrantRepository.GetListAsync(providerName, providerKey))
|
|
|
|
|
// .Select(p => p.Name)
|
|
|
|
|
// .ToList();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public async Task GrantAsync(string name, string providerName, string providerKey)
|
|
|
|
|
//{
|
|
|
|
|
// Check.NotNull(name, nameof(name));
|
|
|
|
|
// Check.NotNull(providerName, nameof(providerName));
|
|
|
|
|
// Check.NotNull(providerKey, nameof(providerKey));
|
|
|
|
|
|
|
|
|
|
// if (await IsGrantedAsync(providerName, providerKey, name))
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// await PermissionGrantRepository.InsertAsync(
|
|
|
|
|
// new PermissionGrant(
|
|
|
|
|
// GuidGenerator.Create(),
|
|
|
|
|
// name,
|
|
|
|
|
// providerName,
|
|
|
|
|
// providerKey
|
|
|
|
|
// )
|
|
|
|
|
// );
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public async Task RevokeAsync(string providerName, string providerKey, string name)
|
|
|
|
|
//{
|
|
|
|
|
// Check.NotNull(providerName, nameof(providerName));
|
|
|
|
|
// Check.NotNull(providerKey, nameof(providerKey));
|
|
|
|
|
// Check.NotNull(name, nameof(name));
|
|
|
|
|
|
|
|
|
|
// if (await IsGrantedAsync(providerName, providerKey, name))
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// var grant = await PermissionGrantRepository.FindAsync(name, providerName, providerKey);
|
|
|
|
|
// if (grant == null)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// await PermissionGrantRepository.DeleteAsync(grant);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
public async Task<PermissionWithGrantedProviders> GetAsync(string name, string providerName, string providerKey)
|
|
|
|
|
{
|
|
|
|
|
return await GetInternalAsync(PermissionDefinitionManager.Get(name), providerName, providerKey);
|
|
|
|
@ -121,6 +61,31 @@ namespace Volo.Abp.Permissions
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SetAsync(string name, string providerName, string providerKey, bool isGranted)
|
|
|
|
|
{
|
|
|
|
|
var currentGrantInfo = await GetAsync(name, providerName, providerKey);
|
|
|
|
|
if (currentGrantInfo.IsGranted == isGranted)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentGrantInfo.IsGranted == false)
|
|
|
|
|
{
|
|
|
|
|
var provider = ManagementProviders.FirstOrDefault(m => m.Name == providerName);
|
|
|
|
|
await provider.GrantAsync(name, providerKey);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (currentGrantInfo.Providers.All(p => p.Name != providerName))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var provider = ManagementProviders.FirstOrDefault(m => m.Name == providerName);
|
|
|
|
|
await provider.RevokeAsync(name, providerKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PermissionWithGrantedProviders> GetInternalAsync(PermissionDefinition permissionDefinition, string providerName, string providerKey)
|
|
|
|
|
{
|
|
|
|
|
var result = new PermissionWithGrantedProviders(permissionDefinition.Name, false);
|
|
|
|
|