Added checks for non-user foreign keys in stores. Load/Saving stores' order is now based on table dependencies. Added ability to use chat message when using redemption.
This commit is contained in:
@@ -7,14 +7,16 @@ namespace HermesSocketServer.Store
|
||||
public class GroupPermissionStore : AutoSavedStore<string, GroupPermission>
|
||||
{
|
||||
private readonly string _userId;
|
||||
private readonly IStore<string, Group> _groups;
|
||||
private readonly Database _database;
|
||||
private readonly Serilog.ILogger _logger;
|
||||
|
||||
|
||||
public GroupPermissionStore(string userId, DatabaseTable table, Database database, Serilog.ILogger logger)
|
||||
public GroupPermissionStore(string userId, DatabaseTable table, IStore<string, Group> groups, Database database, Serilog.ILogger logger)
|
||||
: base(table, database, logger)
|
||||
{
|
||||
_userId = userId;
|
||||
_groups = groups;
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -30,7 +32,7 @@ namespace HermesSocketServer.Store
|
||||
{
|
||||
Id = id,
|
||||
UserId = _userId,
|
||||
GroupId = reader.GetGuid(1).ToString(),
|
||||
GroupId = reader.GetGuid(1),
|
||||
Path = reader.GetString(2),
|
||||
Allow = await reader.IsDBNullAsync(3) ? null : reader.GetBoolean(3),
|
||||
});
|
||||
@@ -43,15 +45,18 @@ namespace HermesSocketServer.Store
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(key, nameof(key));
|
||||
ArgumentNullException.ThrowIfNull(value, nameof(value));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(value.UserId, nameof(value.UserId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(value.GroupId, nameof(value.GroupId));
|
||||
ArgumentNullException.ThrowIfNull(value.GroupId, nameof(value.GroupId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(value.Path, nameof(value.Path));
|
||||
|
||||
if (_groups.Get(value.GroupId.ToString()) == null)
|
||||
throw new ArgumentException("The group id does not exist.");
|
||||
}
|
||||
|
||||
protected override void OnInitialModify(string key, GroupPermission oldValue, GroupPermission newValue)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newValue, nameof(newValue));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(newValue.UserId, nameof(newValue.UserId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(newValue.GroupId, nameof(newValue.GroupId));
|
||||
ArgumentNullException.ThrowIfNull(newValue.GroupId, nameof(newValue.GroupId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(newValue.Path, nameof(newValue.Path));
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.UserId, newValue.UserId, nameof(oldValue.UserId));
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.GroupId, newValue.GroupId, nameof(oldValue.GroupId));
|
||||
|
||||
Reference in New Issue
Block a user