44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
|
using API.Authentication.GrantNames;
|
||
|
using API.Authentication.Interfaces;
|
||
|
using API.DTO.Base;
|
||
|
using API.Services;
|
||
|
using DAL.Models;
|
||
|
|
||
|
namespace API.Authentication
|
||
|
{
|
||
|
public class SavedEventAuthentication : ISavedEventAuthentication
|
||
|
{
|
||
|
private readonly GrantService _grantService;
|
||
|
private readonly ILogger<SavedEventAuthentication> _logger;
|
||
|
public SavedEventAuthentication(ILogger<SavedEventAuthentication> logger, GrantService grantService)
|
||
|
{
|
||
|
_logger = logger;
|
||
|
_grantService = grantService;
|
||
|
}
|
||
|
|
||
|
public bool canGetAll(User user)
|
||
|
{
|
||
|
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanGetAll);
|
||
|
}
|
||
|
public bool canGet(SavedEvent model, User user)
|
||
|
{
|
||
|
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanGetAny) ||
|
||
|
_grantService.getULongValues(user.permissionId, SavedEventGrantNames.CanGet).Exists(x => x == model.id);
|
||
|
}
|
||
|
public bool canAdd(SavedEventDTO item, User user)
|
||
|
{
|
||
|
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanAdd);
|
||
|
}
|
||
|
public bool canUpdate(SavedEvent model, User user)
|
||
|
{
|
||
|
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanUpdateAny) ||
|
||
|
_grantService.getULongValues(user.permissionId, SavedEventGrantNames.CanUpdate).Exists(x => x == model.id);
|
||
|
}
|
||
|
public bool canDelete(SavedEvent model, User user)
|
||
|
{
|
||
|
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanDeleteAny) ||
|
||
|
_grantService.getULongValues(user.permissionId, SavedEventGrantNames.CanDelete).Exists(x => x == model.id);
|
||
|
}
|
||
|
}
|
||
|
}
|