diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs index 7b80ecf217..cc26eb8a67 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs @@ -7,7 +7,7 @@ namespace Volo.Abp.Permissions { string Name { get; } - Task IsGrantedAsync([NotNull] PermissionDefinition permission, [CanBeNull] string providerKey); + Task IsGrantedAsync([NotNull] PermissionDefinition permission, [CanBeNull] string providerName, [CanBeNull] string providerKey); Task SetAsync([NotNull] PermissionDefinition permission, bool isGranted, [CanBeNull] string providerKey); diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionManager.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionManager.cs index 4a03836d67..0363250571 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionManager.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionManager.cs @@ -50,7 +50,7 @@ namespace Volo.Abp.Permissions Check.NotNull(name, nameof(name)); Check.NotNull(providerName, nameof(providerName)); - return IsGrantedInternalAsync(name, providerName, providerKey, fallback); + return IsGrantedInternalAsync(name, providerName, providerKey); } public virtual async Task IsGrantedInternalAsync(string name, string providerName, string providerKey, bool fallback = true) @@ -71,7 +71,7 @@ namespace Volo.Abp.Permissions foreach (var provider in providers) { - var value = await provider.IsGrantedAsync(permission, providerKey); + var value = await provider.IsGrantedAsync(permission, providerName, providerKey); if (value != null) { return value.Value; @@ -150,7 +150,9 @@ namespace Volo.Abp.Permissions } } - protected virtual async Task> GetAllFromProvidersAsync([NotNull] List providers, [CanBeNull] string providerKey) + protected virtual async Task> GetAllFromProvidersAsync( + [NotNull] List providers, + [CanBeNull] string providerKey) { var permissionDefinitions = PermissionDefinitionManager.GetAll(); var permissionGrantInfos = new Dictionary(); @@ -161,7 +163,7 @@ namespace Volo.Abp.Permissions foreach (var provider in providers) { - var value = await provider.IsGrantedAsync(permission, providerKey); + var value = await provider.IsGrantedAsync(permission, provider.Name, providerKey); if (value != null) { permissionGrantInfos[permission.Name] = diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs index 6313d57303..559e000655 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.Permissions PermissionStore = permissionStore; } - public abstract Task IsGrantedAsync(PermissionDefinition permission, string providerKey); + public abstract Task IsGrantedAsync(PermissionDefinition permission, string providerName, string providerKey); public abstract Task SetAsync(PermissionDefinition permission, bool isGranted, string providerKey); diff --git a/src/Volo.Abp.Session/Volo/Abp/Session/RolePermissionValueProvider.cs b/src/Volo.Abp.Session/Volo/Abp/Session/RolePermissionValueProvider.cs new file mode 100644 index 0000000000..ca3a8fd70a --- /dev/null +++ b/src/Volo.Abp.Session/Volo/Abp/Session/RolePermissionValueProvider.cs @@ -0,0 +1,47 @@ +using System.Threading.Tasks; +using Volo.Abp.Permissions; + +namespace Volo.Abp.Session +{ + //TODO: This should be located under Identity, or we should create a Volo.Abp.Roles package (with role store implementation)...! + + //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 IsGrantedAsync(PermissionDefinition permission, string providerKey) + // { + // if (providerKey == null) + // { + // if (CurrentUser.Id == null) + // { + // return null; + // } + + // providerKey = CurrentUser.Id.ToString(); + // } + + // return await PermissionStore.IsGrantedAsync(permission.Name, Name, providerKey); + // } + + // public override Task SetAsync(PermissionDefinition permission, bool isGranted, string providerKey) + // { + // return PermissionStore.SetAsync(permission.Name, isGranted, Name, providerKey); + // } + + // public override Task ClearAsync(PermissionDefinition permission, string providerKey) + // { + // return PermissionStore.DeleteAsync(permission.Name, Name, providerKey); + // } + //} +} diff --git a/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs b/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs index 25c8fa8bf0..03740781a7 100644 --- a/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs +++ b/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs @@ -17,7 +17,7 @@ namespace Volo.Abp.Session CurrentUser = currentUser; } - public override async Task IsGrantedAsync(PermissionDefinition permission, string providerKey) + public override async Task IsGrantedAsync(PermissionDefinition permission, string providerName, string providerKey) { if (providerKey == null) {