From a9845fbd6726ac3c812d7c11068e0336340c59d5 Mon Sep 17 00:00:00 2001 From: trisua Date: Fri, 6 Jun 2025 15:57:31 -0400 Subject: [PATCH] add: check associated when voting on polls --- crates/app/src/public/js/me.js | 4 +++- crates/app/src/routes/api/v1/communities/posts.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/app/src/public/js/me.js b/crates/app/src/public/js/me.js index 6cc76af..f88acb7 100644 --- a/crates/app/src/public/js/me.js +++ b/crates/app/src/public/js/me.js @@ -129,7 +129,9 @@ res.message, ]); - window.location.href = `/post/${id}`; + if (res.ok) { + window.location.href = `/post/${id}`; + } }); }); diff --git a/crates/app/src/routes/api/v1/communities/posts.rs b/crates/app/src/routes/api/v1/communities/posts.rs index 0a76fa0..6e578ce 100644 --- a/crates/app/src/routes/api/v1/communities/posts.rs +++ b/crates/app/src/routes/api/v1/communities/posts.rs @@ -356,6 +356,18 @@ pub async fn vote_request( Err(e) => return Json(e.into()), }; + // check associated accounts for prior votes + for id in user.associated { + if data.get_pollvote_by_owner_poll(id, poll.id).await.is_ok() { + return Json( + Error::MiscError( + "You've already voted on this poll on a different account".to_string(), + ) + .into(), + ); + } + } + // ... match data .create_pollvote(PollVote::new(user.id, poll.id, req.option))