From be410a0fff4718f33b51a71441114f2d3042b58e Mon Sep 17 00:00:00 2001 From: Muhammad Mustapha Date: Mon, 29 Jun 2026 22:10:41 +0100 Subject: [PATCH] Enforce Strict Type-Safety in Authorization Module --- src/lib/auth/acl.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/auth/acl.ts b/src/lib/auth/acl.ts index 02968ea2..a217612a 100644 --- a/src/lib/auth/acl.ts +++ b/src/lib/auth/acl.ts @@ -1,11 +1,9 @@ -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck import { User, UserRole, Permission } from '@/types/api'; /** * Mapping of roles to their granted permissions. */ -export const ROLES_PERMISSIONS = { +export const ROLES_PERMISSIONS: Record = { ADMIN: Object.values(Permission), INSTRUCTOR: [ Permission.COURSE_VIEW, @@ -19,7 +17,7 @@ export const ROLES_PERMISSIONS = { ], STUDENT: [Permission.COURSE_VIEW, Permission.COURSE_DOWNLOAD, Permission.CONTENT_ACCESS], GUEST: [Permission.COURSE_VIEW], -} satisfies Record; +}; /** * Check if a user has a specific permission based on their role. @@ -27,7 +25,7 @@ export const ROLES_PERMISSIONS = { export function hasPermission(user: User | null | undefined, permission: Permission): boolean { if (!user) return false; - const permissions = ROLES_PERMISSIONS[user.role] || []; + const permissions = ROLES_PERMISSIONS[user.role] ?? []; return permissions.includes(permission); }