33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Volo.Abp.Authorization.Permissions;
|
|||
|
|
|
|||
|
|
namespace Sozsoft.Mcp;
|
|||
|
|
|
|||
|
|
public static class PermissionCheckerExtensions
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Verilen yetki adlarından kullanıcıya açık olanlar; tek toplu kontrol yapılır ve sonuç
|
|||
|
|
/// adla sorgulanabilen küme olarak döner. Araç listesi, ekran süzgeci ve ret mesajı aynı kümeyi okur.
|
|||
|
|
/// </summary>
|
|||
|
|
public static async Task<HashSet<string>> GetGrantedNamesAsync(
|
|||
|
|
this IPermissionChecker permissionChecker,
|
|||
|
|
IEnumerable<string> names)
|
|||
|
|
{
|
|||
|
|
var distinct = names.Distinct(StringComparer.Ordinal).ToArray();
|
|||
|
|
if (distinct.Length == 0)
|
|||
|
|
{
|
|||
|
|
return new HashSet<string>(StringComparer.Ordinal);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var grants = await permissionChecker.IsGrantedAsync(distinct);
|
|||
|
|
|
|||
|
|
return grants.Result
|
|||
|
|
.Where(result => result.Value == PermissionGrantResult.Granted)
|
|||
|
|
.Select(result => result.Key)
|
|||
|
|
.ToHashSet(StringComparer.Ordinal);
|
|||
|
|
}
|
|||
|
|
}
|