Skip to content

Commit

Permalink
added isadmin check in isAuthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
RA341 committed Nov 10, 2024
1 parent b61aa14 commit 2476314
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions devU-api/src/authorization/authorization.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UserCourseService from '../entities/userCourse/userCourse.service'
import RoleService from '../entities/role/role.service'
import { serialize } from '../entities/role/role.serializer'
import { Role } from '../../devu-shared-modules'
import UserService from '../entities/user/user.service'

/**
* Are you authorized to access this endpoint?
Expand All @@ -23,6 +24,14 @@ export function isAuthorized(permission: string, permissionIfSelf?: string) {
return res.status(404).json(NotFound)
}

// check if admin
const user = await UserService.isAdmin(userId!)
if (user && user.isAdmin!) {
// no role checks needed
// user is admin !
return next()
}

// Pull userCourse
const userCourse = await UserCourseService.retrieveByCourseAndUser(courseId, userId)

Expand Down

0 comments on commit 2476314

Please sign in to comment.