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,
|
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)
|
||||||
{
|
{
|
||||||
|
@ -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}]");
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user