@@ -2333,7 +2333,7 @@ export async function getCourseRunningLiveQuizzes(
23332333}
23342334
23352335export async function getLiveQuizLeaderboard (
2336- { quizId } : { quizId : string } ,
2336+ { quizId, hmac } : { quizId : string ; hmac ?: string | null } ,
23372337 ctx : Context
23382338) {
23392339 const quiz = await ctx . prisma . liveQuiz . findUnique ( {
@@ -2363,12 +2363,24 @@ export async function getLiveQuizLeaderboard(
23632363 } )
23642364 : null
23652365
2366- const participantProfilePublic =
2366+ let participantProfilesVisible =
23672367 ( participant ?. isProfilePublic ?? false ) ||
23682368 ctx . user ?. role === DB . UserRole . TEMPORARY_PARTICIPANT ||
23692369 ctx . user ?. role === DB . UserRole . USER ||
23702370 ctx . user ?. role === DB . UserRole . ADMIN
23712371
2372+ // if a valid hmac is passed, the participant profile is also visible
2373+ if ( typeof hmac === 'string' && hmac !== null && hmac !== '' ) {
2374+ const hmacEncoder = createHmac ( 'sha256' , process . env . APP_SECRET as string )
2375+ hmacEncoder . update ( quiz . namespace + quiz . id )
2376+ const quizHmac = hmacEncoder . digest ( 'hex' )
2377+
2378+ // evaluate whether the hashed quiz.namespace and quiz.id equals the hmac
2379+ if ( quizHmac === hmac ) {
2380+ participantProfilesVisible = true
2381+ }
2382+ }
2383+
23722384 // find the order attribute of the last exectued block
23732385 const executedBlockOrders = quiz ?. blocks
23742386 . filter ( ( quizBlock ) => quizBlock . status === DB . ElementBlockStatus . EXECUTED )
@@ -2388,11 +2400,11 @@ export async function getLiveQuizLeaderboard(
23882400 id : entry . id ,
23892401 participantId : entry . participant . id ,
23902402 username :
2391- entry . participant . isProfilePublic && participantProfilePublic
2403+ entry . participant . isProfilePublic && participantProfilesVisible
23922404 ? entry . participant . username
23932405 : 'Anonymous' ,
23942406 avatar :
2395- entry . participant . isProfilePublic && participantProfilePublic
2407+ entry . participant . isProfilePublic && participantProfilesVisible
23962408 ? entry . participant . avatar
23972409 : null ,
23982410 score : entry . score ,
@@ -2407,8 +2419,8 @@ export async function getLiveQuizLeaderboard(
24072419 return {
24082420 id : Math . floor ( Math . random ( ) * 1000000000 ) , // generate a random large number for temporary leaderboard entries
24092421 participantId : entry . id ,
2410- username : participantProfilePublic ? entry . username : 'Anonymous' ,
2411- avatar : participantProfilePublic ? entry . avatar : null ,
2422+ username : participantProfilesVisible ? entry . username : 'Anonymous' ,
2423+ avatar : participantProfilesVisible ? entry . avatar : null ,
24122424 score : entry . score ,
24132425 level : 1 , // temporary leaderboard entries do not have a experience points
24142426 // isSelf: entry.id === ctx.user.sub,
0 commit comments