@@ -101,8 +101,8 @@ def set_total_marks(questions: list) -> int:
101101
102102
103103@frappe .whitelist ()
104- def submit_quiz (quiz : str , results : str ):
105- results = results and json .loads (results )
104+ def submit_quiz (quiz : str , results : str | None = None ):
105+ results = json .loads (results ) if results else []
106106 percentage = 0
107107
108108 quiz_details = frappe .db .get_value (
@@ -275,7 +275,19 @@ def save_progress_after_quiz(quiz_details: dict, percentage: float):
275275
276276
277277@frappe .whitelist ()
278- def check_answer (question : str , question_type : str , answers : str ):
278+ def check_answer (quiz : str , question : str , question_type : str , answers : str ):
279+ ADMIN_ROLES = ("System Manager" , "Moderator" , "Course Creator" , "Batch Evaluator" )
280+ is_admin = any (role in ADMIN_ROLES for role in frappe .get_roles ())
281+
282+ if not frappe .db .exists ("LMS Quiz Question" , {"parent" : quiz , "question" : question }):
283+ frappe .throw (_ ("Question not found in this quiz." ), frappe .PermissionError )
284+
285+ if not is_admin and not frappe .db .get_value ("LMS Quiz" , quiz , "show_answers" ):
286+ frappe .throw (
287+ _ ("Live answer checking is not enabled for this quiz." ),
288+ frappe .PermissionError ,
289+ )
290+
279291 answers = answers and json .loads (answers )
280292 if question_type == "Choices" :
281293 return check_choice_answers (question , answers )
0 commit comments