From 2749162746d5f4a4d3eb4a9497f964686979bed6 Mon Sep 17 00:00:00 2001 From: Ruben Young On <r.d.youngon@student.tudelft.nl> Date: Sun, 19 May 2019 14:50:01 +0200 Subject: [PATCH] Fixed location where error is thrown if exam is finalized --- zesje/api/feedback.py | 7 +++---- "\357\200\272q" | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 "\357\200\272q" diff --git a/zesje/api/feedback.py b/zesje/api/feedback.py index 630ac52a..dbb144dd 100644 --- a/zesje/api/feedback.py +++ b/zesje/api/feedback.py @@ -125,7 +125,7 @@ class Feedback(Resource): problem = fb.problem if problem.id != problem_id: return dict(status=409, message="Feedback does not match the problem."), 409 - if problem.exam.finalized: + if fb.mc_option and problem.exam.finalized: return dict(status=401, message='Cannot delete feedback option' + ' attached to a multiple choice option in a finalized exam.'), 401 @@ -143,8 +143,7 @@ class Feedback(Resource): db.session.commit() # Delete mc_options associated with this feedback option - if fb.mc_option: - db.session.delete(fb.mc_option) - db.session.commit() + db.session.delete(fb.mc_option) + db.session.commit() return dict(status=200, message=f"Feedback option with id {feedback_id} deleted."), 200 diff --git "a/\357\200\272q" "b/\357\200\272q" new file mode 100644 index 00000000..857f1b12 --- /dev/null +++ "b/\357\200\272q" @@ -0,0 +1,24 @@ +[1mdiff --git a/zesje/api/feedback.py b/zesje/api/feedback.py[m +[1mindex 0ed472b..686afb5 100644[m +[1m--- a/zesje/api/feedback.py[m +[1m+++ b/zesje/api/feedback.py[m +[36m@@ -140,14 +140,11 @@[m [mclass Feedback(Resource):[m + db.session.commit()[m + [m + # Delete mc_options associated with this feedback option[m +[31m- if fb.mc_option:[m +[32m+[m[32m if fb.mc_option and fb.problem.exam.finalized:[m +[32m+[m[32m return dict(status=401, message='Cannot delete feedback option'[m +[32m+[m[32m + ' attached to a multiple choice option in a finalized exam.'), 401[m + [m +[31m- # Check if the exam with this feedback option[m +[31m- if fb.problem.exam.finalized:[m +[31m- return dict(status=401, message='Cannot delete feedback option'[m +[31m- + ' attached to a multiple choice option in a finalized exam.'), 401[m +[31m-[m +[31m- db.session.delete(fb.mc_option)[m +[31m- db.session.commit()[m +[32m+[m[32m db.session.delete(fb.mc_option)[m +[32m+[m[32m db.session.commit()[m + [m + return dict(status=200, message=f"Feedback option with id {feedback_id} deleted."), 200[m -- GitLab