| | | 1 | | using Elsa.Common.Multitenancy; |
| | | 2 | | using Elsa.Secrets.Contracts; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Secrets.Repositories; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Applies the same ambient-tenant visibility and write rules used by EF Core persistence to the |
| | | 8 | | /// default secret repositories. |
| | | 9 | | /// </summary> |
| | | 10 | | internal static class SecretRepositoryTenant |
| | | 11 | | { |
| | | 12 | | public static string CurrentTenantId(ITenantAccessor? tenantAccessor) => |
| | 148 | 13 | | tenantAccessor?.TenantId ?? Tenant.DefaultTenantId; |
| | | 14 | | |
| | | 15 | | public static void Stamp(Secret secret, ITenantAccessor? tenantAccessor, bool tenancyEnabled) |
| | | 16 | | { |
| | 174 | 17 | | if (!tenancyEnabled || tenantAccessor is null || secret.TenantId == Tenant.AgnosticTenantId) |
| | 94 | 18 | | return; |
| | | 19 | | |
| | 80 | 20 | | secret.TenantId ??= tenantAccessor.TenantId; |
| | 80 | 21 | | } |
| | | 22 | | |
| | | 23 | | public static bool IsVisible(Secret secret, ITenantAccessor? tenantAccessor, bool tenancyEnabled) => |
| | 298 | 24 | | !tenancyEnabled || TenantVisibility.IsVisible(secret.TenantId, CurrentTenantId(tenantAccessor)); |
| | | 25 | | |
| | | 26 | | public static bool CanReplace(Secret existing, Secret incoming, ITenantAccessor? tenantAccessor, bool tenancyEnabled |
| | 35 | 27 | | !tenancyEnabled || TenantVisibility.CanReplaceOwnedRow(existing.TenantId, incoming.TenantId, CurrentTenantId(ten |
| | | 28 | | |
| | | 29 | | public static bool HasName(Secret secret, string name, ISecretNameValidator nameValidator) => |
| | 258 | 30 | | string.Equals(nameValidator.Normalize(secret.Name), nameValidator.Normalize(name), StringComparison.Ordinal); |
| | | 31 | | |
| | | 32 | | public static bool HasSameTenantName(Secret existing, Secret incoming, ISecretNameValidator nameValidator, bool tena |
| | 52 | 33 | | HasName(existing, incoming.Name, nameValidator) |
| | 52 | 34 | | && (!tenancyEnabled || string.Equals( |
| | 52 | 35 | | existing.TenantId ?? Tenant.DefaultTenantId, |
| | 52 | 36 | | incoming.TenantId ?? Tenant.DefaultTenantId, |
| | 52 | 37 | | StringComparison.Ordinal)); |
| | | 38 | | } |