Remove poll votation types

Unfortunately this feature wasn't properly reviewed and tested, and it
had many bugs, some of them critical and hard to fix, like validations
being skipped in concurrent requests.

So we're removing it before releasing version 1.1. We might add it back
in the future if we manage to solve the critical issues.

This commit reverts commit 836f9ba7.
This commit is contained in:
Javi Martín
2019-10-30 18:48:55 +01:00
parent f3df3f4fbc
commit af7c37634d
53 changed files with 173 additions and 2244 deletions

View File

@@ -5,73 +5,14 @@ class Polls::QuestionsController < ApplicationController
has_orders %w[most_voted newest oldest], only: :show
def answer
answer = store_answer
vote_stored(answer, params[:answer], params[:token]) if answer.present?
load_for_answers
if @question.enum_type&.include?("answer_couples")
last_pair ||= generate_and_store_new_pair(@question)
@last_pair_question_answers = { @question.id => last_pair }
end
answer = @question.answers.find_or_initialize_by(author: current_user)
token = params[:token]
answer.answer = params[:answer]
answer.touch if answer.persisted?
answer.save!
answer.record_voter_participation(token)
@answers_by_question_id = { @question.id => params[:answer] }
end
def load_answers
load_for_answers
render action: "answer.js.erb"
end
def prioritized_answers
unless params[:ordered_list].empty?
params[:ordered_list].each_with_index do |answer, i|
answer_obj = @question.votation_type.answer(current_user,
answer,
order: i + 1)
vote_stored(answer_obj, answer, params[:tooken]) if answer_obj.present?
end
@question.votation_type.update_priorized_values(current_user.id)
end
load_for_answers
render action: "answer.js.erb"
end
private
def load_for_answers
@page = params[:page].presence || 1
question_answers
@answers_by_question_id = { @question.id => @question.answers
.by_author(current_user)
.order(:order)
.pluck(:answer) }
end
def vote_stored(answer, new_answer, token)
answer.answer = new_answer
answer.touch if answer.persisted?
answer.save!
answer.record_voter_participation(token)
@question.question_answers.visibles.where(question_id: @question).each(&:set_most_voted)
end
def store_answer
if @question.votation_type.nil?
answer = @question.answers.find_or_initialize_by(author: current_user)
else
answer = @question.votation_type.answer(current_user,
params[:answer],
positive: params[:positive])
end
answer
end
def generate_and_store_new_pair(question)
Poll::PairAnswer.generate_pair(question, current_user)
end
def question_answers
if @question.is_positive_negative?
@answers = @question.question_answers.visibles.page(@page)
else
@answers = @question.question_answers.visibles
end
end
end