2024-08-31 18:38:07 -05:00
|
|
|
using API.Authentication.GrantNames;
|
|
|
|
using API.Authentication.Interfaces;
|
|
|
|
using API.DTO.Base.Update;
|
|
|
|
using API.Services.Interfaces;
|
|
|
|
using DAL.Models;
|
|
|
|
|
|
|
|
namespace API.Authentication
|
|
|
|
{
|
|
|
|
public class SignupAuthentication : ISignupAuthentication
|
|
|
|
{
|
|
|
|
private readonly IGrantManager _grantManager;
|
|
|
|
private readonly ILogger<SignupAuthentication> _logger;
|
2024-10-29 19:13:15 -05:00
|
|
|
|
2024-08-31 18:38:07 -05:00
|
|
|
public SignupAuthentication(IGrantManager grantManager, ILogger<SignupAuthentication> logger)
|
|
|
|
{
|
|
|
|
_grantManager = grantManager;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
2024-10-29 19:13:15 -05:00
|
|
|
|
2024-08-31 18:38:07 -05:00
|
|
|
//todo make more restrictive
|
2024-10-29 19:13:15 -05:00
|
|
|
|
2024-08-31 18:38:07 -05:00
|
|
|
public bool canGetAll(User user)
|
|
|
|
{
|
|
|
|
return _grantManager.hasGrant(user.permissionId, SignupGrantNames.CanGetAll);
|
|
|
|
}
|
|
|
|
public bool canGet(Signup model, User user)
|
|
|
|
{
|
|
|
|
return _grantManager.hasGrant(user.permissionId, SignupGrantNames.CanGetAny) ||
|
|
|
|
_grantManager.getULongValues(user.permissionId, SignupGrantNames.CanGet).Exists(x => x == model.id);
|
|
|
|
}
|
|
|
|
public bool canAdd(SignupDTO item, User user)
|
|
|
|
{
|
2024-10-29 19:13:15 -05:00
|
|
|
if (item.userId == user.id)
|
|
|
|
return _grantManager.hasGrant(user.permissionId, SignupGrantNames.CanAdd);
|
|
|
|
return _grantManager.hasGrant(user.permissionId, SignupGrantNames.CanAddOthers);
|
2024-08-31 18:38:07 -05:00
|
|
|
}
|
|
|
|
public bool canUpdate(Signup model, User user)
|
|
|
|
{
|
|
|
|
return _grantManager.hasGrant(user.permissionId, SignupGrantNames.CanUpdateAny) ||
|
|
|
|
_grantManager.getULongValues(user.permissionId, SignupGrantNames.CanUpdate).Exists(x => x == model.id);
|
|
|
|
}
|
|
|
|
public bool canDelete(Signup model, User user)
|
|
|
|
{
|
|
|
|
return _grantManager.hasGrant(user.permissionId, SignupGrantNames.CanDeleteAny) ||
|
2024-12-19 16:00:48 -06:00
|
|
|
(model.userId == user.id && _grantManager.hasGrant(user.permissionId, SignupGrantNames.CanDeleteSelf)) ||
|
2024-08-31 18:38:07 -05:00
|
|
|
_grantManager.getULongValues(user.permissionId, SignupGrantNames.CanDelete).Exists(x => x == model.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|