|
|
|
@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using Volo.Abp.Authorization.Permissions; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
|
|
|
|
namespace Volo.Abp.PermissionManagement; |
|
|
|
|
|
|
|
@ -67,36 +68,39 @@ public class PermissionStore : IPermissionStore, ITransientDependency |
|
|
|
string currentName, |
|
|
|
PermissionGrantCacheItem currentCacheItem) |
|
|
|
{ |
|
|
|
var permissions = await PermissionDefinitionManager.GetPermissionsAsync(); |
|
|
|
using (PermissionGrantRepository.DisableTracking()) |
|
|
|
{ |
|
|
|
var permissions = await PermissionDefinitionManager.GetPermissionsAsync(); |
|
|
|
|
|
|
|
Logger.LogDebug($"Getting all granted permissions from the repository for this provider name,key: {providerName},{providerKey}"); |
|
|
|
Logger.LogDebug($"Getting all granted permissions from the repository for this provider name,key: {providerName},{providerKey}"); |
|
|
|
|
|
|
|
var grantedPermissionsHashSet = new HashSet<string>( |
|
|
|
(await PermissionGrantRepository.GetListAsync(providerName, providerKey)).Select(p => p.Name) |
|
|
|
); |
|
|
|
var grantedPermissionsHashSet = new HashSet<string>( |
|
|
|
(await PermissionGrantRepository.GetListAsync(providerName, providerKey)).Select(p => p.Name) |
|
|
|
); |
|
|
|
|
|
|
|
Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}"); |
|
|
|
Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}"); |
|
|
|
|
|
|
|
var cacheItems = new List<KeyValuePair<string, PermissionGrantCacheItem>>(); |
|
|
|
var cacheItems = new List<KeyValuePair<string, PermissionGrantCacheItem>>(); |
|
|
|
|
|
|
|
foreach (var permission in permissions) |
|
|
|
{ |
|
|
|
var isGranted = grantedPermissionsHashSet.Contains(permission.Name); |
|
|
|
foreach (var permission in permissions) |
|
|
|
{ |
|
|
|
var isGranted = grantedPermissionsHashSet.Contains(permission.Name); |
|
|
|
|
|
|
|
cacheItems.Add(new KeyValuePair<string, PermissionGrantCacheItem>( |
|
|
|
CalculateCacheKey(permission.Name, providerName, providerKey), |
|
|
|
new PermissionGrantCacheItem(isGranted)) |
|
|
|
); |
|
|
|
cacheItems.Add(new KeyValuePair<string, PermissionGrantCacheItem>( |
|
|
|
CalculateCacheKey(permission.Name, providerName, providerKey), |
|
|
|
new PermissionGrantCacheItem(isGranted)) |
|
|
|
); |
|
|
|
|
|
|
|
if (permission.Name == currentName) |
|
|
|
{ |
|
|
|
currentCacheItem.IsGranted = isGranted; |
|
|
|
if (permission.Name == currentName) |
|
|
|
{ |
|
|
|
currentCacheItem.IsGranted = isGranted; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
await Cache.SetManyAsync(cacheItems); |
|
|
|
await Cache.SetManyAsync(cacheItems); |
|
|
|
|
|
|
|
Logger.LogDebug($"Finished setting the cache items. Count: {permissions.Count}"); |
|
|
|
Logger.LogDebug($"Finished setting the cache items. Count: {permissions.Count}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<MultiplePermissionGrantResult> IsGrantedAsync(string[] names, string providerName, string providerKey) |
|
|
|
@ -169,34 +173,37 @@ public class PermissionStore : IPermissionStore, ITransientDependency |
|
|
|
string providerKey, |
|
|
|
List<string> notCacheKeys) |
|
|
|
{ |
|
|
|
var permissions = (await PermissionDefinitionManager.GetPermissionsAsync()) |
|
|
|
.Where(x => notCacheKeys.Any(k => GetPermissionNameFormCacheKeyOrNull(k) == x.Name)).ToList(); |
|
|
|
using (PermissionGrantRepository.DisableTracking()) |
|
|
|
{ |
|
|
|
var permissions = (await PermissionDefinitionManager.GetPermissionsAsync()) |
|
|
|
.Where(x => notCacheKeys.Any(k => GetPermissionNameFormCacheKeyOrNull(k) == x.Name)).ToList(); |
|
|
|
|
|
|
|
Logger.LogDebug($"Getting not cache granted permissions from the repository for this provider name,key: {providerName},{providerKey}"); |
|
|
|
Logger.LogDebug($"Getting not cache granted permissions from the repository for this provider name,key: {providerName},{providerKey}"); |
|
|
|
|
|
|
|
var grantedPermissionsHashSet = new HashSet<string>( |
|
|
|
(await PermissionGrantRepository.GetListAsync(notCacheKeys.Select(GetPermissionNameFormCacheKeyOrNull).ToArray(), providerName, providerKey)).Select(p => p.Name) |
|
|
|
); |
|
|
|
var grantedPermissionsHashSet = new HashSet<string>( |
|
|
|
(await PermissionGrantRepository.GetListAsync(notCacheKeys.Select(GetPermissionNameFormCacheKeyOrNull).ToArray(), providerName, providerKey)).Select(p => p.Name) |
|
|
|
); |
|
|
|
|
|
|
|
Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}"); |
|
|
|
Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}"); |
|
|
|
|
|
|
|
var cacheItems = new List<KeyValuePair<string, PermissionGrantCacheItem>>(); |
|
|
|
var cacheItems = new List<KeyValuePair<string, PermissionGrantCacheItem>>(); |
|
|
|
|
|
|
|
foreach (var permission in permissions) |
|
|
|
{ |
|
|
|
var isGranted = grantedPermissionsHashSet.Contains(permission.Name); |
|
|
|
foreach (var permission in permissions) |
|
|
|
{ |
|
|
|
var isGranted = grantedPermissionsHashSet.Contains(permission.Name); |
|
|
|
|
|
|
|
cacheItems.Add(new KeyValuePair<string, PermissionGrantCacheItem>( |
|
|
|
CalculateCacheKey(permission.Name, providerName, providerKey), |
|
|
|
new PermissionGrantCacheItem(isGranted)) |
|
|
|
); |
|
|
|
} |
|
|
|
cacheItems.Add(new KeyValuePair<string, PermissionGrantCacheItem>( |
|
|
|
CalculateCacheKey(permission.Name, providerName, providerKey), |
|
|
|
new PermissionGrantCacheItem(isGranted)) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
await Cache.SetManyAsync(cacheItems); |
|
|
|
await Cache.SetManyAsync(cacheItems); |
|
|
|
|
|
|
|
Logger.LogDebug($"Finished setting the cache items. Count: {permissions.Count}"); |
|
|
|
Logger.LogDebug($"Finished setting the cache items. Count: {permissions.Count}"); |
|
|
|
|
|
|
|
return cacheItems; |
|
|
|
return cacheItems; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) |
|
|
|
|