Remove unused go_back_to_new calls and unused error_create key

- Remove two redundant go_back_to_new calls in build_results, since
  @poll.questions.find already raises RecordNotFound if a question
  does not exist.
- Drop the fallback flash translation error_create, which is no longer
  used since commit 592fdffe4e and only remained as a default in
  go_back_to_new.
- Move check_officer_assignment from Officing::BaseController to
  Officing::ResultsController, its only place of use.
This commit is contained in:
taitus
2025-09-10 09:28:00 +02:00
parent 086c79993f
commit 896ebc82fd
4 changed files with 8 additions and 12 deletions

View File

@@ -13,12 +13,6 @@ class Officing::BaseController < ApplicationController
raise CanCan::AccessDenied unless current_user&.poll_officer? raise CanCan::AccessDenied unless current_user&.poll_officer?
end end
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
end
end
def load_officer_assignment def load_officer_assignment
@officer_assignments ||= current_user.poll_officer.officer_assignments.where(date: Time.current.to_date) @officer_assignments ||= current_user.poll_officer.officer_assignments.where(date: Time.current.to_date)
end end

View File

@@ -38,13 +38,11 @@ class Officing::ResultsController < Officing::BaseController
params[:questions].each_pair do |question_id, results| params[:questions].each_pair do |question_id, results|
question = @poll.questions.find(question_id) question = @poll.questions.find(question_id)
go_back_to_new if question.blank?
results.each_pair do |answer_index, count| results.each_pair do |answer_index, count|
next if count.blank? next if count.blank?
answer = question.question_options.find_by(given_order: answer_index.to_i + 1).title answer = question.question_options.find_by(given_order: answer_index.to_i + 1).title
go_back_to_new if question.blank?
partial_result = ::Poll::PartialResult.find_or_initialize_by( partial_result = ::Poll::PartialResult.find_or_initialize_by(
booth_assignment_id: @officer_assignment.booth_assignment_id, booth_assignment_id: @officer_assignment.booth_assignment_id,
@@ -79,10 +77,10 @@ class Officing::ResultsController < Officing::BaseController
@results << recount @results << recount
end end
def go_back_to_new(alert = nil) def go_back_to_new(alert)
params[:d] = Date.current params[:d] = Date.current
params[:oa] = results_params[:officer_assignment_id] params[:oa] = results_params[:officer_assignment_id]
flash.now[:alert] = (alert || t("officing.results.flash.error_create")) flash.now[:alert] = alert
load_officer_assignments load_officer_assignments
load_partial_results load_partial_results
render :new render :new
@@ -123,4 +121,10 @@ class Officing::ResultsController < Officing::BaseController
def index_params def index_params
params.permit(:booth_assignment_id, :date) params.permit(:booth_assignment_id, :date)
end end
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
end
end
end end

View File

@@ -41,7 +41,6 @@ en:
results: results:
flash: flash:
create: "Results saved" create: "Results saved"
error_create: "Results NOT saved. Error in data."
error_wrong_booth: "Wrong booth. Results NOT saved." error_wrong_booth: "Wrong booth. Results NOT saved."
new: new:
title: "%{poll} - Add results" title: "%{poll} - Add results"

View File

@@ -41,7 +41,6 @@ es:
results: results:
flash: flash:
create: "Datos guardados" create: "Datos guardados"
error_create: "Resultados NO añadidos. Error en los datos"
error_wrong_booth: "Urna incorrecta. Resultados NO guardados." error_wrong_booth: "Urna incorrecta. Resultados NO guardados."
new: new:
title: "%{poll} - Añadir resultados" title: "%{poll} - Añadir resultados"