elsa-core/src/modules/Elsa.Identity/Services/RoleManager.cs
Sipke Schoorstra 1b09538a13
Introduce role and user management services (#7297)
* Introduce role and user management services

- Add `CreateRoleResult` and `CreateUserResult` models for managing creation results.
- Implement `IRoleManager` and `IUserManager` interfaces and their service classes.
- Configure dependency injection for role and user managers.
- Refactor endpoints to use new manager interfaces.

* Remove IRoleStore dependency from Create endpoint
2026-02-15 18:50:11 +01:00

41 lines
964 B
C#

using Elsa.Identity.Contracts;
using Elsa.Identity.Entities;
using Elsa.Identity.Models;
using Humanizer;
namespace Elsa.Identity.Services;
/// <summary>
/// Default implementation of <see cref="IRoleManager"/>.
/// </summary>
public class RoleManager : IRoleManager
{
private readonly IRoleStore _roleStore;
public RoleManager(IRoleStore roleStore)
{
_roleStore = roleStore;
}
/// <inheritdoc />
public async Task<CreateRoleResult> CreateRoleAsync(
string name,
ICollection<string>? permissions = null,
string? id = null,
CancellationToken cancellationToken = default)
{
var roleId = id ?? name.Kebaberize();
var role = new Role
{
Id = roleId,
Name = name,
Permissions = permissions ?? new List<string>()
};
await _roleStore.SaveAsync(role, cancellationToken);
return new CreateRoleResult(role);
}
}