Added policy messages for WS. Fixed DB changes via stores. Updated chat voices messages via WS to use stores.
This commit is contained in:
49
Requests/CreatePolicy.cs
Normal file
49
Requests/CreatePolicy.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using HermesSocketServer.Models;
|
||||
using HermesSocketServer.Services;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class CreatePolicy : IRequest
|
||||
{
|
||||
public string Name => "create_policy";
|
||||
public string[] RequiredKeys => ["groupId", "path", "count", "span"];
|
||||
private ChannelManager _channels;
|
||||
private ILogger _logger;
|
||||
|
||||
public CreatePolicy(ChannelManager channels, ILogger logger)
|
||||
{
|
||||
_channels = channels;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
var id = Guid.NewGuid();
|
||||
string groupId = data["groupId"].ToString()!;
|
||||
string path = data["path"].ToString()!;
|
||||
int count = int.Parse(data["count"].ToString()!);
|
||||
int span = int.Parse(data["span"].ToString()!);
|
||||
|
||||
var policy = new PolicyMessage()
|
||||
{
|
||||
Id = id,
|
||||
UserId = sender,
|
||||
GroupId = Guid.Parse(groupId),
|
||||
Path = path,
|
||||
Usage = count,
|
||||
Span = span,
|
||||
};
|
||||
|
||||
var channel = _channels.Get(sender);
|
||||
bool result = channel.Policies.Set(id.ToString(), policy);
|
||||
|
||||
if (result)
|
||||
{
|
||||
_logger.Information($"Added policy to channel [policy id: {id}][group id: {groupId}][path: {path}][count: {count}][span: {span}][channel: {sender}]");
|
||||
return RequestResult.Successful(policy);
|
||||
}
|
||||
return RequestResult.Failed("Something went wrong when updating the cache.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user