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 ColorAuthentication : IColorAuthentication
|
|
{
|
|
private readonly GrantService _grantService;
|
|
private readonly ILogger<ColorAuthentication> _logger;
|
|
public ColorAuthentication(ILogger<ColorAuthentication> logger, GrantService grantService)
|
|
{
|
|
_logger = logger;
|
|
_grantService = grantService;
|
|
}
|
|
|
|
public bool canGetAll(User user)
|
|
{
|
|
return _grantService.hasGrant(user.permissionId, ColorGrantNames.CanGetAll);
|
|
}
|
|
public bool canGet(Color model, User user)
|
|
{
|
|
return _grantService.hasGrant(user.permissionId, ColorGrantNames.CanGetAny) ||
|
|
_grantService.getULongValues(user.permissionId, ColorGrantNames.CanGet).Exists(x => x == model.id);
|
|
}
|
|
public bool canAdd(ColorDTO item, User user)
|
|
{
|
|
return _grantService.hasGrant(user.permissionId, ColorGrantNames.CanAdd);
|
|
}
|
|
public bool canUpdate(Color model, User user)
|
|
{
|
|
return _grantService.hasGrant(user.permissionId, ColorGrantNames.CanUpdateAny) ||
|
|
_grantService.getULongValues(user.permissionId, ColorGrantNames.CanUpdate).Exists(x => x == model.id);
|
|
}
|
|
public bool canDelete(Color model, User user)
|
|
{
|
|
return _grantService.hasGrant(user.permissionId, ColorGrantNames.CanDeleteAny) ||
|
|
_grantService.getULongValues(user.permissionId, ColorGrantNames.CanDelete).Exists(x => x == model.id);
|
|
}
|
|
}
|
|
}
|