| | | 1 | | using System.Reflection; |
| | | 2 | | |
| | | 3 | | namespace Syki.Shared.Auth; |
| | | 4 | | |
| | | 5 | | public static class FeaturesStore |
| | | 6 | | { |
| | 2 | 7 | | public static readonly SykiFeature ViewUsers = new(0, 0, "Ver usuários."); |
| | 2 | 8 | | public static readonly SykiFeature CreateUser = new(0, 1, "Criar usuário."); |
| | 2 | 9 | | public static readonly SykiFeature ViewRoles = new(0, 2, "Ver roles."); |
| | 2 | 10 | | public static readonly SykiFeature CreateRole = new(0, 3, "Criar role."); |
| | 2 | 11 | | public static readonly SykiFeature UpdateRole = new(0, 4, "Editar role."); |
| | 2 | 12 | | public static readonly SykiFeature ViewFeatures = new(0, 5, "Ver features."); |
| | 2 | 13 | | public static readonly SykiFeature ViewPolicies = new(0, 6, "Ver policies."); |
| | 2 | 14 | | public static readonly SykiFeature ViewAuditTrails = new(0, 7, "Ver audit trails."); |
| | 2 | 15 | | public static readonly SykiFeature ViewAuditTrailDetails = new(0, 8, "Ver detalhes de um audit trail."); |
| | | 16 | | |
| | 2 | 17 | | public static readonly SykiFeature ViewDomainEvents = new(1, 9, "Ver eventos de domínio."); |
| | 2 | 18 | | public static readonly SykiFeature ViewDomainEventDetails = new(1, 10, "Ver detalhes de um evento de domínio."); |
| | 2 | 19 | | public static readonly SykiFeature ViewCommands = new(1, 11, "Ver comandos."); |
| | 2 | 20 | | public static readonly SykiFeature ViewCommandDetails = new(1, 12, "Ver detalhes de um comando."); |
| | 2 | 21 | | public static readonly SykiFeature ReprocessCommand = new(1, 13, "Reprocessar um comando."); |
| | 2 | 22 | | public static readonly SykiFeature ViewCommandBatches = new(1, 14, "Ver lotes de comandos."); |
| | 2 | 23 | | public static readonly SykiFeature ViewCommandBatchDetails = new(1, 15, "Ver detalhes de um lote de comandos."); |
| | | 24 | | |
| | 2 | 25 | | public static readonly SykiFeature ViewInstitutions = new(2, 16, "Ver instituições de ensino."); |
| | 2 | 26 | | public static readonly SykiFeature CreateInstitution = new(2, 17, "Criar instituição de ensino."); |
| | 2 | 27 | | public static readonly SykiFeature ViewInstitutionDetails = new(2, 18, "Ver detalhes de uma instituição de ensino.") |
| | | 28 | | |
| | 2 | 29 | | public static readonly List<FeatureGroup> Groups = []; |
| | 2 | 30 | | public static readonly List<SykiFeature> Features = []; |
| | | 31 | | static FeaturesStore() |
| | | 32 | | { |
| | 2 | 33 | | Groups = |
| | 2 | 34 | | [ |
| | 2 | 35 | | new(0, "Users"), |
| | 2 | 36 | | new(1, "Daemon"), |
| | 2 | 37 | | new(2, "Instituições"), |
| | 2 | 38 | | ]; |
| | | 39 | | |
| | 2 | 40 | | Features = typeof(FeaturesStore) |
| | 2 | 41 | | .GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) |
| | 42 | 42 | | .Where(f => f.FieldType == typeof(SykiFeature)) |
| | 38 | 43 | | .Select(f => (SykiFeature)f.GetValue(null)!) |
| | 38 | 44 | | .OrderBy(f => f.GroupId) |
| | 38 | 45 | | .ThenBy(f => f.Id) |
| | 2 | 46 | | .ToList(); |
| | | 47 | | |
| | 104 | 48 | | if (Features.Any(x => Groups.FirstOrDefault(g => g.Id == x.GroupId) == null)) throw new Exception("Invalid group |
| | | 49 | | |
| | 40 | 50 | | if (!Features.Select(x => x.Id).IsAllDistinct()) throw new Exception("Duplicated feature ids!"); |
| | | 51 | | |
| | 40 | 52 | | if (!Features.Select(x => x.Name).IsAllDistinct()) throw new Exception("Duplicated feature names!"); |
| | | 53 | | |
| | 40 | 54 | | if (Features.Count - 1 != Features.OrderByDescending(x => x.Id).First().Id) throw new Exception("Wrong ids!"); |
| | 2 | 55 | | } |
| | | 56 | | } |