Added EventAuthentication
This commit is contained in:
parent
58cf1cd74c
commit
7ae98f4bb4
44
API/Authentication/EventAuthentication.cs
Normal file
44
API/Authentication/EventAuthentication.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class EventAuthentication : IEventAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly ILogger<EventAuthentication> _logger;
|
||||
|
||||
public EventAuthentication(GrantService grantService, ILogger<EventAuthentication> logger)
|
||||
{
|
||||
_grantService = grantService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanGetAll);
|
||||
}
|
||||
public bool canGet(Event model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanGetAny) ||
|
||||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(EventDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanAdd);
|
||||
}
|
||||
public bool canUpdate(Event model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanUpdateAny) ||
|
||||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canDelete(Event model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanDeleteAny) ||
|
||||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanDelete).Exists(x => x == model.id);
|
||||
}
|
||||
}
|
||||
}
|
14
API/Authentication/GrantNames/EventGrantNames.cs
Normal file
14
API/Authentication/GrantNames/EventGrantNames.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace API.Authentication.GrantNames
|
||||
{
|
||||
public static class EventGrantNames
|
||||
{
|
||||
public const string CanGetAll = "api.event.get.all";
|
||||
public const string CanGetAny = "api.event.get.any";
|
||||
public const string CanGet = "api.event.get";
|
||||
public const string CanAdd = "api.event.add";
|
||||
public const string CanUpdateAny = "api.event.update.any";
|
||||
public const string CanUpdate = "api.event.update";
|
||||
public const string CanDeleteAny = "api.event.delete.any";
|
||||
public const string CanDelete = "api.event.delete";
|
||||
}
|
||||
}
|
9
API/Authentication/Interfaces/IEventAuthentication.cs
Normal file
9
API/Authentication/Interfaces/IEventAuthentication.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using API.DTO.Base;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication.Interfaces
|
||||
{
|
||||
public interface IEventAuthentication : IGenericAuthentication<EventDTO, Event>
|
||||
{
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ namespace API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class EventController : CRUDBase<EventController, EventDTO, EventUpdateDTO, Event, AuditEvent, IYesAuthentication, EventService>
|
||||
public class EventController : CRUDBase<EventController, EventDTO, EventUpdateDTO, Event, AuditEvent, IEventAuthentication, EventService>
|
||||
{
|
||||
public EventController(ILogger<EventController> logger, UserService userService, EventService service) : base(logger, userService, service)
|
||||
{
|
||||
|
@ -6,9 +6,9 @@ using DAL.Models.Audits;
|
||||
|
||||
namespace API.Services
|
||||
{
|
||||
public class EventService : ServiceBase<EventService, EventDTO, Event, AuditEvent, IYesAuthentication>
|
||||
public class EventService : ServiceBase<EventService, EventDTO, Event, AuditEvent, IEventAuthentication>
|
||||
{
|
||||
public EventService(ILogger<EventService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
|
||||
public EventService(ILogger<EventService> logger, SASGContext context, IEventAuthentication auth) : base(logger, context, auth)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user