Added ImageAuthentication
This commit is contained in:
parent
71cabbd548
commit
d5a7ffc596
14
API/Authentication/GrantNames/ImageGrantNames.cs
Normal file
14
API/Authentication/GrantNames/ImageGrantNames.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace API.Authentication.GrantNames
|
||||||
|
{
|
||||||
|
public static class ImageGrantNames
|
||||||
|
{
|
||||||
|
public const string CanGetAll = "api.image.get.all";
|
||||||
|
public const string CanGetAny = "api.image.get.any";
|
||||||
|
public const string CanGet = "api.image.get";
|
||||||
|
public const string CanAdd = "api.image.add";
|
||||||
|
public const string CanUpdateAny = "api.image.update.any";
|
||||||
|
public const string CanUpdate = "api.image.update";
|
||||||
|
public const string CanDeleteAny = "api.image.delete.any";
|
||||||
|
public const string CanDelete = "api.image.delete";
|
||||||
|
}
|
||||||
|
}
|
43
API/Authentication/ImageAuthentication.cs
Normal file
43
API/Authentication/ImageAuthentication.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
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<ImageAuthentication> _logger;
|
||||||
|
public ImageAuthentication(ILogger<ImageAuthentication> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
API/Authentication/Interfaces/IImageAuthentication.cs
Normal file
9
API/Authentication/Interfaces/IImageAuthentication.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using API.DTO.Base;
|
||||||
|
using DAL.Models;
|
||||||
|
|
||||||
|
namespace API.Authentication.Interfaces
|
||||||
|
{
|
||||||
|
public interface IImageAuthentication : IGenericAuthentication<ImageDTO, Image>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ namespace API.Controllers
|
|||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/v1/[controller]")]
|
[Route("api/v1/[controller]")]
|
||||||
public class ImageController : CRUDBase<ImageController, ImageDTO, ImageUpdateDTO, Image, AuditImage, IYesAuthentication, ImageService>
|
public class ImageController : CRUDBase<ImageController, ImageDTO, ImageUpdateDTO, Image, AuditImage, IImageAuthentication, ImageService>
|
||||||
{
|
{
|
||||||
public ImageController(ILogger<ImageController> logger, UserService userService, ImageService service) : base(logger, userService, service)
|
public ImageController(ILogger<ImageController> logger, UserService userService, ImageService service) : base(logger, userService, service)
|
||||||
{
|
{
|
||||||
|
@ -6,9 +6,9 @@ using DAL.Models.Audits;
|
|||||||
|
|
||||||
namespace API.Services
|
namespace API.Services
|
||||||
{
|
{
|
||||||
public class ImageService : ServiceBase<ImageService, ImageDTO, Image, AuditImage, IYesAuthentication>
|
public class ImageService : ServiceBase<ImageService, ImageDTO, Image, AuditImage, IImageAuthentication>
|
||||||
{
|
{
|
||||||
public ImageService(ILogger<ImageService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
|
public ImageService(ILogger<ImageService> logger, SASGContext context, IImageAuthentication auth) : base(logger, context, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user