feat: Enhance security by adding @login_required to multiple views and replacing print statements with logger.debug

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Ross
2026-04-30 21:35:08 +01:00
co-authored by Copilot
parent 5d37cad48d
commit 2aff9516ac
13 changed files with 389 additions and 113 deletions
+30 -24
View File
@@ -778,36 +778,42 @@ def feedback_mark_complete(request, pk):
return redirect(q.get_object_url())
@csrf_exempt
@login_required
def answer_suggestion_submit(request):
if request.method == "POST":
post_data = json.loads(request.body)
question_type, qid = post_data["qid"].split("/")
answer_string = post_data["answer"]
status = post_data["status"]
"""Submit a proposed answer to a question for review.
if str(status) not in " 012":
return JsonResponse({"success": False, "error": "Invalid status"})
Scope: authenticated users only.
Functionality: accepts a JSON POST containing the question ID, proposed answer
string, and status; creates a new Answer record marked as proposed=True for
moderator review. Only 'anatomy' and 'rapid' question types are supported.
"""
if request.method != "POST":
return JsonResponse({"success": False, "error": "Invalid data"})
if question_type == "anatomy":
AnswerModel = AnatomyAnswer
question = AnatomyQuestion
elif question_type == "rapid":
AnswerModel = RapidAnswer
question = Rapid
else:
return JsonResponse({"success": False, "error": "Invalid question type"})
post_data = json.loads(request.body)
question_type, qid = post_data["qid"].split("/")
answer_string = post_data["answer"]
status = post_data["status"]
q = get_object_or_404(question, pk=qid)
if AnswerModel.objects.filter(answer=answer_string, question=q):
return JsonResponse({"success": False, "error": "Answer already exists"})
if str(status) not in " 012":
return JsonResponse({"success": False, "error": "Invalid status"})
a = AnswerModel(question=q, answer=answer_string, status=status, proposed=True)
a.save()
return JsonResponse({"success": True, "error": "Answer submited"})
if question_type == "anatomy":
AnswerModel = AnatomyAnswer
question = AnatomyQuestion
elif question_type == "rapid":
AnswerModel = RapidAnswer
question = Rapid
else:
return JsonResponse({"success": False, "error": "Invalid question type"})
# post_exam_answers
return JsonResponse({"success": False, "error": "Invalid data"})
q = get_object_or_404(question, pk=qid)
if AnswerModel.objects.filter(answer=answer_string, question=q):
return JsonResponse({"success": False, "error": "Answer already exists"})
a = AnswerModel(question=q, answer=answer_string, status=status, proposed=True)
a.save()
return JsonResponse({"success": True, "error": "Answer submitted"})
@login_required