Skip to content

Commit

Permalink
⛏ Implement Permission Checker Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
furkandeveloper committed Oct 10, 2021
1 parent c0e96c3 commit c13fc23
Showing 1 changed file with 32 additions and 0 deletions.
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));
}
}
}

0 comments on commit c13fc23

Please sign in to comment.