| | | 1 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 2 | | using Elsa.ExternalAuthentication.Models; |
| | | 3 | | using Elsa.Identity.Contracts; |
| | | 4 | | using Elsa.Identity.Entities; |
| | | 5 | | using Elsa.Identity.Models; |
| | | 6 | | |
| | | 7 | | namespace Elsa.ExternalAuthentication.Services; |
| | | 8 | | |
| | | 9 | | /// <summary>Prevents deleting users that still own external identity links.</summary> |
| | 3 | 10 | | public sealed class ExternalAuthenticationUserDeletionDependencyContributor( |
| | 3 | 11 | | IExternalIdentityLinkManagementStore links) : IUserDeletionDependencyContributor |
| | | 12 | | { |
| | | 13 | | public const string SourceName = "external-authentication"; |
| | 2 | 14 | | public string Source => SourceName; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public async ValueTask<UserDeletionDependency?> InspectAsync(User user, CancellationToken cancellationToken = defaul |
| | | 18 | | { |
| | 5 | 19 | | var linksForUser = await links.FindAsync(new ExternalIdentityLinkFilter |
| | 5 | 20 | | { |
| | 5 | 21 | | TenantId = user.TenantId ?? string.Empty, |
| | 5 | 22 | | UserId = user.Id |
| | 5 | 23 | | }, cancellationToken); |
| | | 24 | | |
| | 5 | 25 | | return linksForUser.Items.Count == 0 |
| | 5 | 26 | | ? null |
| | 5 | 27 | | : new UserDeletionDependency(Source, "The user is referenced by one or more external identity links."); |
| | 5 | 28 | | } |
| | | 29 | | } |