Added checks for existing permissions when creating, updating and deleting permissions.

This commit is contained in:
Tom
2025-03-29 20:11:12 +00:00
parent 07cb396dd7
commit c80f1f2aa0
3 changed files with 12 additions and 1 deletions

View File

@ -31,6 +31,11 @@ namespace HermesSocketServer.Requests
Allow = allow, 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); bool result = channel.GroupPermissions.Set(id.ToString(), permission);
if (result) if (result)
{ {

View File

@ -18,11 +18,12 @@ namespace HermesSocketServer.Requests
{ {
var id = data["id"].ToString()!; var id = data["id"].ToString()!;
var permission = channel.GroupPermissions.Get(id);
var result = channel.GroupPermissions.Remove(id); var result = channel.GroupPermissions.Remove(id);
if (result) if (result)
{ {
_logger.Information($"Deleted a group permission by id [group permission id: {id}]"); _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}]"); _logger.Warning($"Group Permission Id does not exist [group permission id: {id}]");

View File

@ -31,6 +31,11 @@ namespace HermesSocketServer.Requests
Allow = allow, 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); bool result = channel.GroupPermissions.Modify(id.ToString(), permission);
if (result) if (result)
{ {