up
Some checks failed
Build Test Deploy / build-test (push) Has been cancelled
Build Test Deploy / authority-container (push) Has been cancelled
Build Test Deploy / docs (push) Has been cancelled
Build Test Deploy / deploy (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Some checks failed
Build Test Deploy / build-test (push) Has been cancelled
Build Test Deploy / authority-container (push) Has been cancelled
Build Test Deploy / docs (push) Has been cancelled
Build Test Deploy / deploy (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
This commit is contained in:
34
inspiration/Ablera.Serdica.Authorization/GroupsUtilities.cs
Normal file
34
inspiration/Ablera.Serdica.Authorization/GroupsUtilities.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Ablera.Serdica.Authorization.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ablera.Serdica.Authorization;
|
||||
public class GroupsUtilities
|
||||
{
|
||||
private readonly string[] KnownRoles;
|
||||
|
||||
public GroupsUtilities(IOptions<RolesConfig> rolesOptions)
|
||||
{
|
||||
RolesConfig value = rolesOptions.Value;
|
||||
if (value == null)
|
||||
{
|
||||
KnownRoles = new string[0];
|
||||
return;
|
||||
}
|
||||
|
||||
KnownRoles = (from x in value.UserRoles.Concat(value.OperationsRoles).Concat(value.UnderwriterRoles).Concat(value.OrganizationAdminRoles)
|
||||
.Concat(value.SuperUserRoles)
|
||||
select x.ToUpper()).ToArray();
|
||||
}
|
||||
|
||||
public string[] GetGroupsByRole(string[] roles)
|
||||
{
|
||||
var source = KnownRoles.Intersect(roles);
|
||||
if (!source.Any())
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
return source.ToArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user