-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17342 from abpframework/IPermissionFinder
Introduce `IPermissionFinder`.
- Loading branch information
Showing
12 changed files
with
124 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 5 additions & 18 deletions
23
...ent.Application/Volo/Abp/PermissionManagement/Integration/PermissionIntegrationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.Application.Dtos; | ||
using Volo.Abp.Application.Services; | ||
using Volo.Abp.Authorization.Permissions; | ||
|
||
namespace Volo.Abp.PermissionManagement.Integration; | ||
|
||
[IntegrationService] | ||
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>(); | ||
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); | ||
return new ListResultDto<IsGrantedResponse>(await PermissionFinder.IsGrantedAsync(input)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...Abp.PermissionManagement.Domain.Shared/Volo/Abp/PermissionManagement/IPermissionFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
4 changes: 2 additions & 2 deletions
4
...ement/Integration/PermissionGrantInput.cs → .../PermissionManagement/IsGrantedRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ment/Integration/PermissionGrantOutput.cs → ...PermissionManagement/IsGrantedResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ssionManagement.Domain.Shared/Volo/Abp/PermissionManagement/PermissionFinderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...rc/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...sionManagement.HttpApi.Client/Volo/Abp/PermissionManagement/HttpClientPermissionFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters