From 4369272c49b4630e5c2646762641f179b70a52ed Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Tue, 3 May 2022 04:37:03 -0400 Subject: [PATCH] Fix issue where hint with a free requirement could not be unlocked (#2107) * Fix issue where hint with a free requirement could not be unlocked * Fix issue with referring to the right hint id --- CTFd/api/v1/hints.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CTFd/api/v1/hints.py b/CTFd/api/v1/hints.py index 10d39f91..0ee60fa3 100644 --- a/CTFd/api/v1/hints.py +++ b/CTFd/api/v1/hints.py @@ -125,7 +125,14 @@ class Hint(Resource): # Get the IDs of all hints that the user has unlocked all_unlocks = HintUnlocks.query.filter_by(account_id=user.account_id).all() - unlock_ids = {unlock.id for unlock in all_unlocks} + unlock_ids = {unlock.target for unlock in all_unlocks} + + # Get the IDs of all free hints + free_hints = Hints.query.filter_by(cost=0).all() + free_ids = {h.id for h in free_hints} + + # Add free hints to unlocked IDs + unlock_ids.update(free_ids) # Filter out hint IDs that don't exist all_hint_ids = {h.id for h in Hints.query.with_entities(Hints.id).all()}