This rule was added in rubocop 1.44.0. It's useful to avoid accidental `unless !condition` clauses. Note we aren't replacing `unless zero?` with `if nonzero?` because we never use `nonzero?`; using it sounds like `if !zero?`. Replacing `unless any?` with `if none?` is only consistent if we also replace `unless present?` with `if blank?`, so we're also adding this case. For consistency, we're also replacing `unless blank?` with `if present?`. We're also simplifying code dealing with `> 0` conditions in order to make the code (hopefully) easier to understand. Also for consistency, we're enabling the `Style/InverseMethods` rule, which follows a similar idea.
50 lines
1.2 KiB
Ruby
50 lines
1.2 KiB
Ruby
class Officing::BaseController < ApplicationController
|
|
layout "admin"
|
|
helper_method :current_booth
|
|
|
|
before_action :authenticate_user!
|
|
before_action :verify_officer
|
|
|
|
skip_authorization_check
|
|
|
|
private
|
|
|
|
def verify_officer
|
|
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
|
|
|
|
def verify_officer_assignment
|
|
if @officer_assignments.blank?
|
|
redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed")
|
|
end
|
|
end
|
|
|
|
def verify_booth
|
|
return if current_booth.present?
|
|
|
|
booths = current_user.poll_officer.todays_booths
|
|
case booths.count
|
|
when 0
|
|
redirect_to officing_root_path
|
|
when 1
|
|
session[:booth_id] = booths.first.id
|
|
else
|
|
redirect_to new_officing_booth_path
|
|
end
|
|
end
|
|
|
|
def current_booth
|
|
Poll::Booth.find_by(id: session[:booth_id])
|
|
end
|
|
end
|