Browse Source

Add resource permission manager extensions for roles and users

pull/24374/head
maliming 3 months ago
parent
commit
8c17421ce6
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 30
      modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/RoleResourcePermissionManagerExtensions.cs
  2. 24
      modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/UserResourcePermissionManagerExtensions.cs

30
modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/RoleResourcePermissionManagerExtensions.cs

@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Authorization.Permissions;
namespace Volo.Abp.PermissionManagement;
public static class RoleResourceresourcePermissionManagerExtensions
{
public static Task<PermissionWithGrantedProviders> GetForRoleAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string roleName, string permissionName, [NotNull] string resourceName, [NotNull] string resourceKey)
{
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager));
return resourcePermissionManager.GetAsync(permissionName, resourceName, resourceKey, RolePermissionValueProvider.ProviderName, roleName);
}
public static Task<List<PermissionWithGrantedProviders>> GetAllForRoleAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string roleName, [NotNull] string resourceName, [NotNull] string resourceKey)
{
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager));
return resourcePermissionManager.GetAllAsync(resourceName, resourceKey, RolePermissionValueProvider.ProviderName, roleName);
}
public static Task SetForRoleAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string roleName, [NotNull] string permissionName, [NotNull] string resourceName, [NotNull] string resourceKey, bool isGranted)
{
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager));
return resourcePermissionManager.SetAsync(permissionName, resourceName, resourceKey, RolePermissionValueProvider.ProviderName, roleName, isGranted);
}
}

24
modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/UserResourcePermissionManagerExtensions.cs

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Authorization.Permissions.Resources;
namespace Volo.Abp.PermissionManagement;
public static class UserResourcePermissionManagerExtensions
{
public static Task<List<PermissionWithGrantedProviders>> GetAllForUserAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, Guid userId, [NotNull] string resourceName, [NotNull] string resourceKey)
{
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager));
return resourcePermissionManager.GetAllAsync(resourceName, resourceKey, UserResourcePermissionValueProvider.ProviderName, userId.ToString());
}
public static Task SetForUserAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, Guid userId, [NotNull] string name, [NotNull] string resourceName, [NotNull] string resourceKey, bool isGranted)
{
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager));
return resourcePermissionManager.SetAsync(name, resourceName, resourceKey, UserResourcePermissionValueProvider.ProviderName, userId.ToString(), isGranted);
}
}
Loading…
Cancel
Save