| | | 1 | | namespace Chronicis.Shared.Admin; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Evaluates system administrator status by checking a user's Auth0 ID or email |
| | | 5 | | /// against the configured <see cref="SysAdminOptions"/>. |
| | | 6 | | /// </summary> |
| | | 7 | | public class SysAdminChecker : ISysAdminChecker |
| | | 8 | | { |
| | | 9 | | private readonly HashSet<string> _auth0UserIds; |
| | | 10 | | private readonly HashSet<string> _emails; |
| | | 11 | | |
| | | 12 | | public SysAdminChecker(SysAdminOptions options) |
| | | 13 | | { |
| | 14 | 14 | | ArgumentNullException.ThrowIfNull(options); |
| | | 15 | | |
| | 13 | 16 | | _auth0UserIds = new HashSet<string>( |
| | 13 | 17 | | options.Auth0UserIds ?? [], |
| | 13 | 18 | | StringComparer.OrdinalIgnoreCase); |
| | | 19 | | |
| | 13 | 20 | | _emails = new HashSet<string>( |
| | 13 | 21 | | options.Emails ?? [], |
| | 13 | 22 | | StringComparer.OrdinalIgnoreCase); |
| | 13 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc/> |
| | | 26 | | public bool IsSysAdmin(string auth0UserId, string? email) |
| | | 27 | | { |
| | 13 | 28 | | if (!string.IsNullOrEmpty(auth0UserId) && _auth0UserIds.Contains(auth0UserId)) |
| | 3 | 29 | | return true; |
| | | 30 | | |
| | 10 | 31 | | if (!string.IsNullOrEmpty(email) && _emails.Contains(email)) |
| | 2 | 32 | | return true; |
| | | 33 | | |
| | 8 | 34 | | return false; |
| | | 35 | | } |
| | | 36 | | } |