@@ -33,6 +33,8 @@ import { PUBLIC_COURSE_BROWSER_ENABLED } from '../../util/config'
3333const adRouter = Router ( )
3434const noadRouter = Router ( )
3535
36+ const isProgrammeCode = ( code : string ) => / ^ \d { 3 } - [ M K ] \d { 3 , 4 } $ / . test ( code )
37+
3638// TODO figure out if the two bellow functions could be united
3739adRouter . get ( '/for-faculty/:code' , async ( req : AuthenticatedRequest , res : Response ) => {
3840 const { user } = req
@@ -41,6 +43,7 @@ adRouter.get('/for-faculty/:code', async (req: AuthenticatedRequest, res: Respon
4143 if ( ! code ) throw ApplicationError . BadRequest ( 'Missing code' )
4244
4345 const organisationAccess = await user . organisationAccess
46+
4447 if ( ! organisationAccess [ code ] ?. read ) throw ApplicationError . Forbidden ( )
4548
4649 const facultyOrganisation = await Organisation . findOne ( {
@@ -56,10 +59,7 @@ adRouter.get('/for-faculty/:code', async (req: AuthenticatedRequest, res: Respon
5659
5760 if ( ! facultyOrganisation ) throw ApplicationError . NotFound ( 'Organisation not found' )
5861
59- const childOrgCodes =
60- facultyOrganisation . childOrganisations
61- ?. filter ( child => organisationAccess [ child . code ] ?. read )
62- . map ( child => child . code ) || [ ]
62+ const childOrgCodes = facultyOrganisation . childOrganisations ?. map ( child => child . code ) . filter ( isProgrammeCode ) || [ ]
6363
6464 const allOrganisationCodes = [ code , ...childOrgCodes ]
6565
@@ -69,6 +69,7 @@ adRouter.get('/for-faculty/:code', async (req: AuthenticatedRequest, res: Respon
6969 startDate : startDate as string ,
7070 endDate : endDate as string ,
7171 user,
72+ skipAccessCheck : orgCode !== code ,
7273 } )
7374 )
7475
0 commit comments