Remove token column from poll_voters table
As it is no longer used as originally pretended [1][2]. [1] Check consul/consul pull request 1994 [2] Check consul/consul pull request 3539
This commit is contained in:
committed by
taitus
parent
dd04765af3
commit
64676be246
@@ -1,28 +1,7 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
App.Polls = {
|
||||
generateToken: function() {
|
||||
var strings;
|
||||
strings = Array.apply(null, {
|
||||
length: 6
|
||||
}).map(function() {
|
||||
return Math.random().toString(36).substr(2); // remove `0.`
|
||||
});
|
||||
return strings.join("").substring(0, 64);
|
||||
},
|
||||
replaceToken: function(token) {
|
||||
$(".js-question-answer").each(function() {
|
||||
var token_param;
|
||||
token_param = this.search.slice(-6);
|
||||
if (token_param === "token=") {
|
||||
this.href = this.href + token;
|
||||
}
|
||||
});
|
||||
},
|
||||
initialize: function() {
|
||||
var token;
|
||||
token = App.Polls.generateToken();
|
||||
App.Polls.replaceToken(token);
|
||||
$(".zoom-link").on("click", function(event) {
|
||||
var answer;
|
||||
answer = $(event.target).closest("div.answer");
|
||||
|
||||
@@ -6,10 +6,9 @@ class Polls::QuestionsController < ApplicationController
|
||||
|
||||
def answer
|
||||
answer = @question.answers.find_or_initialize_by(author: current_user)
|
||||
token = params[:token]
|
||||
|
||||
answer.answer = params[:answer]
|
||||
answer.save_and_record_voter_participation(token)
|
||||
answer.save_and_record_voter_participation
|
||||
|
||||
@answers_by_question_id = { @question.id => params[:answer] }
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class PollsController < ApplicationController
|
||||
include FeatureFlags
|
||||
include PollsHelper
|
||||
|
||||
feature_flag :polls
|
||||
|
||||
@@ -20,7 +19,6 @@ class PollsController < ApplicationController
|
||||
|
||||
def show
|
||||
@questions = @poll.questions.for_render.sort_for_list
|
||||
@token = poll_voter_token(@poll, current_user)
|
||||
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
|
||||
.with_content.order(:given_order)
|
||||
|
||||
|
||||
@@ -12,10 +12,6 @@ module PollsHelper
|
||||
booth.name + location
|
||||
end
|
||||
|
||||
def poll_voter_token(poll, user)
|
||||
Poll::Voter.find_by(poll: poll, user: user, origin: "web")&.token || ""
|
||||
end
|
||||
|
||||
def voted_before_sign_in(question)
|
||||
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at > vote.updated_at }
|
||||
end
|
||||
|
||||
@@ -14,11 +14,11 @@ class Poll::Answer < ApplicationRecord
|
||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
||||
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
||||
|
||||
def save_and_record_voter_participation(token)
|
||||
def save_and_record_voter_participation
|
||||
transaction do
|
||||
touch if persisted?
|
||||
save!
|
||||
Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web", token: token)
|
||||
Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
</span>
|
||||
<% else %>
|
||||
<%= link_to answer.title,
|
||||
answer_question_path(question, answer: answer.title, token: token),
|
||||
answer_question_path(question, answer: answer.title),
|
||||
method: :post,
|
||||
remote: true,
|
||||
title: t("poll_questions.show.vote_answer", answer: answer.title),
|
||||
class: "button secondary hollow js-question-answer" %>
|
||||
class: "button secondary hollow" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% elsif !user_signed_in? %>
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
</h3>
|
||||
|
||||
<div id="<%= dom_id(question) %>_answers" class="padding">
|
||||
<%= render "polls/questions/answers", question: question, token: token %>
|
||||
<%= render "polls/questions/answers", question: question %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
<% token = poll_voter_token(@question.poll, current_user) %>
|
||||
$("#<%= dom_id(@question) %>_answers").html("<%= j render("polls/questions/answers", question: @question, token: token) %>");
|
||||
$("#<%= dom_id(@question) %>_answers").html("<%= j render("polls/questions/answers", question: @question) %>");
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<% end %>
|
||||
|
||||
<% @questions.each do |question| %>
|
||||
<%= render "polls/questions/question", question: question, token: @token %>
|
||||
<%= render "polls/questions/question", question: question %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -146,8 +146,7 @@ section "Creating Poll Voters" do
|
||||
document_number: user.document_number,
|
||||
user: user,
|
||||
poll: poll,
|
||||
origin: "web",
|
||||
token: SecureRandom.hex(32))
|
||||
origin: "web")
|
||||
end
|
||||
|
||||
def randomly_answer_questions(poll, user)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveTokenFromPollVoter < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
remove_column :poll_voters, :token, :string
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_11_03_112944) do
|
||||
ActiveRecord::Schema.define(version: 2022_09_15_154808) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_trgm"
|
||||
@@ -1210,7 +1210,6 @@ ActiveRecord::Schema.define(version: 2021_11_03_112944) do
|
||||
t.integer "user_id"
|
||||
t.string "origin"
|
||||
t.integer "officer_id"
|
||||
t.string "token"
|
||||
t.index ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id"
|
||||
t.index ["document_number"], name: "index_poll_voters_on_document_number"
|
||||
t.index ["officer_assignment_id"], name: "index_poll_voters_on_officer_assignment_id"
|
||||
|
||||
@@ -144,7 +144,6 @@ FactoryBot.define do
|
||||
poll { budget&.poll || association(:poll, budget: budget) }
|
||||
trait :from_web do
|
||||
origin { "web" }
|
||||
token { SecureRandom.hex(32) }
|
||||
end
|
||||
|
||||
trait :from_booth do
|
||||
|
||||
@@ -46,7 +46,7 @@ describe Poll::Answer do
|
||||
answer = create(:poll_answer, question: question, author: author, answer: "Yes")
|
||||
expect(answer.poll.voters).to be_blank
|
||||
|
||||
answer.save_and_record_voter_participation("token")
|
||||
answer.save_and_record_voter_participation
|
||||
expect(poll.reload.voters.size).to eq(1)
|
||||
voter = poll.voters.first
|
||||
|
||||
@@ -57,12 +57,12 @@ describe Poll::Answer do
|
||||
|
||||
it "updates a poll_voter with user and poll data" do
|
||||
answer = create(:poll_answer, question: question, author: author, answer: "Yes")
|
||||
answer.save_and_record_voter_participation("token")
|
||||
answer.save_and_record_voter_participation
|
||||
|
||||
expect(poll.reload.voters.size).to eq(1)
|
||||
|
||||
answer = create(:poll_answer, question: question, author: author, answer: "No")
|
||||
answer.save_and_record_voter_participation("token")
|
||||
answer.save_and_record_voter_participation
|
||||
|
||||
expect(poll.reload.voters.size).to eq(1)
|
||||
|
||||
@@ -76,7 +76,7 @@ describe Poll::Answer do
|
||||
answer = build(:poll_answer)
|
||||
|
||||
expect do
|
||||
answer.save_and_record_voter_participation("token")
|
||||
answer.save_and_record_voter_participation
|
||||
end.to raise_error(ActiveRecord::RecordInvalid)
|
||||
|
||||
expect(answer).not_to be_persisted
|
||||
|
||||
@@ -196,21 +196,19 @@ describe Poll::Voter do
|
||||
|
||||
it "sets user info" do
|
||||
user = create(:user, document_number: "1234A", document_type: "1")
|
||||
voter = build(:poll_voter, user: user, token: "1234abcd")
|
||||
voter = build(:poll_voter, user: user)
|
||||
voter.save!
|
||||
|
||||
expect(voter.document_number).to eq("1234A")
|
||||
expect(voter.document_type).to eq("1")
|
||||
expect(voter.token).to eq("1234abcd")
|
||||
end
|
||||
|
||||
it "sets user info with skip verification enabled" do
|
||||
Setting["feature.user.skip_verification"] = true
|
||||
user = create(:user)
|
||||
voter = build(:poll_voter, user: user, token: "1234abcd")
|
||||
voter.save!
|
||||
voter = build(:poll_voter, user: user)
|
||||
|
||||
expect(voter.token).to eq("1234abcd")
|
||||
expect { voter.save! }.not_to raise_exception
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,8 +38,8 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).not_to have_link(answer_yes.title, href: "/questions/#{question.id}/answer?answer=#{answer_yes.title}&token=")
|
||||
expect(page).not_to have_link(answer_no.title, href: "/questions/#{question.id}/answer?answer=#{answer_no.title}&token=")
|
||||
expect(page).not_to have_link(answer_yes.title, href: "/questions/#{question.id}/answer?answer=#{answer_yes.title}")
|
||||
expect(page).not_to have_link(answer_no.title, href: "/questions/#{question.id}/answer?answer=#{answer_no.title}")
|
||||
end
|
||||
|
||||
expect(page).to have_content("You must verify your account in order to answer")
|
||||
|
||||
Reference in New Issue
Block a user