Added checks for existing permissions when creating, updating and deleting permissions.
This commit is contained in:
@ -31,6 +31,11 @@ namespace HermesSocketServer.Requests
|
||||
Allow = allow,
|
||||
};
|
||||
|
||||
if (channel.GroupPermissions.Get().Values.Any(p => p.GroupId == groupId && p.Path == path))
|
||||
{
|
||||
return Task.FromResult(RequestResult.Failed("Permission exists already."));
|
||||
}
|
||||
|
||||
bool result = channel.GroupPermissions.Set(id.ToString(), permission);
|
||||
if (result)
|
||||
{
|
||||
|
@ -18,11 +18,12 @@ namespace HermesSocketServer.Requests
|
||||
{
|
||||
var id = data["id"].ToString()!;
|
||||
|
||||
var permission = channel.GroupPermissions.Get(id);
|
||||
var result = channel.GroupPermissions.Remove(id);
|
||||
if (result)
|
||||
{
|
||||
_logger.Information($"Deleted a group permission by id [group permission id: {id}]");
|
||||
return Task.FromResult(RequestResult.Successful(null));
|
||||
return Task.FromResult(RequestResult.Successful(permission));
|
||||
}
|
||||
|
||||
_logger.Warning($"Group Permission Id does not exist [group permission id: {id}]");
|
||||
|
@ -31,6 +31,11 @@ namespace HermesSocketServer.Requests
|
||||
Allow = allow,
|
||||
};
|
||||
|
||||
if (!channel.GroupPermissions.Get().Values.Any(p => p.GroupId == groupId && p.Path == path))
|
||||
{
|
||||
return Task.FromResult(RequestResult.Failed("Permission does not exist."));
|
||||
}
|
||||
|
||||
bool result = channel.GroupPermissions.Modify(id.ToString(), permission);
|
||||
if (result)
|
||||
{
|
||||
|
Reference in New Issue
Block a user