Compare commits
5 Commits
a07f5f5869
...
fe1213ed90
Author | SHA1 | Date | |
---|---|---|---|
fe1213ed90 | |||
ea3799e9b0 | |||
374b8c64c9 | |||
63b95b7ee6 | |||
13f92d49cc |
6
.gitignore
vendored
6
.gitignore
vendored
@ -3,3 +3,9 @@
|
||||
/API/bin/
|
||||
/API/obj/
|
||||
/API/appsettings.*
|
||||
/Setup/bin/
|
||||
/Setup/obj/
|
||||
/Setup/appsettings.*
|
||||
/web/bin/
|
||||
/web/obj/
|
||||
/web/appsettings.*
|
||||
|
7
.idea/.idea.sanAntonioSeniorGolf/.idea/sqldialects.xml
generated
Normal file
7
.idea/.idea.sanAntonioSeniorGolf/.idea/sqldialects.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/Setup/Filler/Grants.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/Setup/Filler/Permissions.sql" dialect="MySQL" />
|
||||
</component>
|
||||
</project>
|
@ -2,42 +2,43 @@ using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class ColorAuthentication : IColorAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly IGrantManager _grantManager;
|
||||
private readonly ILogger<ColorAuthentication> _logger;
|
||||
public ColorAuthentication(ILogger<ColorAuthentication> logger, GrantService grantService)
|
||||
public ColorAuthentication(ILogger<ColorAuthentication> logger, IGrantManager grantManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_grantService = grantService;
|
||||
_grantManager = grantManager;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, ColorGrantNames.CanGetAll);
|
||||
return _grantManager.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);
|
||||
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanGetAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, ColorGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(ColorDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, ColorGrantNames.CanAdd);
|
||||
return _grantManager.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);
|
||||
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanUpdateAny) ||
|
||||
_grantManager.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);
|
||||
return _grantManager.hasGrant(user.permissionId, ColorGrantNames.CanDeleteAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, ColorGrantNames.CanDelete).Exists(x => x == model.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,43 +2,44 @@ using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class EventAuthentication : IEventAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly IGrantManager _grantManager;
|
||||
private readonly ILogger<EventAuthentication> _logger;
|
||||
|
||||
public EventAuthentication(GrantService grantService, ILogger<EventAuthentication> logger)
|
||||
public EventAuthentication(IGrantManager grantManager, ILogger<EventAuthentication> logger)
|
||||
{
|
||||
_grantService = grantService;
|
||||
_grantManager = grantManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanGetAll);
|
||||
return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanGetAll);
|
||||
}
|
||||
public bool canGet(Event model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanGetAny) ||
|
||||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanGet).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanGetAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, EventGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(EventDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanAdd);
|
||||
return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanAdd);
|
||||
}
|
||||
public bool canUpdate(Event model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanUpdateAny) ||
|
||||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanUpdateAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, EventGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canDelete(Event model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanDeleteAny) ||
|
||||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanDelete).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanDeleteAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, EventGrantNames.CanDelete).Exists(x => x == model.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,34 +2,35 @@ using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class GrantAuthentication : IGrantAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly IGrantManager _grantManager;
|
||||
private readonly ILogger<GrantAuthentication> _logger;
|
||||
|
||||
public GrantAuthentication(GrantService grantService, ILogger<GrantAuthentication> logger)
|
||||
public GrantAuthentication(IGrantManager grantManager, ILogger<GrantAuthentication> logger)
|
||||
{
|
||||
_grantService = grantService;
|
||||
_grantManager = grantManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, GrantGrantNames.CanGetAll);
|
||||
return _grantManager.hasGrant(user.permissionId, GrantGrantNames.CanGetAll);
|
||||
}
|
||||
public bool canGet(Grant model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, GrantGrantNames.CanGetAny) ||
|
||||
_grantService.getULongValues(user.permissionId, GrantGrantNames.CanGet).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, GrantGrantNames.CanGetAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, GrantGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(GrantDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, GrantGrantNames.CanAdd) &&
|
||||
_grantService.hasGrant(user.permissionId, item.name);
|
||||
return _grantManager.hasGrant(user.permissionId, GrantGrantNames.CanAdd) &&
|
||||
_grantManager.hasGrant(user.permissionId, item.name);
|
||||
}
|
||||
public bool canUpdate(Grant model, User user)
|
||||
{
|
||||
@ -38,9 +39,9 @@ namespace API.Authentication
|
||||
}
|
||||
public bool canDelete(Grant model, User user)
|
||||
{
|
||||
return (_grantService.hasGrant(user.permissionId, GrantGrantNames.CanDeleteAny) ||
|
||||
_grantService.getULongValues(user.permissionId, GrantGrantNames.CanDelete).Exists(x => x == model.id))
|
||||
&& _grantService.hasGrant(user.permissionId, model.name);
|
||||
return (_grantManager.hasGrant(user.permissionId, GrantGrantNames.CanDeleteAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, GrantGrantNames.CanDelete).Exists(x => x == model.id))
|
||||
&& _grantManager.hasGrant(user.permissionId, model.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,42 +2,43 @@ using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class ImageAuthentication : IImageAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly IGrantManager _grantManager;
|
||||
private readonly ILogger<ImageAuthentication> _logger;
|
||||
public ImageAuthentication(ILogger<ImageAuthentication> logger, GrantService grantService)
|
||||
public ImageAuthentication(ILogger<ImageAuthentication> logger, IGrantManager grantManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_grantService = grantService;
|
||||
_grantManager = grantManager;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, ImageGrantNames.CanGetAll);
|
||||
return _grantManager.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);
|
||||
return _grantManager.hasGrant(user.permissionId, ImageGrantNames.CanGetAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, ImageGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(ImageDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, ImageGrantNames.CanAdd);
|
||||
return _grantManager.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);
|
||||
return _grantManager.hasGrant(user.permissionId, ImageGrantNames.CanUpdateAny) ||
|
||||
_grantManager.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);
|
||||
return _grantManager.hasGrant(user.permissionId, ImageGrantNames.CanDeleteAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, ImageGrantNames.CanDelete).Exists(x => x == model.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,42 +2,43 @@ using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class PermissionAuthentication : IPermissionAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly IGrantManager _grantManager;
|
||||
private readonly ILogger<PermissionAuthentication> _logger;
|
||||
public PermissionAuthentication(ILogger<PermissionAuthentication> logger, GrantService grantService)
|
||||
public PermissionAuthentication(ILogger<PermissionAuthentication> logger, IGrantManager grantManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_grantService = grantService;
|
||||
_grantManager = grantManager;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, PermissionGrantNames.CanGetAll);
|
||||
return _grantManager.hasGrant(user.permissionId, PermissionGrantNames.CanGetAll);
|
||||
}
|
||||
public bool canGet(Permission model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, PermissionGrantNames.CanGetAny) ||
|
||||
_grantService.getULongValues(user.permissionId, PermissionGrantNames.CanGet).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, PermissionGrantNames.CanGetAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, PermissionGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(PermissionDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, PermissionGrantNames.CanAdd);
|
||||
return _grantManager.hasGrant(user.permissionId, PermissionGrantNames.CanAdd);
|
||||
}
|
||||
public bool canUpdate(Permission model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, PermissionGrantNames.CanUpdateAny) ||
|
||||
_grantService.getULongValues(user.permissionId, PermissionGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, PermissionGrantNames.CanUpdateAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, PermissionGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canDelete(Permission model, User user)
|
||||
{
|
||||
return (_grantService.hasGrant(user.permissionId, PermissionGrantNames.CanDeleteAny) ||
|
||||
_grantService.getULongValues(user.permissionId, PermissionGrantNames.CanDelete).Exists(x => x == model.id))
|
||||
return (_grantManager.hasGrant(user.permissionId, PermissionGrantNames.CanDeleteAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, PermissionGrantNames.CanDelete).Exists(x => x == model.id))
|
||||
&& model.id != user.permissionId;
|
||||
}
|
||||
}
|
||||
|
@ -2,42 +2,43 @@ using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class SavedEventAuthentication : ISavedEventAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly IGrantManager _grantManager;
|
||||
private readonly ILogger<SavedEventAuthentication> _logger;
|
||||
public SavedEventAuthentication(ILogger<SavedEventAuthentication> logger, GrantService grantService)
|
||||
public SavedEventAuthentication(ILogger<SavedEventAuthentication> logger, IGrantManager grantManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_grantService = grantService;
|
||||
_grantManager = grantManager;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanGetAll);
|
||||
return _grantManager.hasGrant(user.permissionId, SavedEventGrantNames.CanGetAll);
|
||||
}
|
||||
public bool canGet(SavedEvent model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanGetAny) ||
|
||||
_grantService.getULongValues(user.permissionId, SavedEventGrantNames.CanGet).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, SavedEventGrantNames.CanGetAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, SavedEventGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(SavedEventDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanAdd);
|
||||
return _grantManager.hasGrant(user.permissionId, SavedEventGrantNames.CanAdd);
|
||||
}
|
||||
public bool canUpdate(SavedEvent model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanUpdateAny) ||
|
||||
_grantService.getULongValues(user.permissionId, SavedEventGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, SavedEventGrantNames.CanUpdateAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, SavedEventGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canDelete(SavedEvent model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, SavedEventGrantNames.CanDeleteAny) ||
|
||||
_grantService.getULongValues(user.permissionId, SavedEventGrantNames.CanDelete).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, SavedEventGrantNames.CanDeleteAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, SavedEventGrantNames.CanDelete).Exists(x => x == model.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,45 +2,44 @@ using API.Authentication.GrantNames;
|
||||
using API.Authentication.Interfaces;
|
||||
using API.DTO.Base;
|
||||
using API.Services;
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Models;
|
||||
|
||||
namespace API.Authentication
|
||||
{
|
||||
public class UserAuthentication : IUserAuthentication
|
||||
{
|
||||
private readonly GrantService _grantService;
|
||||
private readonly IGrantManager _grantManager;
|
||||
private readonly ILogger<UserAuthentication> _logger;
|
||||
private readonly UserService _userService;
|
||||
public UserAuthentication(ILogger<UserAuthentication> logger, GrantService grantService, UserService userService)
|
||||
public UserAuthentication(ILogger<UserAuthentication> logger, IGrantManager grantManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_grantService = grantService;
|
||||
_userService = userService;
|
||||
_grantManager = grantManager;
|
||||
}
|
||||
|
||||
public bool canGetAll(User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, UserGrantNames.CanGetAll);
|
||||
return _grantManager.hasGrant(user.permissionId, UserGrantNames.CanGetAll);
|
||||
}
|
||||
public bool canGet(User model, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, UserGrantNames.CanGetAny) ||
|
||||
_grantService.getULongValues(user.permissionId, UserGrantNames.CanGet).Exists(x => x == model.id);
|
||||
return _grantManager.hasGrant(user.permissionId, UserGrantNames.CanGetAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, UserGrantNames.CanGet).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canAdd(UserDTO item, User user)
|
||||
{
|
||||
return _grantService.hasGrant(user.permissionId, UserGrantNames.CanAdd);
|
||||
return _grantManager.hasGrant(user.permissionId, UserGrantNames.CanAdd);
|
||||
}
|
||||
|
||||
// todo this needs to be made much better
|
||||
public bool canUpdate(User model, User user)
|
||||
{
|
||||
User origUser;
|
||||
User origUser = user;
|
||||
if (model.id == user.id)
|
||||
{
|
||||
if (!_grantService.hasGrant(user.permissionId, UserGrantNames.CanUpdateSelf)
|
||||
|| !_grantService.hasGrant(user.permissionId, UserGrantNames.CanUpdateAny)
|
||||
|| !_grantService.getULongValues(user.permissionId, UserGrantNames.CanUpdate).Exists(x => x == model.id)
|
||||
if (!_grantManager.hasGrant(user.permissionId, UserGrantNames.CanUpdateSelf)
|
||||
|| !_grantManager.hasGrant(user.permissionId, UserGrantNames.CanUpdateAny)
|
||||
|| !_grantManager.getULongValues(user.permissionId, UserGrantNames.CanUpdate).Exists(x => x == model.id)
|
||||
)
|
||||
return false;
|
||||
|
||||
@ -49,38 +48,38 @@ namespace API.Authentication
|
||||
return false;
|
||||
origUser = user;
|
||||
}
|
||||
else
|
||||
{
|
||||
origUser = _userService.getNoAuthentication(model.id) ?? throw new InvalidOperationException("Model is null.");
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// origUser = _userService.getNoAuthentication(model.id) ?? throw new InvalidOperationException("Model is null.");
|
||||
// }
|
||||
|
||||
if (origUser.permissionId != model.permissionId)
|
||||
{
|
||||
if (!_grantService.hasGrant(user.permissionId, UserGrantNames.CanUpdatePermission))
|
||||
if (!_grantManager.hasGrant(user.permissionId, UserGrantNames.CanUpdatePermission))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (origUser.firstName != user.firstName || origUser.lastName != user.lastName)
|
||||
{
|
||||
if (!_grantService.hasGrant(user.permissionId, UserGrantNames.CanUpdateNames))
|
||||
if (!_grantManager.hasGrant(user.permissionId, UserGrantNames.CanUpdateNames))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (origUser.phoneNumber != user.phoneNumber)
|
||||
{
|
||||
if (!_grantService.hasGrant(user.permissionId, UserGrantNames.CanUpdatePhoneNumber))
|
||||
if (!_grantManager.hasGrant(user.permissionId, UserGrantNames.CanUpdatePhoneNumber))
|
||||
return false;
|
||||
}
|
||||
|
||||
return _grantService.hasGrant(user.permissionId, UserGrantNames.CanUpdateAny)
|
||||
return _grantManager.hasGrant(user.permissionId, UserGrantNames.CanUpdateAny)
|
||||
|| model.id == user.id &&
|
||||
_grantService.hasGrant(user.permissionId, UserGrantNames.CanUpdateSelf)
|
||||
|| _grantService.getULongValues(user.permissionId, UserGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
_grantManager.hasGrant(user.permissionId, UserGrantNames.CanUpdateSelf)
|
||||
|| _grantManager.getULongValues(user.permissionId, UserGrantNames.CanUpdate).Exists(x => x == model.id);
|
||||
}
|
||||
public bool canDelete(User model, User user)
|
||||
{
|
||||
return (_grantService.hasGrant(user.permissionId, UserGrantNames.CanDeleteAny) ||
|
||||
_grantService.getULongValues(user.permissionId, UserGrantNames.CanDelete).Exists(x => x == model.id))
|
||||
return (_grantManager.hasGrant(user.permissionId, UserGrantNames.CanDeleteAny) ||
|
||||
_grantManager.getULongValues(user.permissionId, UserGrantNames.CanDelete).Exists(x => x == model.id))
|
||||
&& model.id != user.id;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using API.Services;
|
||||
using DAL.Models;
|
||||
using DAL.Models.Audits;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MUser = DAL.Models.User;
|
||||
|
||||
namespace API.Controllers
|
||||
{
|
||||
@ -15,5 +16,28 @@ namespace API.Controllers
|
||||
public EventController(ILogger<EventController> logger, UserService userService, EventService service) : base(logger, userService, service)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpGet("period")]
|
||||
public virtual ActionResult<List<EventDTO>> getPeriod(DateTime start, DateTime end)
|
||||
{
|
||||
MUser? user = getUser(User);
|
||||
if (user == null)
|
||||
return Unauthorized();
|
||||
|
||||
IEnumerable<Event>? result = Service.get(user, x=> x.when >= start && x.when <= end);
|
||||
if (result == null)
|
||||
return Forbid();
|
||||
|
||||
List<EventDTO> dtos = [];
|
||||
|
||||
Parallel.ForEach(result, item =>
|
||||
{
|
||||
EventDTO dto = new EventDTO();
|
||||
dto.adaptFromModel(item);
|
||||
dtos.Add(dto);
|
||||
});
|
||||
|
||||
return Ok(dtos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace API.DTO.Base
|
||||
public ulong? bgColorId { get; set; }
|
||||
public ulong? fgColorId { get; set; }
|
||||
public ulong? imageId { get; set; }
|
||||
public DateTime when { get; set; }
|
||||
public bool hidden { get; set; }
|
||||
public DateTime updated { get; set; }
|
||||
public ulong updater { get; set; }
|
||||
@ -28,6 +29,7 @@ namespace API.DTO.Base
|
||||
bgColorId = bgColorId,
|
||||
fgColorId = fgColorId,
|
||||
imageId = imageId,
|
||||
when = when,
|
||||
hidden = hidden,
|
||||
updated = updated,
|
||||
updater = updater
|
||||
@ -41,6 +43,7 @@ namespace API.DTO.Base
|
||||
bgColorId = model.bgColorId;
|
||||
fgColorId = model.fgColorId;
|
||||
imageId = model.imageId;
|
||||
when = model.when;
|
||||
hidden = model.hidden;
|
||||
updated = model.updated;
|
||||
updater = model.updater;
|
||||
|
@ -13,6 +13,7 @@ namespace API.DTO.Base.Update
|
||||
public UnSettable<ulong?>? bgColorId { get; set; }
|
||||
public UnSettable<ulong?>? fgColorId { get; set; }
|
||||
public UnSettable<ulong?>? imageId { get; set; }
|
||||
public UnSettable<DateTime>? when { get; set; }
|
||||
public bool? hidden { get; set; }
|
||||
|
||||
public void adaptModel(ref Event model)
|
||||
@ -22,6 +23,7 @@ namespace API.DTO.Base.Update
|
||||
if (bgColorId != null) model.bgColorId = bgColorId.Value.value;
|
||||
if (fgColorId != null) model.bgColorId = fgColorId.Value.value;
|
||||
if (imageId != null) model.imageId = imageId.Value.value;
|
||||
if (when != null) model.when = when.Value.value;
|
||||
if (hidden != null) model.hidden = (bool)hidden;
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,23 @@ using InvalidOperationException = System.InvalidOperationException;
|
||||
|
||||
namespace API
|
||||
{
|
||||
internal class Program
|
||||
internal static class Program
|
||||
{
|
||||
public static IServiceCollection AddLazyResolution(this IServiceCollection services)
|
||||
{
|
||||
return services.AddTransient(
|
||||
typeof(Lazy<>),
|
||||
typeof(LazilyResolved<>));
|
||||
}
|
||||
|
||||
private class LazilyResolved<T> : Lazy<T>
|
||||
{
|
||||
public LazilyResolved(IServiceProvider serviceProvider)
|
||||
: base(serviceProvider.GetRequiredService<T>)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
@ -58,12 +73,15 @@ namespace API
|
||||
builder.Services.AddTransient<IGrantAuthentication, GrantAuthentication>();
|
||||
builder.Services.AddTransient<IImageAuthentication, ImageAuthentication>();
|
||||
builder.Services.AddTransient<IColorAuthentication, ColorAuthentication>();
|
||||
builder.Services.AddTransient<IColorAuthentication, ColorAuthentication>();
|
||||
builder.Services.AddTransient<IPermissionAuthentication, PermissionAuthentication>();
|
||||
builder.Services.AddTransient<ISavedEventAuthentication, SavedEventAuthentication>();
|
||||
builder.Services.AddTransient<IUserAuthentication, UserAuthentication>();
|
||||
|
||||
builder.Services.AddTransient<IHashingFactory, HashingFactory>();
|
||||
|
||||
builder.Services.AddTransient<IHashingAlgorithm, Pbkdf2>();
|
||||
|
||||
builder.Services.AddTransient<IGrantManager, GrantManager>();
|
||||
builder.Services.AddTransient<IUserManager, UserManager>(options =>
|
||||
{
|
||||
UserService userService = options.GetRequiredService<UserService>();
|
||||
@ -78,7 +96,13 @@ namespace API
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
|
||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
|
||||
{
|
||||
options.Cookie.SameSite = SameSiteMode.None;
|
||||
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
|
||||
});
|
||||
|
||||
builder.Services.AddLazyResolution();
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
@ -90,11 +114,15 @@ namespace API
|
||||
|
||||
app.UseCookiePolicy(new CookiePolicyOptions
|
||||
{
|
||||
MinimumSameSitePolicy = SameSiteMode.Strict
|
||||
MinimumSameSitePolicy = SameSiteMode.None
|
||||
});
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseCors(builder => {
|
||||
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
|
||||
});
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
|
85
API/Services/GrantManager.cs
Normal file
85
API/Services/GrantManager.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using API.Services.Interfaces;
|
||||
using DAL.Contexts;
|
||||
using DAL.Models;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace API.Services
|
||||
{
|
||||
public class GrantManager : IGrantManager
|
||||
{
|
||||
private ILogger<GrantManager> _logger;
|
||||
private SASGContext _context;
|
||||
|
||||
public GrantManager(ILogger<GrantManager> logger, SASGContext context)
|
||||
{
|
||||
_logger = logger;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
private IEnumerable<Grant> getGrant(Expression<Func<Grant, bool>> whereClause)
|
||||
{
|
||||
return _context.Set<Grant>().Where(whereClause);
|
||||
}
|
||||
|
||||
public bool hasGrant(ulong permissionId, string grantName)
|
||||
{
|
||||
return getGrant(x => x.permissionId == permissionId && x.name.Equals(grantName)).Any();
|
||||
}
|
||||
|
||||
public List<string> getValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<Grant> grants = getGrant(x => x.permissionId == permissionId && x.name.StartsWith(grantName + ".")).ToList();
|
||||
|
||||
List<string> values = [];
|
||||
foreach (Grant grant in grants)
|
||||
{
|
||||
string value = grant.name.Substring(grantName.Length);
|
||||
if (value.Contains('.'))
|
||||
// Were not looking at a value and instead another grant
|
||||
continue;
|
||||
|
||||
values.Add(value);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public List<string> getStringValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<string> values = getValues(permissionId, grantName);
|
||||
|
||||
// Get rid of numbers
|
||||
values = values.Where(x => !Int32.TryParse(x, out int _)).ToList();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public List<int> getIntValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<string> values = getValues(permissionId, grantName);
|
||||
List<int> intValues = [];
|
||||
|
||||
Parallel.ForEach(values, x =>
|
||||
{
|
||||
if (Int32.TryParse(x, out int parsed))
|
||||
intValues.Add(parsed);
|
||||
});
|
||||
|
||||
return intValues;
|
||||
}
|
||||
|
||||
public List<ulong> getULongValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<string> values = getValues(permissionId, grantName);
|
||||
List<ulong> uLongValues = [];
|
||||
|
||||
Parallel.ForEach(values, x =>
|
||||
{
|
||||
if (UInt64.TryParse(x, out ulong parsed))
|
||||
uLongValues.Add(parsed);
|
||||
});
|
||||
|
||||
return uLongValues;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,66 +11,5 @@ namespace API.Services
|
||||
public GrantService(ILogger<GrantService> logger, SASGContext context, IGrantAuthentication auth) : base(logger, context, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public bool hasGrant(ulong permissionId, string grantName)
|
||||
{
|
||||
return getNoAuthentication(x => x.permissionId == permissionId && x.name.Equals(grantName)).Any();
|
||||
}
|
||||
|
||||
public List<string> getValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<Grant> grants = getNoAuthentication(x => x.permissionId == permissionId && x.name.StartsWith(grantName + ".")).ToList();
|
||||
|
||||
List<string> values = [];
|
||||
foreach (Grant grant in grants)
|
||||
{
|
||||
string value = grant.name.Substring(grantName.Length);
|
||||
if (value.Contains('.'))
|
||||
// Were not looking at a value and instead another grant
|
||||
continue;
|
||||
|
||||
values.Add(value);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public List<string> getStringValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<string> values = getValues(permissionId, grantName);
|
||||
|
||||
// Get rid of numbers
|
||||
values = values.Where(x => !Int32.TryParse(x, out int _)).ToList();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public List<int> getIntValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<string> values = getValues(permissionId, grantName);
|
||||
List<int> intValues = [];
|
||||
|
||||
Parallel.ForEach(values, x =>
|
||||
{
|
||||
if (Int32.TryParse(x, out int parsed))
|
||||
intValues.Add(parsed);
|
||||
});
|
||||
|
||||
return intValues;
|
||||
}
|
||||
|
||||
public List<ulong> getULongValues(ulong permissionId, string grantName)
|
||||
{
|
||||
List<string> values = getValues(permissionId, grantName);
|
||||
List<ulong> uLongValues = [];
|
||||
|
||||
Parallel.ForEach(values, x =>
|
||||
{
|
||||
if (UInt64.TryParse(x, out ulong parsed))
|
||||
uLongValues.Add(parsed);
|
||||
});
|
||||
|
||||
return uLongValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
API/Services/Interfaces/IGrantManager.cs
Normal file
11
API/Services/Interfaces/IGrantManager.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace API.Services.Interfaces
|
||||
{
|
||||
public interface IGrantManager
|
||||
{
|
||||
public bool hasGrant(ulong permissionId, string grantName);
|
||||
public List<string> getValues(ulong permissionId, string grantName);
|
||||
public List<string> getStringValues(ulong permissionId, string grantName);
|
||||
public List<int> getIntValues(ulong permissionId, string grantName);
|
||||
public List<ulong> getULongValues(ulong permissionId, string grantName);
|
||||
}
|
||||
}
|
@ -76,8 +76,6 @@ namespace API.Services
|
||||
if (origModel == null)
|
||||
return null;
|
||||
|
||||
copyToAudit(origModel);
|
||||
|
||||
model.updateModel(ref origModel);
|
||||
|
||||
origModel.updated = DateTime.Now;
|
||||
@ -97,22 +95,14 @@ namespace API.Services
|
||||
if (origModel == null)
|
||||
return null;
|
||||
|
||||
copyToAudit(origModel);
|
||||
|
||||
origModel.updated = DateTime.Now;
|
||||
origModel.updater = user.id;
|
||||
|
||||
copyToAudit(origModel);
|
||||
Context.SaveChanges();
|
||||
|
||||
Context.Remove(origModel);
|
||||
Context.SaveChanges();
|
||||
|
||||
return origModel.adaptToAudit();
|
||||
}
|
||||
|
||||
private void copyToAudit(TModel model)
|
||||
{
|
||||
Context.Set<TAudit>().Add(model.adaptToAudit());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,48 +98,6 @@ namespace DAL.Contexts
|
||||
.HasForeignKey(e => e.updater).HasConstraintName("events_users_id_fk");
|
||||
entity.Property(e => e.hashingType).HasConversion<string>();
|
||||
});
|
||||
|
||||
builder.Entity<AuditColor>(entity =>
|
||||
{
|
||||
entity.HasOne<Color>().WithMany(e => e.audits)
|
||||
.HasForeignKey(e => e.originalId).IsRequired();
|
||||
});
|
||||
|
||||
builder.Entity<AuditEvent>(entity =>
|
||||
{
|
||||
entity.HasOne<Event>().WithMany(e => e.audits)
|
||||
.HasForeignKey(e => e.originalId).IsRequired();
|
||||
});
|
||||
|
||||
builder.Entity<AuditGrant>(entity =>
|
||||
{
|
||||
entity.HasOne<Grant>().WithMany(e => e.audits)
|
||||
.HasForeignKey(e => e.originalId).IsRequired();
|
||||
});
|
||||
|
||||
builder.Entity<AuditImage>(entity =>
|
||||
{
|
||||
entity.HasOne<Image>().WithMany(e => e.audits)
|
||||
.HasForeignKey(e => e.originalId).IsRequired();
|
||||
});
|
||||
|
||||
builder.Entity<AuditPermission>(entity =>
|
||||
{
|
||||
entity.HasOne<Permission>().WithMany(e => e.audits)
|
||||
.HasForeignKey(e => e.originalId).IsRequired();
|
||||
});
|
||||
|
||||
builder.Entity<AuditSavedEvent>(entity =>
|
||||
{
|
||||
entity.HasOne<SavedEvent>().WithMany(e => e.audits)
|
||||
.HasForeignKey(e => e.originalId).IsRequired();
|
||||
});
|
||||
|
||||
builder.Entity<AuditUser>(entity =>
|
||||
{
|
||||
entity.HasOne<User>().WithMany(e => e.audits)
|
||||
.HasForeignKey(e => e.originalId).IsRequired();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ namespace DAL.Models.Audits
|
||||
[Column("imageId")]
|
||||
public ulong? imageId { get; set; }
|
||||
|
||||
[Column("when")]
|
||||
public DateTime when { get; set; }
|
||||
|
||||
[Column("hidden")]
|
||||
public bool hidden { get; set; }
|
||||
|
||||
|
@ -11,6 +11,7 @@ namespace DAL.Models
|
||||
[Index("fgColorId", Name = "events_colors_id_fk_2")]
|
||||
[Index("imageId", Name = "events_images_id_fk")]
|
||||
[Index("savedEventId", Name = "events_savedEvents_id_fk")]
|
||||
[Index("when", Name = "events_when_index")]
|
||||
public class Event : Model<Event, AuditEvent>
|
||||
{
|
||||
[Column("savedEventId")]
|
||||
@ -29,6 +30,9 @@ namespace DAL.Models
|
||||
[Column("imageId")]
|
||||
public ulong? imageId { get; set; }
|
||||
|
||||
[Column("when")]
|
||||
public DateTime when { get; set; }
|
||||
|
||||
[Column("hidden")]
|
||||
public bool hidden { get; set; }
|
||||
|
||||
|
180
Setup/Filler/Grants.sql
Normal file
180
Setup/Filler/Grants.sql
Normal file
@ -0,0 +1,180 @@
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.get.all', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.get.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.get', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.add', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.update.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.update', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.delete.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.color.delete', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.get.all', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.get.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.get', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.add', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.update.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.update', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.delete.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.event.delete', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.get.all', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.get.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.get', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.add', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.update.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.update', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.delete.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.grant.delete', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.get.all', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.get.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.get', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.add', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.update.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.update', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.delete.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.image.delete', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.get.all', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.get.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.get', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.add', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.update.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.update', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.delete.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.permission.delete', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.get.all', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.get.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.get', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.add', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.update.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.update', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.delete.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.savedEvent.delete', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.get.all', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.get.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.get', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.add', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.update.any', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.update', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.update.self', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.update.names', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.update.phoneNumber', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.update.permission', 1, NOW(), 1);
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.grants (name, permissionId, updated, updater)
|
||||
VALUES ('api.user.delete.any', 1, NOW(), 1);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
6
Setup/Filler/Permissions.sql
Normal file
6
Setup/Filler/Permissions.sql
Normal file
@ -0,0 +1,6 @@
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
INSERT INTO san_antonio_senior_golf.permissions (name, updated, updater)
|
||||
VALUES ('admin', NOW(), 1);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
116
Setup/Program.cs
Normal file
116
Setup/Program.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using API.Hashing;
|
||||
using API.Hashing.Interfaces;
|
||||
using DAL.Contexts;
|
||||
using DAL.Models;
|
||||
using DAL.Values;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Mysqlx.Session;
|
||||
using System.Configuration;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Setup
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
public static bool lineIsYes(string? input)
|
||||
{
|
||||
if (input == null)
|
||||
return false;
|
||||
|
||||
input = input.Trim().ToLower();
|
||||
switch (input)
|
||||
{
|
||||
case "y":
|
||||
case "yes":
|
||||
return true;
|
||||
case "n":
|
||||
case "no":
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string getStringWithConfirmation(string message)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.Write(message);
|
||||
string? input = Console.ReadLine();
|
||||
Console.WriteLine();
|
||||
if (input == null)
|
||||
continue;
|
||||
|
||||
Console.Write($"Is '{input}' correct? [Y/N]: ");
|
||||
if (lineIsYes(Console.ReadLine()))
|
||||
{
|
||||
Console.WriteLine();
|
||||
return input;
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.Write("Entering setup. Only run this once. Will reinstate database. Continue? [Y/N]: ");
|
||||
if (!lineIsYes(Console.ReadLine()))
|
||||
System.Environment.Exit(0);
|
||||
Console.WriteLine();
|
||||
|
||||
string connectionString = getStringWithConfirmation("Enter connection string: ");
|
||||
|
||||
DbContextOptionsBuilder<SASGContext> optionsBuilder = new DbContextOptionsBuilder<SASGContext>();
|
||||
optionsBuilder.UseMySQL(connectionString);
|
||||
|
||||
SASGContext context = new SASGContext(optionsBuilder.Options);
|
||||
|
||||
string firstName = getStringWithConfirmation("Enter admin first name: ");
|
||||
string lastname = getStringWithConfirmation("Enter admin last name: ");
|
||||
PhoneNumber phoneNumber = getStringWithConfirmation("Enter admin phone number: ");
|
||||
string unHashedPassword = getStringWithConfirmation("Enter admin password: ");
|
||||
|
||||
HashingType defaultHashingType = Enum.Parse<HashingType>(
|
||||
getStringWithConfirmation($"Enter default hashing type [{String.Join(", ", Enum.GetNames(typeof(HashingType)))}]: "));
|
||||
|
||||
IHashingFactory hashingFactory = new HashingFactory();
|
||||
IHashingAlgorithm algorithm = hashingFactory.getAlgorithm(defaultHashingType) ?? throw new InvalidOperationException();
|
||||
|
||||
byte[] salt;
|
||||
string password = algorithm.hash(unHashedPassword, out salt);
|
||||
|
||||
Console.Write("About to touch db. Continue? [Y/N]: ");
|
||||
if (!lineIsYes(Console.ReadLine()))
|
||||
System.Environment.Exit(0);
|
||||
|
||||
MySqlConnection conn = (MySqlConnection) context.Database.GetDbConnection();
|
||||
|
||||
conn.Open();
|
||||
using (MySqlCommand reader = new MySqlCommand(File.ReadAllText("Filler/Permissions.sql"), conn))
|
||||
{
|
||||
reader.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
using (MySqlCommand reader = new MySqlCommand(File.ReadAllText("Filler/Grants.sql"), conn))
|
||||
{
|
||||
reader.ExecuteNonQuery();
|
||||
}
|
||||
conn.Close();
|
||||
|
||||
context.users.Add(new User
|
||||
{
|
||||
firstName = firstName,
|
||||
lastName = lastname,
|
||||
phoneNumber = phoneNumber,
|
||||
password = password,
|
||||
salt = salt,
|
||||
hashingType = defaultHashingType,
|
||||
permissionId = 1,
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
26
Setup/Setup.csproj
Normal file
26
Setup/Setup.csproj
Normal file
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../DAL/DAL.csproj"/>
|
||||
<ProjectReference Include="../API/API.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Filler\Grants.sql" />
|
||||
<Content Include="Filler\Grants.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Remove="Filler\Permissions.sql" />
|
||||
<Content Include="Filler\Permissions.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL", "DAL\DAL.csproj", "{E
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Setup", "Setup\Setup.csproj", "{B887051E-90C7-43BA-A08B-3958D570DCA7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -18,5 +20,9 @@ Global
|
||||
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B887051E-90C7-43BA-A08B-3958D570DCA7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
Loading…
x
Reference in New Issue
Block a user