| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Identity.Contracts; |
| | | 4 | | using Elsa.Identity.Models; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.AspNetCore.Http; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Identity.Endpoints.Users.Delete; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// An endpoint that deletes a user by ID. |
| | | 12 | | /// </summary> |
| | | 13 | | [PublicAPI] |
| | 3 | 14 | | internal class Delete(IUserDeletionCoordinator coordinator) : ElsaEndpointWithoutRequest |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public override void Configure() |
| | | 18 | | { |
| | 3 | 19 | | Delete("/identity/users/{id}"); |
| | 3 | 20 | | RequirePermission(Elsa.Identity.Permissions.IdentityPermissions.Users, CoreVerbs.Delete); |
| | 3 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public override async Task HandleAsync(CancellationToken cancellationToken) |
| | | 25 | | { |
| | 0 | 26 | | var id = Route<string>("id")!; |
| | | 27 | | |
| | 0 | 28 | | var result = await coordinator.DeleteAsync(id, cancellationToken); |
| | | 29 | | switch (result) |
| | | 30 | | { |
| | | 31 | | case UserDeletionOperationResult.Deleted: |
| | 0 | 32 | | await Send.NoContentAsync(cancellationToken); |
| | 0 | 33 | | break; |
| | | 34 | | case UserDeletionOperationResult.NotFound: |
| | 0 | 35 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 36 | | break; |
| | | 37 | | case UserDeletionOperationResult.Blocked blocked: |
| | 0 | 38 | | HttpContext.Response.StatusCode = StatusCodes.Status409Conflict; |
| | 0 | 39 | | await HttpContext.Response.WriteAsJsonAsync( |
| | 0 | 40 | | new { error = "conflict", message = "The user is referenced by one or more installed modules.", depe |
| | 0 | 41 | | cancellationToken); |
| | 0 | 42 | | break; |
| | | 43 | | default: |
| | 0 | 44 | | throw new InvalidOperationException("Unknown user-deletion operation result."); |
| | | 45 | | } |
| | 0 | 46 | | } |
| | | 47 | | } |