| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Authorization; |
| | | 3 | | using Elsa.Permissions; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Identity.Endpoints.Me.Permissions; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Returns the calling principal's effective grants, so a client can hide sections, disable actions and |
| | | 10 | | /// show read-only states from one call rather than probing endpoints. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <remarks> |
| | | 13 | | /// This is for rendering. The source of truth is always server-side: every protected endpoint |
| | | 14 | | /// re-evaluates independently, and this response is never an authorization decision. |
| | | 15 | | /// </remarks> |
| | | 16 | | [PublicAPI] |
| | 3 | 17 | | internal class Get(IPermissionDescriptorRegistry registry, IPermissionEvaluator evaluator) : ElsaEndpointWithoutRequest< |
| | | 18 | | { |
| | | 19 | | /// <inheritdoc /> |
| | | 20 | | public override void Configure() |
| | | 21 | | { |
| | 3 | 22 | | Get("/identity/me/permissions"); |
| | | 23 | | |
| | | 24 | | // Any authenticated principal may ask what it holds; no grant is required to see your own. |
| | 3 | 25 | | RequireAuthenticatedOnly(); |
| | 3 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | | 29 | | public override Task<Response> ExecuteAsync(CancellationToken cancellationToken) |
| | | 30 | | { |
| | 0 | 31 | | var grants = registry.List() |
| | 0 | 32 | | .Select(descriptor => new ResourceGrant( |
| | 0 | 33 | | descriptor.Resource, |
| | 0 | 34 | | descriptor.SupportedVerbs.Where(verb => evaluator.HasPermission(User, descriptor.Resource, verb)).ToArra |
| | 0 | 35 | | .ToArray(); |
| | | 36 | | |
| | 0 | 37 | | return Task.FromResult(new Response(grants)); |
| | | 38 | | } |
| | | 39 | | } |