using API.Authentication.GrantNames; using API.Authentication.Interfaces; using API.DTO.Base; using API.Services; using DAL.Models; namespace API.Authentication { public class ImageAuthentication : IImageAuthentication { private readonly GrantService _grantService; private readonly ILogger _logger; public ImageAuthentication(ILogger logger, GrantService grantService) { _logger = logger; _grantService = grantService; } public bool canGetAll(User user) { return _grantService.hasGrant(user.permissionId, ImageGrantNames.CanGetAll); } public bool canGet(Image model, User user) { return _grantService.hasGrant(user.permissionId, ImageGrantNames.CanGetAny) || _grantService.getULongValues(user.permissionId, ImageGrantNames.CanGet).Exists(x => x == model.id); } public bool canAdd(ImageDTO item, User user) { return _grantService.hasGrant(user.permissionId, ImageGrantNames.CanAdd); } public bool canUpdate(Image model, User user) { return _grantService.hasGrant(user.permissionId, ImageGrantNames.CanUpdateAny) || _grantService.getULongValues(user.permissionId, ImageGrantNames.CanUpdate).Exists(x => x == model.id); } public bool canDelete(Image model, User user) { return _grantService.hasGrant(user.permissionId, ImageGrantNames.CanDeleteAny) || _grantService.getULongValues(user.permissionId, ImageGrantNames.CanDelete).Exists(x => x == model.id); } } }