diff --git a/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/Index.cshtml b/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/Index.cshtml index 2709633bbe..9820c0bac7 100644 --- a/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/Index.cshtml +++ b/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/Index.cshtml @@ -8,10 +8,10 @@ } @section scripts { - - - - + + + + } diff --git a/src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/AbpSettingsConsts.cs b/src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/AbpPermissionConsts.cs similarity index 100% rename from src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/AbpSettingsConsts.cs rename to src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/AbpPermissionConsts.cs diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionChecker.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionChecker.cs index 73fade810d..7b48276291 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionChecker.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionChecker.cs @@ -6,7 +6,7 @@ namespace Volo.Abp.Permissions { public interface IPermissionChecker { - Task IsGrantedAsync([NotNull]string name); + Task CheckAsync([NotNull]string name); Task> GetAllAsync(); } diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs index 8566a33534..a5ac1d3dba 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/IPermissionValueProvider.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using JetBrains.Annotations; namespace Volo.Abp.Permissions { @@ -7,10 +6,6 @@ namespace Volo.Abp.Permissions { string Name { get; } - //Task SetAsync([NotNull] PermissionDefinition permission, bool isGranted, [CanBeNull] string providerKey); - - //Task ClearAsync([NotNull] PermissionDefinition permission, [CanBeNull] string providerKey); - - Task IsGrantedAsync(PermissionDefinition permission); + Task CheckAsync(PermissionDefinition permission); } } \ No newline at end of file diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs index e696b10ba8..b0890726b7 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs @@ -34,19 +34,11 @@ namespace Volo.Abp.Permissions ); } - public virtual async Task IsGrantedAsync(string name) + public Task CheckAsync(string name) { var permission = PermissionDefinitionManager.Get(name); - foreach (var provider in Providers) - { - if (await provider.IsGrantedAsync(permission)) - { - return true; - } - } - - return false; + return GetPermissionGrantInfo(permission); } public virtual async Task> GetAllAsync() @@ -66,9 +58,10 @@ namespace Volo.Abp.Permissions { foreach (var provider in Providers) { - if (await provider.IsGrantedAsync(permission)) + var result = await provider.CheckAsync(permission); + if (result.IsGranted) { - return new PermissionGrantInfo(permission.Name, true, provider.Name); + return new PermissionGrantInfo(permission.Name, true, provider.Name, result.ProviderKey); } } diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionCheckerExtensions.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionCheckerExtensions.cs new file mode 100644 index 0000000000..86900c763e --- /dev/null +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionCheckerExtensions.cs @@ -0,0 +1,12 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Permissions +{ + public static class PermissionCheckerExtensions + { + public static async Task IsGrantedAsync(this IPermissionChecker permissionChecker, string name) + { + return (await permissionChecker.CheckAsync(name)).IsGranted; + } + } +} diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionGrantInfo.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionGrantInfo.cs index 6e7d65a90c..1d2b584ee2 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionGrantInfo.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionGrantInfo.cs @@ -10,13 +10,16 @@ namespace Volo.Abp.Permissions public string ProviderName { get; } - public PermissionGrantInfo([NotNull] string name, bool isGranted, [CanBeNull] string providerName = null) + public string ProviderKey { get; } + + public PermissionGrantInfo([NotNull] string name, bool isGranted, [CanBeNull] string providerName = null, [CanBeNull] string providerKey = null) { Check.NotNull(name, nameof(name)); Name = name; IsGranted = isGranted; ProviderName = providerName; + ProviderKey = providerKey; } } } \ No newline at end of file diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs index a3a41f2e9f..1bb6d1c616 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProvider.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; +using System.Threading.Tasks; using Volo.Abp.DependencyInjection; namespace Volo.Abp.Permissions @@ -10,24 +7,13 @@ namespace Volo.Abp.Permissions { public abstract string Name { get; } - public ILoggerFactory LoggerFactory { get; set; } - protected IPermissionStore PermissionStore { get; } - protected ILogger Logger => _lazyLogger.Value; - private Lazy _lazyLogger => new Lazy(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true); - protected PermissionValueProvider(IPermissionStore permissionStore) { PermissionStore = permissionStore; } - //public abstract Task IsGrantedAsync(PermissionDefinition permission, string providerName, string providerKey); - - //public abstract Task SetAsync(PermissionDefinition permission, bool isGranted, string providerKey); - - //public abstract Task ClearAsync(PermissionDefinition permission, string providerKey); - - public abstract Task IsGrantedAsync(PermissionDefinition permission); + public abstract Task CheckAsync(PermissionDefinition permission); } } \ No newline at end of file diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProviderGrantInfo.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProviderGrantInfo.cs new file mode 100644 index 0000000000..da83db49f8 --- /dev/null +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionValueProviderGrantInfo.cs @@ -0,0 +1,19 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.Permissions +{ + public class PermissionValueProviderGrantInfo + { + public static PermissionValueProviderGrantInfo NonGranted { get; } = new PermissionValueProviderGrantInfo(false); + + public virtual bool IsGranted { get; } + + public virtual string ProviderKey { get; } + + public PermissionValueProviderGrantInfo(bool isGranted, [CanBeNull] string providerKey = null) + { + IsGranted = isGranted; + ProviderKey = providerKey; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Session/Volo/Abp/Session/RolePermissionValueProvider.cs b/src/Volo.Abp.Session/Volo/Abp/Session/RolePermissionValueProvider.cs index a3af23959f..9b9c102dc1 100644 --- a/src/Volo.Abp.Session/Volo/Abp/Session/RolePermissionValueProvider.cs +++ b/src/Volo.Abp.Session/Volo/Abp/Session/RolePermissionValueProvider.cs @@ -18,22 +18,22 @@ namespace Volo.Abp.Session CurrentUser = currentUser; } - public override async Task IsGrantedAsync(PermissionDefinition permission) + public override async Task CheckAsync(PermissionDefinition permission) { if (CurrentUser.Id == null || !CurrentUser.Roles.Any()) { - return false; + return PermissionValueProviderGrantInfo.NonGranted; } foreach (var role in CurrentUser.Roles) { if (await PermissionStore.IsGrantedAsync(permission.Name, Name, role)) { - return true; + return new PermissionValueProviderGrantInfo(true, role); } } - return false; + return PermissionValueProviderGrantInfo.NonGranted; } } } \ No newline at end of file diff --git a/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs b/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs index 6771561a04..14db07cac9 100644 --- a/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs +++ b/src/Volo.Abp.Session/Volo/Abp/Session/UserPermissionValueProvider.cs @@ -17,14 +17,17 @@ namespace Volo.Abp.Session CurrentUser = currentUser; } - public override async Task IsGrantedAsync(PermissionDefinition permission) + public override async Task CheckAsync(PermissionDefinition permission) { if (CurrentUser.Id == null) { - return false; + return PermissionValueProviderGrantInfo.NonGranted; } - return await PermissionStore.IsGrantedAsync(permission.Name, Name, CurrentUser.Id.Value.ToString()); + return new PermissionValueProviderGrantInfo( + await PermissionStore.IsGrantedAsync(permission.Name, Name, CurrentUser.Id.Value.ToString()), + CurrentUser.Id.ToString() + ); } } }