From 159af40cfe805cfe9755cea99023d631f66dc1e5 Mon Sep 17 00:00:00 2001 From: TLSM Date: Tue, 28 Jun 2022 03:43:16 -0400 Subject: [PATCH] Fix /bet route not enforcing exclusive votes. --- files/routes/votes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/files/routes/votes.py b/files/routes/votes.py index da2038d15..1ff55af04 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -239,8 +239,10 @@ def bet(comment_id, v): vote = request.values.get("vote") comment_id = int(comment_id) comment = get_comment(comment_id) - - existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() + + option_ids = map(lambda x: x.id, comment.post.bet_options) + existing = g.db.query(CommentVote).filter_by(user_id=v.id) \ + .filter(CommentVote.comment_id.in_(option_ids)).one_or_none() if existing: return "", 204 vote = CommentVote(user_id=v.id, vote_type=1, comment_id=comment.id)