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:
@ -18,7 +18,7 @@ namespace HermesSocketServer.Requests
|
||||
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||||
{
|
||||
var id = Guid.NewGuid();
|
||||
string groupId = data["group"].ToString()!;
|
||||
Guid groupId = new Guid(data["group"].ToString()!);
|
||||
string path = data["path"].ToString()!;
|
||||
bool? allow = bool.TryParse(data["allow"].ToString()!, out bool a) ? a : null;
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace HermesSocketServer.Requests
|
||||
public class CreateRedeemableAction : IRequest
|
||||
{
|
||||
public string Name => "create_redeemable_action";
|
||||
public string[] RequiredKeys => ["name", "data", "type"];
|
||||
public string[] RequiredKeys => ["name", "has_message", "type", "data"];
|
||||
private ILogger _logger;
|
||||
|
||||
public CreateRedeemableAction(ILogger logger)
|
||||
@ -19,8 +19,9 @@ namespace HermesSocketServer.Requests
|
||||
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||||
{
|
||||
string name = data["name"].ToString()!;
|
||||
string d = data["data"].ToString()!;
|
||||
string type = data["type"].ToString()!;
|
||||
bool hasMessage = data["has_message"].ToString()!.ToLower() == "true";
|
||||
string d = data["data"].ToString()!;
|
||||
IDictionary<string, string> dict = new Dictionary<string, string>();
|
||||
|
||||
try
|
||||
@ -29,7 +30,7 @@ namespace HermesSocketServer.Requests
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"Failed to parse data on redeemable action while creating action [name: {name}][type: {type}][data: {d}]");
|
||||
_logger.Error(ex, $"Failed to parse data on redeemable action while creating action [name: {name}][type: {type}][has message: {hasMessage}][data: {d}]");
|
||||
return Task.FromResult(RequestResult.Failed("Could not parse the data on this action."));
|
||||
}
|
||||
|
||||
@ -37,14 +38,15 @@ namespace HermesSocketServer.Requests
|
||||
{
|
||||
UserId = channel.Id,
|
||||
Name = name,
|
||||
Data = dict,
|
||||
Type = type,
|
||||
HasMessage = hasMessage,
|
||||
Data = dict,
|
||||
};
|
||||
|
||||
bool result = channel.Actions.Set(name, action);
|
||||
if (result)
|
||||
{
|
||||
_logger.Information($"Added redeemable action to channel [name: {name}][type: {type}][channel: {channel.Id}]");
|
||||
_logger.Information($"Added redeemable action to channel [name: {name}][type: {type}][has message: {hasMessage}][channel: {channel.Id}]");
|
||||
return Task.FromResult(RequestResult.Successful(action));
|
||||
}
|
||||
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
||||
|
@ -22,7 +22,7 @@ namespace HermesSocketServer.Requests
|
||||
if (result)
|
||||
{
|
||||
var permissions = channel.GroupPermissions.Get().Values
|
||||
.Where(p => p.GroupId == groupId);
|
||||
.Where(p => p.GroupId.ToString() == groupId);
|
||||
|
||||
Task? chattersSave = null;
|
||||
if (channel.Groups.Chatters.TryGetValue(groupId, out var chatters))
|
||||
@ -32,7 +32,7 @@ namespace HermesSocketServer.Requests
|
||||
{
|
||||
foreach (var chatter in filteredChatters)
|
||||
{
|
||||
var res = chatters.Remove(chatter.ChatterId.ToString());
|
||||
var res = chatters.Remove(chatter.ChatterId.ToString(), fromCascade: true);
|
||||
if (!res)
|
||||
_logger.Warning($"Failed to delete group chatter by id [group chatter id: {chatter.ChatterId}]");
|
||||
}
|
||||
@ -43,7 +43,7 @@ namespace HermesSocketServer.Requests
|
||||
|
||||
foreach (var permission in permissions)
|
||||
{
|
||||
var res = channel.GroupPermissions.Remove(permission.Id);
|
||||
var res = channel.GroupPermissions.Remove(permission.Id, fromCascade: true);
|
||||
if (!res)
|
||||
_logger.Warning($"Failed to delete group permission by id [group chatter id: {permission.Id}]");
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace HermesSocketServer.Requests
|
||||
public class DeleteGroupChatter : IRequest
|
||||
{
|
||||
public string Name => "delete_group_chatter";
|
||||
public string[] RequiredKeys => ["id", "group"];
|
||||
public string[] RequiredKeys => ["chatter", "group"];
|
||||
private ILogger _logger;
|
||||
|
||||
public DeleteGroupChatter(ILogger logger)
|
||||
@ -16,7 +16,7 @@ namespace HermesSocketServer.Requests
|
||||
|
||||
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||||
{
|
||||
var chatterId = data["id"].ToString()!;
|
||||
var chatterId = data["chatter"].ToString()!;
|
||||
var groupId = data["group"].ToString()!;
|
||||
|
||||
if (!channel.Groups.Chatters.TryGetValue(groupId, out var chatters))
|
||||
|
@ -30,8 +30,8 @@ namespace HermesSocketServer.Requests
|
||||
|
||||
private class GroupDetails
|
||||
{
|
||||
public required Group Group;
|
||||
public required IEnumerable<GroupChatter> Chatters;
|
||||
public required Group Group { get; set; }
|
||||
public required IEnumerable<GroupChatter> Chatters { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace HermesSocketServer.Requests
|
||||
var id = Guid.NewGuid();
|
||||
string groupId = data["group"].ToString()!;
|
||||
if (!int.TryParse(data["chatter"].ToString()!, out var chatterId))
|
||||
return Task.FromResult(RequestResult.Failed("Priority needs to be an integer."));
|
||||
return Task.FromResult(RequestResult.Failed("Chatter Id needs to be an integer."));
|
||||
string chatterLabel = data["label"].ToString()!;
|
||||
|
||||
var groupChatter = new GroupChatter()
|
||||
|
@ -18,7 +18,7 @@ namespace HermesSocketServer.Requests
|
||||
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||||
{
|
||||
var id = data["id"].ToString()!;
|
||||
string groupId = data["group"].ToString()!;
|
||||
Guid groupId = new Guid(data["group"].ToString()!);
|
||||
string path = data["path"].ToString()!;
|
||||
bool? allow = bool.TryParse(data["allow"].ToString()!, out bool a) ? a : null;
|
||||
|
||||
|
@ -19,8 +19,9 @@ namespace HermesSocketServer.Requests
|
||||
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||||
{
|
||||
string name = data["name"].ToString()!;
|
||||
string d = data["data"].ToString()!;
|
||||
string type = data["type"].ToString()!;
|
||||
bool hasMessage = data["has_message"].ToString()!.ToLower() == "true";
|
||||
string d = data["data"].ToString()!;
|
||||
IDictionary<string, string> dict = new Dictionary<string, string>();
|
||||
|
||||
try
|
||||
@ -29,7 +30,7 @@ namespace HermesSocketServer.Requests
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"Failed to parse data on redeemable action while updating action [name: {name}][type: {type}][data: {d}]");
|
||||
_logger.Error(ex, $"Failed to parse data on redeemable action while updating action [name: {name}][type: {type}][has message: {hasMessage}][data: {d}]");
|
||||
return Task.FromResult(RequestResult.Failed("Could not parse the data on this action."));
|
||||
}
|
||||
|
||||
@ -37,14 +38,15 @@ namespace HermesSocketServer.Requests
|
||||
{
|
||||
UserId = channel.Id,
|
||||
Name = name,
|
||||
Data = dict,
|
||||
Type = type,
|
||||
HasMessage = hasMessage,
|
||||
Data = dict,
|
||||
};
|
||||
|
||||
bool result = channel.Actions.Modify(name, action);
|
||||
if (result)
|
||||
{
|
||||
_logger.Information($"Updated redeemable action on channel [name: {name}][type: {type}][channel: {channel.Id}]");
|
||||
_logger.Information($"Updated redeemable action on channel [name: {name}][type: {type}][has message: {hasMessage}][channel: {channel.Id}]");
|
||||
return Task.FromResult(RequestResult.Successful(action));
|
||||
}
|
||||
if (channel.Actions.Get(name) == null)
|
||||
|
Reference in New Issue
Block a user