Added functions for getting grants.
This commit is contained in:
parent
18ab0b592f
commit
0cdc5ebb20
14
API/Authentication/GrantNames/ColorGrantNames.cs
Normal file
14
API/Authentication/GrantNames/ColorGrantNames.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace API.Authentication.GrantNames
|
||||||
|
{
|
||||||
|
public static class ColorGrantNames
|
||||||
|
{
|
||||||
|
public const string CanGetAll = "api.color.get.all";
|
||||||
|
public const string CanGetAny = "api.color.get.any";
|
||||||
|
public const string CanGet = "api.color.get";
|
||||||
|
public const string CanAdd = "api.color.add";
|
||||||
|
public const string CanUpdateAny = "api.color.update.any";
|
||||||
|
public const string CanUpdate = "api.color.update";
|
||||||
|
public const string CanDeleteAny = "api.color.delete.any";
|
||||||
|
public const string CanDelete = "api.color.delete";
|
||||||
|
}
|
||||||
|
}
|
@ -11,5 +11,66 @@ namespace API.Services
|
|||||||
public GrantService(ILogger<GrantService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
|
public GrantService(ILogger<GrantService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool hasGrant(ulong permissionId, string grantName)
|
||||||
|
{
|
||||||
|
return getNoAuthentication(x => x.permissionId == permissionId && x.name.Equals(grantName)).Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> getValues(ulong permissionId, string grantName)
|
||||||
|
{
|
||||||
|
List<Grant> grants = getNoAuthentication(x => x.permissionId == permissionId && x.name.StartsWith(grantName + ".")).ToList();
|
||||||
|
|
||||||
|
List<string> values = [];
|
||||||
|
foreach (Grant grant in grants)
|
||||||
|
{
|
||||||
|
string value = grant.name.Substring(grantName.Length);
|
||||||
|
if (value.Contains('.'))
|
||||||
|
// Were not looking at a value and instead another grant
|
||||||
|
continue;
|
||||||
|
|
||||||
|
values.Add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> getStringValues(ulong permissionId, string grantName)
|
||||||
|
{
|
||||||
|
List<string> values = getValues(permissionId, grantName);
|
||||||
|
|
||||||
|
// Get rid of numbers
|
||||||
|
values = values.Where(x => !Int32.TryParse(x, out int _)).ToList();
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<int> getIntValues(ulong permissionId, string grantName)
|
||||||
|
{
|
||||||
|
List<string> values = getValues(permissionId, grantName);
|
||||||
|
List<int> intValues = [];
|
||||||
|
|
||||||
|
Parallel.ForEach(values, x =>
|
||||||
|
{
|
||||||
|
if (Int32.TryParse(x, out int parsed))
|
||||||
|
intValues.Add(parsed);
|
||||||
|
});
|
||||||
|
|
||||||
|
return intValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ulong> getULongValues(ulong permissionId, string grantName)
|
||||||
|
{
|
||||||
|
List<string> values = getValues(permissionId, grantName);
|
||||||
|
List<ulong> uLongValues = [];
|
||||||
|
|
||||||
|
Parallel.ForEach(values, x =>
|
||||||
|
{
|
||||||
|
if (UInt64.TryParse(x, out ulong parsed))
|
||||||
|
uLongValues.Add(parsed);
|
||||||
|
});
|
||||||
|
|
||||||
|
return uLongValues;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user