sozsoft-platform/api/modules/Sozsoft.Mcp/Sozsoft.Mcp.Domain.Shared/PermissionCheckerExtensions.cs
2026-10-17 21:51:10 +03:00

32 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}