]> git.cworth.org Git - turbot/commitdiff
Reject puzzle edit if "solved" and "solution" are inconsistent
authorCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 06:19:29 +0000 (22:19 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 06:19:29 +0000 (22:19 -0800)
There's an argument here that we really shouldn't be giving the user
two different fields if we're forcing them to be edited together, but
that's what we have right now.

turbot/interaction.py

index 8ae4a53556d45542ec19dca22471e46b89f8f702..417066aba650324fd3ff0199311552f94bb16214 100644 (file)
@@ -197,6 +197,15 @@ def edit_puzzle_submission(turb, payload, metadata):
             sol.strip() for sol in solution.split(',')
         ]
 
+    # Verify that there's a solution if the puzzle is mark solved
+    if puzzle['status'] == 'solved' and not puzzle['solution']:
+        return submission_error("solution",
+                                "A solved puzzle requires a solution.")
+
+    if puzzle['status'] == 'unsolved' and puzzle['solution']:
+        return submission_error("solution",
+                                "An unsolved puzzle should have no solution.")
+
     # Add any new rounds to the database
     if new_rounds:
         if 'rounds' not in puzzle: