-
Notifications
You must be signed in to change notification settings - Fork 4
/
PermissionCheckerManager.cs
32 lines (28 loc) · 1.08 KB
/
PermissionCheckerManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using EasyPermissionManagement.Core.Abstractions;
using EasyPermissionManagement.Core.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EasyPermissionManagement.Core.Concrete
{
public class PermissionCheckerManager : IPermissionChecker
{
private readonly IEasyPermissionContext context;
public PermissionCheckerManager(IEasyPermissionContext context)
{
this.context = context;
}
public virtual Task<bool> CheckAsync(string permissionKey, string provider, string identifierKey)
{
var permission = context.Get<Permission>().FirstOrDefault(a => a.Key == permissionKey && a.Provider == provider);
if (permission is null)
{
throw new Exception($"Permission {permissionKey} not found");
}
return Task.FromResult(context.Get<IdentifierPermission>()
.Any(a => a.PermissionId == permission.Id && a.IdentifierKey == identifierKey));
}
}
}