Files
grecia/app/controllers/officing/base_controller.rb
Javi Martín f7f9fc15a5 Move todays_booths_for_officer to the model
This way we can easily add a test which will fail if by accident we
change the method to use `Date.today`. Until now using `Date.today`
would only fail if we ran specs in a time zone with a different date.
2019-03-28 15:49:17 +01:00

47 lines
1.1 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.try(:poll_officer?)
end
def load_officer_assignment
@officer_assignments ||= current_user.poll_officer.
officer_assignments.
voting_days.
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 unless current_booth.blank?
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.where(id: session[:booth_id]).first
end
end