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?
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
@officer_assignments ||= current_user.poll_officer.officer_assignments.where(date: Time.current.to_date)
end

View File

@@ -38,13 +38,11 @@ class Officing::ResultsController < Officing::BaseController
params[:questions].each_pair do |question_id, results|
question = @poll.questions.find(question_id)
go_back_to_new if question.blank?
results.each_pair do |answer_index, count|
next if count.blank?
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(
booth_assignment_id: @officer_assignment.booth_assignment_id,
@@ -79,10 +77,10 @@ class Officing::ResultsController < Officing::BaseController
@results << recount
end
def go_back_to_new(alert = nil)
def go_back_to_new(alert)
params[:d] = Date.current
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_partial_results
render :new
@@ -123,4 +121,10 @@ class Officing::ResultsController < Officing::BaseController
def index_params
params.permit(:booth_assignment_id, :date)
end
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
end
end
end