using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace LCU.Library.Internal.IncentiveApiModels.Entities { public class Permission { public string Code { get; } public string Description { get; } private Permission(string code, string description) { Code = code; Description = description; } public static Permission LookupPermissionFromCode(string code) { var foundPermissions = GetAllPermissions().Where(x => x.Code == code).ToList(); if (foundPermissions.Count != 1) { throw new Exception($"{foundPermissions.Count} found using Code: {code}"); } return foundPermissions.FirstOrDefault(); } public static readonly Permission AccessTestEnvironments = new Permission("ACCESS_TEST_ENVIRONMENT", "User can access the test environments"); public static readonly Permission AssignAssociatesToDepartment = new Permission("ASSIGN_ASSOCIATES_TO_DEPARTMENT", "User can assign associates to additional departments"); public static readonly Permission AssignPermissionsToAssociates = new Permission("ASSIGN_PERMISSIONS_TO_ASSOCIATES", "User can add permissions to an associate's user role"); public static readonly Permission AssignRegionalManager = new Permission("ASSIGN_REGIONAL_MANAGER", "User can set the regional manager for a region"); public static readonly Permission CreateActivity = new Permission("CREATE_ACTIVITY", "User can create manual activity"); public static readonly Permission EligibleForReferrals = new Permission("ELIGIBLE_FOR_REFERRALS", "User is eligible for referrals"); public static readonly Permission GeneratePayoutFiles = new Permission("GENERATE_PAYOUT_FILES", "User can generate payout files for HR"); public static readonly Permission HaveSalesGoals = new Permission("HAVE_SALES_GOALS", "User can have sales goals"); public static readonly Permission ManageCommissions = new Permission("MANAGE_COMMISSIONS", "User can manage the commission table"); public static readonly Permission ManageDepartments = new Permission("MANAGE_DEPARTMENTS", "User can manage departments"); public static readonly Permission ManageDepartmentGoals = new Permission("MANAGE_DEPARTMENT_GOALS", "User can manage their department goals"); public static readonly Permission ManageEmployeeDetails = new Permission("MANAGE_EMPLOYEE_DETAILS", "User can manage employee details"); public static readonly Permission ManagePersonnelGoals = new Permission("MANAGE_PERSONNEL_GOALS", "User can manage personnel goals"); public static readonly Permission ManageRoleMappings = new Permission("MANAGE_ROLE_MAPPINGS", "User can manage the business to application role mappings"); public static readonly Permission SetActivityAcceptedDate = new Permission("SET_ACTIVITY_ACCEPTED_DATE", "User can set activity accepted date"); public static readonly Permission SetActivityToAcceptedFromManualReview = new Permission("SET_ACTIVITY_TO_ACCEPTED_FROM_MANUAL_REVIEW", "User can set activity to Accepted from ManualReview"); public static readonly Permission SetActivityToAcceptedFromPendingReferral = new Permission("SET_ACTIVITY_TO_ACCEPTED_FROM_PENDING_REFERRAL", "User can set activity to Accepted from PendingReferral"); public static readonly Permission SetActivityToAcceptedFromPendingTransfer = new Permission("SET_ACTIVITY_TO_ACCEPTED_FROM_PENDING_TRANSFER", "User can set activity to Accepted from PendingTransfer"); public static readonly Permission SetActivityToAcceptedFromRejected = new Permission("SET_ACTIVITY_TO_ACCEPTED_FROM_REJECTED", "User can set activity to Accepted from Rejected"); public static readonly Permission SetActivityToManualReviewFromAccepted = new Permission("SET_ACTIVITY_TO_MANUAL_REVIEW_FROM_ACCEPTED", "User can set activity to ManualReview from Accepted"); public static readonly Permission SetActivityToManualReviewFromRejected = new Permission("SET_ACTIVITY_TO_MANUAL_REVIEW_FROM_REJECTED", "User can set activity to ManualReview from Rejected"); public static readonly Permission SetActivityToPendingReferralFromAccepted = new Permission("SET_ACTIVITY_TO_PENDING_REFERRAL_FROM_ACCEPTED", "User can set activity to PendingReferral from Accepted"); public static readonly Permission SetActivityToPendingReferralFromRejected = new Permission("SET_ACTIVITY_TO_PENDING_REFERRAL_FROM_REJECTED", "User can set activity to PendingReferral from Rejected"); public static readonly Permission SetActivityToPendingTransferFromAccepted = new Permission("SET_ACTIVITY_TO_PENDING_TRANSFER_FROM_ACCEPTED", "User can set activity to PendingTransfer from Accepted"); public static readonly Permission SetActivityToRejectedFromAccepted = new Permission("SET_ACTIVITY_TO_REJECTED_FROM_ACCEPTED", "User can set activity to Rejected from Accepted"); public static readonly Permission SetActivityToRejectedFromManualReview = new Permission("SET_ACTIVITY_TO_REJECTED_FROM_MANUAL_REVIEW", "User can set activity to Rejected from ManualReview"); public static readonly Permission SetActivityToTransferredFromPendingTransfer = new Permission("SET_ACTIVITY_TO_TRANSFERRED_FROM_PENDING_TRANSFER", "User can set activity to Transferred from PendingTransfer"); public static readonly Permission TransferActivitiesBetweenAssociates = new Permission("TRANSFER_ACTIVITIES_BETWEEN_ASSOCIATES", "User can transfer activities between associates"); public static readonly Permission TransferActivitiesBetweenDepartments = new Permission("TRANSFER_ACTIVITIES_BETWEEN_DEPARTMENTS", "User can transfer activities between departments"); public static readonly Permission Unknown = new Permission("UNKNOWN", "A Permission Could Not Be Parsed By The System. Possibly Removed."); public static readonly Permission ViewActivityAudit = new Permission("VIEW_ACTIVITY_AUDIT", "User can view the activity audit page"); public static readonly Permission ViewActivityReport = new Permission("VIEW_ACTIVITY_REPORT", "User can view the activity report"); public static readonly Permission ViewAuditReport = new Permission("VIEW_AUDIT_REPORT", "User can view the audit report"); public static readonly Permission ViewAssociateRecordReport = new Permission("VIEW_ASSOCIATE_RECORD_REPORT", "User can view the associate record report"); public static readonly Permission ViewDashboard = new Permission("VIEW_DASHBOARD", "User can see a dashboard showing their referral totals and their sales totals compared to goal"); public static readonly Permission ViewDeadActivityQueue = new Permission("VIEW_DEAD_ACTIVITY_QUEUE", "User can see the dead activity queue"); public static readonly Permission ViewGoalProgressReport = new Permission("VIEW_GOAL_PROGRESS_REPORT", "User can view the goal progress report"); public static readonly Permission ViewPayoutReport = new Permission("VIEW_PAYOUT_REPORT", "User can view the payout report"); public static readonly Permission ViewPerformanceForBusinessLine = new Permission("VIEW_PERFORMANCE_FOR_BUSINESS_LINE", "User can see performance for their business line"); public static readonly Permission ViewPerformanceForDepartment = new Permission("VIEW_PERFORMANCE_FOR_DEPARTMENT", "User can see performance for their department"); public static readonly Permission ViewPerformanceForRegion = new Permission("VIEW_PERFORMANCE_FOR_REGION", "User can see performance for their region"); public static readonly Permission ViewReports = new Permission("VIEW_REPORTS", "User can access the reports landing page"); public static List GetAllPermissions(bool excludeUnknown = false) { var foundInstances = new List(); foreach (var field in typeof(Permission).GetFields(BindingFlags.Static | BindingFlags.Public)) { if (field.FieldType != typeof(Permission)) { continue; } if (field.GetValue(field.Name) is Permission instance) { foundInstances.Add(instance); } } return excludeUnknown ? foundInstances.Where(x => x.Code != Unknown.Code).ToList() : foundInstances; } /** Collection of permissions needed for minimal application access */ public static List BaselinePermissions() { return new List { ViewActivityAudit, ViewDashboard }; } public static List DepartmentManagerPermissions() { return new List { AssignAssociatesToDepartment, SetActivityToRejectedFromManualReview, TransferActivitiesBetweenAssociates, TransferActivitiesBetweenDepartments, ViewReports, ViewActivityReport, ViewGoalProgressReport, ViewPerformanceForDepartment } .Concat(TransferApprovalPermissions()) .Concat(TransferRejectionPermissions()) .Concat(TransferRequestPermissions()) .ToList(); } public static List TransferApprovalPermissions() { return new List { SetActivityToTransferredFromPendingTransfer }; } public static List TransferRejectionPermissions() { return new List { SetActivityToAcceptedFromPendingTransfer }; } public static List TransferRequestPermissions() { return new List { SetActivityToPendingTransferFromAccepted }; } } }