@@ -2,12 +2,20 @@ import createError from 'http-errors';
2
2
import { ROLE } from '@/constants' ;
3
3
import { findQuestion , getMaxScore } from '@/repository/question' ;
4
4
import { getSubmissionById , getSubmissions , insertGrade , insertSubmission } from '@/repository/submission' ;
5
+ import { isFromAdmin } from '@/utils' ;
5
6
import { triggerScorekeeper as initiateTesting } from './github' ;
6
7
7
8
export const createSubmission = async ( { question : questionId , link } , user ) => {
8
9
const question = await findQuestion ( { _id : questionId } ) ;
9
10
if ( ! question ) throw new createError ( 422 , 'Invalid question ID' ) ;
10
11
if ( ! question . enabled ) throw new createError ( 400 , 'You cannot make a submission for a disabled question' ) ;
12
+
13
+ const checkUrl = `https://${ process . env . AZURE_SOLUTION_UPLOAD_STORAGE_ACCOUNT } .blob.core.windows.net/${
14
+ process . env . AZURE_STORAGE_CONTAINER
15
+ } /${ encodeURIComponent ( user . name ) } `;
16
+
17
+ if ( ! link . startsWith ( checkUrl ) ) throw new createError ( 422 , 'Invalid submission link' ) ;
18
+
11
19
const submission = await insertSubmission ( user . _id , questionId , link ) ;
12
20
initiateTesting (
13
21
user . name ,
@@ -21,7 +29,7 @@ export const createSubmission = async ({ question: questionId, link }, user) =>
21
29
} ;
22
30
23
31
export const viewSubmissions = ( query , user ) => {
24
- if ( user . role != ROLE . ADMIN ) {
32
+ if ( user . role != ROLE . ADMIN || ! isFromAdmin ( ) ) {
25
33
if ( ! query . filter ) query . filter = { } ;
26
34
query . filter . user = user . _id ;
27
35
}
0 commit comments