-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⛏ Implement Permission Checker Manager
- Loading branch information
1 parent
c0e96c3
commit c13fc23
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/EasyPermissionManagement.Core/Concrete/PermissionCheckerManager.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,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)); | ||
} | ||
} | ||
} |