Files
nairobi/app/controllers/officing/voters_controller.rb
Javi Martín 9a8bfac5bd Prevent creation of duplicate poll voters
Note that, when taking votes from an erased user, since poll answers
don't belong to poll voters, we were not migrating them in the
`take_votes_from` method (and we aren't migrating them now either).
2024-06-26 15:41:44 +02:00

42 lines
1.3 KiB
Ruby

class Officing::VotersController < Officing::BaseController
respond_to :html, :js
before_action :load_officer_assignment
before_action :verify_officer_assignment
before_action :verify_booth
def new
@user = User.find(params[:id])
@polls = current_booth.polls.current
end
def create
@poll = Poll.find(voter_params[:poll_id])
@user = User.find(voter_params[:user_id])
@voter = Poll::Voter.new(document_type: @user.document_type,
document_number: @user.document_number,
user: @user,
poll: @poll,
origin: "booth",
officer: current_user.poll_officer,
booth_assignment: current_booth.booth_assignments.find_by(poll: @poll),
officer_assignment: officer_assignment(@poll))
@user.with_lock { @voter.save! }
end
private
def voter_params
params.require(:voter).permit(:poll_id, :user_id)
end
def officer_assignment(poll)
Poll::OfficerAssignment.by_officer(current_user.poll_officer)
.by_poll(poll)
.by_booth(current_booth)
.by_date(Date.current)
.find_by(final: false)
end
end