@@ -1812,9 +1812,9 @@ export class SubmissionService {
18121812 : undefined ;
18131813
18141814 if ( requestedMemberId ) {
1815- const userId = authUser . userId ? String ( authUser . userId ) : undefined ;
1815+ const userId = authUser ? .userId ? String ( authUser . userId ) : undefined ;
18161816 const isRequestingMember = userId === requestedMemberId ;
1817- const hasCopilotRole = ( authUser . roles ?? [ ] ) . includes (
1817+ const hasCopilotRole = ( authUser ? .roles ?? [ ] ) . includes (
18181818 UserRole . Copilot ,
18191819 ) ;
18201820 const hasElevatedAccess = isAdmin ( authUser ) || hasCopilotRole ;
@@ -1862,7 +1862,7 @@ export class SubmissionService {
18621862 : '' ;
18631863
18641864 let restrictedChallengeIds = new Set < string > ( ) ;
1865- if ( ! isPrivilegedRequester && requesterUserId ) {
1865+ if ( ! isPrivilegedRequester && requesterUserId && ! queryDto . challengeId ) {
18661866 try {
18671867 restrictedChallengeIds =
18681868 await this . getActiveSubmitterRestrictedChallengeIds (
@@ -1885,7 +1885,8 @@ export class SubmissionService {
18851885 if (
18861886 ! isPrivilegedRequester &&
18871887 requesterUserId &&
1888- restrictedChallengeIds . size
1888+ restrictedChallengeIds . size &&
1889+ ! queryDto . challengeId
18891890 ) {
18901891 const restrictedList = Array . from ( restrictedChallengeIds ) ;
18911892 const restrictionCriteria : Prisma . submissionWhereInput = {
@@ -1928,12 +1929,16 @@ export class SubmissionService {
19281929 orderBy,
19291930 } ) ;
19301931
1931- // Enrich with submitter handle and max rating for authorized callers
1932- const canViewSubmitter = await this . canViewSubmitterIdentity (
1933- authUser ,
1934- queryDto . challengeId ,
1935- ) ;
1936- if ( canViewSubmitter && submissions . length ) {
1932+ // Enrich with submitter handle and max rating (always for challenge listings)
1933+ const shouldEnrichSubmitter =
1934+ submissions . length > 0 &&
1935+ ( queryDto . challengeId
1936+ ? true
1937+ : await this . canViewSubmitterIdentity (
1938+ authUser ,
1939+ queryDto . challengeId ,
1940+ ) ) ;
1941+ if ( shouldEnrichSubmitter ) {
19371942 try {
19381943 const memberIds = Array . from (
19391944 new Set (
@@ -1943,11 +1948,24 @@ export class SubmissionService {
19431948 ) ,
19441949 ) ;
19451950 if ( memberIds . length ) {
1946- const idsAsBigInt = memberIds . map ( ( id ) => BigInt ( id ) ) ;
1947- const members = await this . memberPrisma . member . findMany ( {
1948- where : { userId : { in : idsAsBigInt } } ,
1949- include : { maxRating : true } ,
1950- } ) ;
1951+ const idsAsBigInt : bigint [ ] = [ ] ;
1952+ for ( const id of memberIds ) {
1953+ try {
1954+ idsAsBigInt . push ( BigInt ( id ) ) ;
1955+ } catch ( error ) {
1956+ this . logger . debug (
1957+ `[listSubmission] Skipping submitter ${ id } : unable to convert to BigInt. ${ error } ` ,
1958+ ) ;
1959+ }
1960+ }
1961+
1962+ const members =
1963+ idsAsBigInt . length > 0
1964+ ? await this . memberPrisma . member . findMany ( {
1965+ where : { userId : { in : idsAsBigInt } } ,
1966+ include : { maxRating : true } ,
1967+ } )
1968+ : [ ] ;
19511969 const map = new Map <
19521970 string ,
19531971 { handle : string ; maxRating : number | null }
@@ -2001,11 +2019,6 @@ export class SubmissionService {
20012019 submissions ,
20022020 reviewVisibilityContext ,
20032021 ) ;
2004- this . stripSubmitterMemberIds (
2005- authUser ,
2006- submissions ,
2007- reviewVisibilityContext ,
2008- ) ;
20092022 await this . stripIsLatestForUnlimitedChallenges ( submissions ) ;
20102023
20112024 this . logger . log (
@@ -2408,25 +2421,43 @@ export class SubmissionService {
24082421 return emptyContext ;
24092422 }
24102423
2424+ const requesterUserId =
2425+ authUser ?. userId !== undefined && authUser ?. userId !== null
2426+ ? String ( authUser . userId ) . trim ( )
2427+ : '' ;
2428+
24112429 const isPrivilegedRequester = authUser ?. isMachine || isAdmin ( authUser ) ;
2430+ if ( ! isPrivilegedRequester && ! requesterUserId ) {
2431+ for ( const submission of submissions ) {
2432+ if ( Object . prototype . hasOwnProperty . call ( submission , 'review' ) ) {
2433+ delete ( submission as any ) . review ;
2434+ }
2435+ if (
2436+ Object . prototype . hasOwnProperty . call ( submission , 'reviewSummation' )
2437+ ) {
2438+ delete ( submission as any ) . reviewSummation ;
2439+ }
2440+ }
2441+ return {
2442+ ...emptyContext ,
2443+ requesterUserId,
2444+ } ;
2445+ }
2446+
24122447 if ( isPrivilegedRequester ) {
2413- const requesterUserId =
2414- authUser ?. userId !== undefined && authUser ?. userId !== null
2415- ? String ( authUser . userId ) . trim ( )
2416- : '' ;
24172448 return {
24182449 ...emptyContext ,
24192450 requesterUserId,
24202451 } ;
24212452 }
24222453
2423- const uid =
2424- authUser ?. userId !== undefined && authUser ?. userId !== null
2425- ? String ( authUser . userId ) . trim ( )
2426- : '' ;
2454+ const uid = requesterUserId ;
24272455
24282456 if ( ! uid ) {
2429- return emptyContext ;
2457+ return {
2458+ ...emptyContext ,
2459+ requesterUserId,
2460+ } ;
24302461 }
24312462
24322463 const challengeIds = Array . from (
@@ -3397,7 +3428,26 @@ export class SubmissionService {
33973428 }
33983429
33993430 const uid = visibilityContext . requesterUserId ;
3431+ this . logger . debug (
3432+ `[stripSubmitterSubmissionDetails] requesterUserId=${ uid ?? '<undefined>' } ` ,
3433+ ) ;
34003434 if ( ! uid ) {
3435+ this . logger . debug (
3436+ '[stripSubmitterSubmissionDetails] Anonymized requester; removing review metadata and URLs.' ,
3437+ ) ;
3438+ for ( const submission of submissions ) {
3439+ if ( Object . prototype . hasOwnProperty . call ( submission , 'review' ) ) {
3440+ delete ( submission as any ) . review ;
3441+ }
3442+ if (
3443+ Object . prototype . hasOwnProperty . call ( submission , 'reviewSummation' )
3444+ ) {
3445+ delete ( submission as any ) . reviewSummation ;
3446+ }
3447+ if ( Object . prototype . hasOwnProperty . call ( submission , 'url' ) ) {
3448+ ( submission as any ) . url = null ;
3449+ }
3450+ }
34013451 return ;
34023452 }
34033453
@@ -3472,6 +3522,19 @@ export class SubmissionService {
34723522
34733523 const uid = visibilityContext . requesterUserId ;
34743524 if ( ! uid ) {
3525+ for ( const submission of submissions ) {
3526+ if ( Object . prototype . hasOwnProperty . call ( submission , 'review' ) ) {
3527+ delete ( submission as any ) . review ;
3528+ }
3529+ if (
3530+ Object . prototype . hasOwnProperty . call ( submission , 'reviewSummation' )
3531+ ) {
3532+ delete ( submission as any ) . reviewSummation ;
3533+ }
3534+ if ( Object . prototype . hasOwnProperty . call ( submission , 'url' ) ) {
3535+ ( submission as any ) . url = null ;
3536+ }
3537+ }
34753538 return ;
34763539 }
34773540
0 commit comments