< Summary - Estud

Information
Class: Estud.Back.Auth.Permissions.EstudPermissions
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Auth/Permissions/EstudPermissions.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 122
Uncovered lines: 0
Coverable lines: 122
Total lines: 168
Line coverage: 100%
Branch coverage
50%
Covered branches: 5
Total branches: 10
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()50%88100%
IsAllowedFor(...)50%22100%

File(s)

/home/runner/work/syki/syki/Back/Auth/Permissions/EstudPermissions.cs

#LineLine coverage
 1using System.Reflection;
 2
 3namespace Estud.Back.Auth.Permissions;
 4
 5public static class EstudPermissions
 6{
 7    // Identity
 28    public static readonly EstudPermission ManageRoles = new(
 29        PermissionGroup.Identity,
 210        000,
 211        "Gerenciar perfis de acesso.",
 212        "Criar, editar e deletar perfis de acesso.",
 213        [UserType.Manager]
 214    );
 215    public static readonly EstudPermission ManageSso = new(
 216        PermissionGroup.Identity,
 217        001,
 218        "Gerenciar SSO.",
 219        "Configurar Single Sign-On (SSO) para a instituição.",
 220        [UserType.Manager]
 221    );
 22
 23    // Users
 224    public static readonly EstudPermission ManageUsers = new(
 225        PermissionGroup.Users,
 226        100,
 227        "Gerenciar usuários.",
 228        "Criar, editar e deletar usuários.",
 229        [UserType.Manager]
 230    );
 31
 32    // Campi
 233    public static readonly EstudPermission ManageCampi = new(
 234        PermissionGroup.Campi,
 235        200,
 236        "Gerenciar campus.",
 237        "Criar e editar campus.",
 238        [UserType.Manager]
 239    );
 40
 41    // Disciplines
 242    public static readonly EstudPermission ManageDisciplines = new(
 243        PermissionGroup.Disciplines,
 244        300,
 245        "Gerenciar disciplinas.",
 246        "Criar e editar disciplinas.",
 247        [UserType.Manager]
 248    );
 49
 50    // Courses
 251    public static readonly EstudPermission ManageCourses = new(
 252        PermissionGroup.Courses,
 253        400,
 254        "Gerenciar cursos.",
 255        "Criar e editar cursos.",
 256        [UserType.Manager]
 257    );
 58
 59    // Teachers
 260    public static readonly EstudPermission ManageTeachers = new(
 261        PermissionGroup.Teachers,
 262        500,
 263        "Gerenciar professores.",
 264        "Criar e editar professores.",
 265        [UserType.Manager]
 266    );
 67
 68    // Students
 269    public static readonly EstudPermission ManageStudents = new(
 270        PermissionGroup.Students,
 271        600,
 272        "Gerenciar alunos.",
 273        "Criar e editar alunos.",
 274        [UserType.Manager]
 275    );
 76
 77    // Periods
 278    public static readonly EstudPermission ManagePeriods = new(
 279        PermissionGroup.Periods,
 280        700,
 281        "Gerenciar períodos acadêmicos.",
 282        "Criar e editar períodos acadêmicos.",
 283        [UserType.Manager]
 284    );
 85
 86    // CourseCurriculums
 287    public static readonly EstudPermission ManageCourseCurriculums = new(
 288        PermissionGroup.CourseCurriculums,
 289        800,
 290        "Gerenciar grades curriculares.",
 291        "Criar e editar grades curriculares.",
 292        [UserType.Manager]
 293    );
 94
 95    // CourseOfferings
 296    public static readonly EstudPermission ManageCourseOfferings = new(
 297        PermissionGroup.CourseOfferings,
 298        900,
 299        "Gerenciar ofertas de curso.",
 2100        "Criar e editar ofertas de curso.",
 2101        [UserType.Manager]
 2102    );
 103
 104    // Classes
 2105    public static readonly EstudPermission ManageClasses = new(
 2106        PermissionGroup.Classes,
 2107        1000,
 2108        "Gerenciar turmas.",
 2109        "Criar e editar turmas.",
 2110        [UserType.Manager]
 2111    );
 112
 113    // Webhooks
 2114    public static readonly EstudPermission ManageWebhooks = new(
 2115        PermissionGroup.Webhooks,
 2116        1100,
 2117        "Gerenciar webhooks.",
 2118        "Criar e visualizar inscrições de webhook.",
 2119        [UserType.Manager]
 2120    );
 121
 122    // Notifications
 2123    public static readonly EstudPermission ManageNotifications = new(
 2124        PermissionGroup.Notifications,
 2125        1200,
 2126        "Gerenciar notificações.",
 2127        "Criar e visualizar notificações.",
 2128        [UserType.Manager]
 2129    );
 130
 131    // Classrooms
 2132    public static readonly EstudPermission ManageClassrooms = new(
 2133        PermissionGroup.Classrooms,
 2134        1300,
 2135        "Gerenciar salas de aula.",
 2136        "Criar e editar salas de aula.",
 2137        [UserType.Manager]
 2138    );
 139
 2140    public static readonly List<PermissionGroup> Groups = [];
 2141    public static readonly List<EstudPermission> Permissions = [];
 2142    private static readonly Dictionary<int, EstudPermission> ById = [];
 143    static EstudPermissions()
 144    {
 2145        Groups = Enum.GetValues<PermissionGroup>().ToList();
 146
 2147        Permissions = typeof(EstudPermissions)
 2148            .GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
 34149            .Where(f => f.FieldType == typeof(EstudPermission))
 30150            .Select(f => (EstudPermission)f.GetValue(null)!)
 30151            .OrderBy(f => f.Group)
 30152                .ThenBy(f => f.Id)
 2153            .ToList();
 154
 32155        if (!Permissions.Select(x => x.Id).IsAllDistinct()) throw new Exception("Duplicated permission ids!");
 156
 32157        if (!Permissions.Select(x => x.Name).IsAllDistinct()) throw new Exception("Duplicated permission names!");
 158
 32159        if (Permissions.Any(x => x.AllowedTypes == null || x.AllowedTypes.Count == 0)) throw new Exception("All permissi
 160
 32161        ById = Permissions.ToDictionary(x => x.Id);
 2162    }
 163
 164    public static bool IsAllowedFor(int permissionId, UserType userType)
 165    {
 4166        return ById.TryGetValue(permissionId, out var p) && p.AllowedTypes.Contains(userType);
 167    }
 168}