| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Identity.Contracts; |
| | | 4 | | using Elsa.Identity.Permissions; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Identity.Endpoints.Users.Create; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// An endpoint that creates a new user. |
| | | 11 | | /// </summary> |
| | | 12 | | [PublicAPI] |
| | 5 | 13 | | internal class Create(IUserManager userManager, IRoleAuthorizationService roleAuthorizationService) : ElsaEndpoint<Reque |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public override void Configure() |
| | | 17 | | { |
| | 5 | 18 | | Post("/identity/users"); |
| | 5 | 19 | | RequirePermission(IdentityPermissions.Users, CoreVerbs.Create); |
| | 5 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 24 | | { |
| | 2 | 25 | | if (!await roleAuthorizationService.CanAssignRolesAsync(User, request.Roles, cancellationToken)) |
| | | 26 | | { |
| | 0 | 27 | | await Send.ForbiddenAsync(cancellationToken); |
| | 0 | 28 | | return; |
| | | 29 | | } |
| | | 30 | | |
| | 2 | 31 | | var result = await userManager.CreateUserAsync( |
| | 2 | 32 | | request.Name, |
| | 2 | 33 | | request.Password, |
| | 2 | 34 | | request.Roles, |
| | 2 | 35 | | cancellationToken); |
| | | 36 | | |
| | 2 | 37 | | await Send.OkAsync(Response.FromResult(result), cancellationToken); |
| | 2 | 38 | | } |
| | | 39 | | } |