mirror of https://github.com/abpframework/abp.git
committed by
GitHub
12 changed files with 124 additions and 45 deletions
@ -1,35 +1,22 @@ |
|||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Linq; |
|
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.Application.Services; |
using Volo.Abp.Application.Services; |
||||
using Volo.Abp.Authorization.Permissions; |
|
||||
|
|
||||
namespace Volo.Abp.PermissionManagement.Integration; |
namespace Volo.Abp.PermissionManagement.Integration; |
||||
|
|
||||
[IntegrationService] |
[IntegrationService] |
||||
public class PermissionIntegrationService : ApplicationService, IPermissionIntegrationService |
public class PermissionIntegrationService : ApplicationService, IPermissionIntegrationService |
||||
{ |
{ |
||||
protected IPermissionManager PermissionManager { get; } |
protected IPermissionFinder PermissionFinder { get; } |
||||
|
|
||||
public PermissionIntegrationService(IPermissionManager permissionManager) |
public PermissionIntegrationService(IPermissionFinder permissionFinder) |
||||
{ |
{ |
||||
PermissionManager = permissionManager; |
PermissionFinder = permissionFinder; |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ListResultDto<PermissionGrantOutput>> IsGrantedAsync(List<PermissionGrantInput> input) |
public virtual async Task<ListResultDto<IsGrantedResponse>> IsGrantedAsync(List<IsGrantedRequest> input) |
||||
{ |
{ |
||||
var result = new List<PermissionGrantOutput>(); |
return new ListResultDto<IsGrantedResponse>(await PermissionFinder.IsGrantedAsync(input)); |
||||
foreach (var item in input) |
|
||||
{ |
|
||||
result.Add(new PermissionGrantOutput |
|
||||
{ |
|
||||
UserId = item.UserId, |
|
||||
Permissions = (await PermissionManager.GetAsync(item.PermissionNames, UserPermissionValueProvider.ProviderName, item.UserId.ToString())).Result |
|
||||
.ToDictionary(x => x.Name, x => x.IsGranted) |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
return new ListResultDto<PermissionGrantOutput>(result); |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,9 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.PermissionManagement; |
||||
|
|
||||
|
public interface IPermissionFinder |
||||
|
{ |
||||
|
Task<List<IsGrantedResponse>> IsGrantedAsync(List<IsGrantedRequest> requests); |
||||
|
} |
||||
@ -1,8 +1,8 @@ |
|||||
using System; |
using System; |
||||
|
|
||||
namespace Volo.Abp.PermissionManagement.Integration; |
namespace Volo.Abp.PermissionManagement; |
||||
|
|
||||
public class PermissionGrantInput |
public class IsGrantedRequest |
||||
{ |
{ |
||||
public Guid UserId { get; set; } |
public Guid UserId { get; set; } |
||||
|
|
||||
@ -1,9 +1,9 @@ |
|||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
|
|
||||
namespace Volo.Abp.PermissionManagement.Integration; |
namespace Volo.Abp.PermissionManagement; |
||||
|
|
||||
public class PermissionGrantOutput |
public class IsGrantedResponse |
||||
{ |
{ |
||||
public Guid UserId { get; set; } |
public Guid UserId { get; set; } |
||||
|
|
||||
@ -0,0 +1,26 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.PermissionManagement; |
||||
|
|
||||
|
public static class PermissionFinderExtensions |
||||
|
{ |
||||
|
public async static Task<bool> IsGrantedAsync(this IPermissionFinder permissionFinder, Guid userId, string permissionName) |
||||
|
{ |
||||
|
return await permissionFinder.IsGrantedAsync(userId, new[] { permissionName }); |
||||
|
} |
||||
|
|
||||
|
public async static Task<bool> IsGrantedAsync(this IPermissionFinder permissionFinder, Guid userId, string[] permissionNames) |
||||
|
{ |
||||
|
return (await permissionFinder.IsGrantedAsync(new List<IsGrantedRequest> |
||||
|
{ |
||||
|
new IsGrantedRequest |
||||
|
{ |
||||
|
UserId = userId, |
||||
|
PermissionNames = permissionNames |
||||
|
} |
||||
|
})).Any(x => x.UserId == userId && x.Permissions.All(p => permissionNames.Contains(p.Key) && p.Value)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.PermissionManagement; |
||||
|
|
||||
|
public class PermissionFinder : IPermissionFinder, ITransientDependency |
||||
|
{ |
||||
|
protected IPermissionManager PermissionManager { get; } |
||||
|
|
||||
|
public PermissionFinder(IPermissionManager permissionManager) |
||||
|
{ |
||||
|
PermissionManager = permissionManager; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<IsGrantedResponse>> IsGrantedAsync(List<IsGrantedRequest> requests) |
||||
|
{ |
||||
|
var result = new List<IsGrantedResponse>(); |
||||
|
foreach (var item in requests) |
||||
|
{ |
||||
|
result.Add(new IsGrantedResponse |
||||
|
{ |
||||
|
UserId = item.UserId, |
||||
|
Permissions = (await PermissionManager.GetAsync(item.PermissionNames, UserPermissionValueProvider.ProviderName, item.UserId.ToString())).Result |
||||
|
.ToDictionary(x => x.Name, x => x.IsGranted) |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.PermissionManagement.Integration; |
||||
|
|
||||
|
namespace Volo.Abp.PermissionManagement; |
||||
|
|
||||
|
[Dependency(TryRegister = true)] |
||||
|
public class HttpClientPermissionFinder : IPermissionFinder, ITransientDependency |
||||
|
{ |
||||
|
protected IPermissionIntegrationService PermissionIntegrationService { get; } |
||||
|
|
||||
|
public HttpClientPermissionFinder(IPermissionIntegrationService permissionIntegrationService) |
||||
|
{ |
||||
|
PermissionIntegrationService = permissionIntegrationService; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<IsGrantedResponse>> IsGrantedAsync(List<IsGrantedRequest> requests) |
||||
|
{ |
||||
|
return (await PermissionIntegrationService.IsGrantedAsync(requests)).Items.ToList(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue