2024-07-12 22:44:58 -05:00
|
|
|
using API.Authentication.GrantNames;
|
2024-05-20 10:44:18 -05:00
|
|
|
using API.Authentication.Interfaces;
|
|
|
|
using API.DTO.Base;
|
2024-07-12 22:44:58 -05:00
|
|
|
using API.Services;
|
2024-08-19 16:08:35 -05:00
|
|
|
using API.Services.Interfaces;
|
2024-05-20 10:44:18 -05:00
|
|
|
using DAL.Models;
|
|
|
|
|
|
|
|
namespace API.Authentication
|
|
|
|
{
|
|
|
|
public class ColorAuthentication : IColorAuthentication
|
|
|
|
{
|
2024-08-19 16:08:35 -05:00
|
|
|
private readonly IGrantManager _grantManager;
|
2024-05-20 10:44:18 -05:00
|
|
|
private readonly ILogger<ColorAuthentication> _logger;
|
2024-08-19 16:08:35 -05:00
|
|
|
public ColorAuthentication(ILogger<ColorAuthentication> logger, IGrantManager grantManager)
|
2024-05-20 10:44:18 -05:00
|
|
|
{
|
|
|
|
_logger = logger;
|
2024-08-19 16:08:35 -05:00
|
|
|
_grantManager = grantManager;
|
2024-05-20 10:44:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool canGetAll(User user)
|
|
|
|
{
|
2024-08-19 16:08:35 -05:00
|
|
|
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanGetAll);
|
2024-05-20 10:44:18 -05:00
|
|
|
}
|
|
|
|
public bool canGet(Color model, User user)
|
|
|
|
{
|
2024-08-19 16:08:35 -05:00
|
|
|
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanGetAny) ||
|
|
|
|
_grantManager.getULongValues(user.permissionId, ColorGrantNames.CanGet).Exists(x => x == model.id);
|
2024-05-20 10:44:18 -05:00
|
|
|
}
|
|
|
|
public bool canAdd(ColorDTO item, User user)
|
|
|
|
{
|
2024-08-19 16:08:35 -05:00
|
|
|
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanAdd);
|
2024-05-20 10:44:18 -05:00
|
|
|
}
|
|
|
|
public bool canUpdate(Color model, User user)
|
|
|
|
{
|
2024-08-19 16:08:35 -05:00
|
|
|
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanUpdateAny) ||
|
|
|
|
_grantManager.getULongValues(user.permissionId, ColorGrantNames.CanUpdate).Exists(x => x == model.id);
|
2024-05-20 10:44:18 -05:00
|
|
|
}
|
|
|
|
public bool canDelete(Color model, User user)
|
|
|
|
{
|
2024-08-19 16:08:35 -05:00
|
|
|
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanDeleteAny) ||
|
|
|
|
_grantManager.getULongValues(user.permissionId, ColorGrantNames.CanDelete).Exists(x => x == model.id);
|
2024-05-20 10:44:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|