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 @@
+diff --git a/zesje/api/feedback.py b/zesje/api/feedback.py
+index 0ed472b..686afb5 100644
+--- a/zesje/api/feedback.py
++++ b/zesje/api/feedback.py
+@@ -140,14 +140,11 @@ class Feedback(Resource):
+         db.session.commit()
+ 
+         # Delete mc_options associated with this feedback option
+-        if fb.mc_option:
++        if fb.mc_option and fb.problem.exam.finalized:
++            return dict(status=401, message='Cannot delete feedback option'
++                                            + ' attached to a multiple choice option in a finalized exam.'), 401
+ 
+-            # Check if the exam with this feedback option
+-            if fb.problem.exam.finalized:
+-                return dict(status=401, message='Cannot delete feedback option'
+-                                                + ' attached to a multiple choice option in a finalized exam.'), 401
+-
+-            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
-- 
GitLab