diff --git a/app/controllers/admin/poll/booths_controller.rb b/app/controllers/admin/poll/booths_controller.rb index ff3700436..4b322f0b2 100644 --- a/app/controllers/admin/poll/booths_controller.rb +++ b/app/controllers/admin/poll/booths_controller.rb @@ -30,6 +30,11 @@ class Admin::Poll::BoothsController < Admin::BaseController end end + def available + @booths = Poll::Booth.available.order(name: :asc).page(params[:page]) + render :index + end + private def booth_params diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index db4cee09d..773dabf34 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -57,7 +57,7 @@ module Abilities can [:index, :create, :edit, :update, :destroy], Geozone can [:read, :create, :update, :destroy, :add_question, :remove_question, :search_booths, :search_questions, :search_officers], Poll - can [:read, :create, :update, :destroy], Poll::Booth + can [:read, :create, :update, :destroy, :available], Poll::Booth can [:search, :create, :index, :destroy], ::Poll::Officer can [:create, :destroy], ::Poll::BoothAssignment can [:create, :destroy], ::Poll::OfficerAssignment diff --git a/app/models/poll/booth.rb b/app/models/poll/booth.rb index 9edbcbaf0..0aca6eecb 100644 --- a/app/models/poll/booth.rb +++ b/app/models/poll/booth.rb @@ -5,10 +5,15 @@ class Poll has_many :shifts validates :name, presence: true, uniqueness: true - + def self.search(terms) return Booth.none if terms.blank? Booth.where("name ILIKE ? OR location ILIKE ?", "%#{terms}%", "%#{terms}%") end + + def self.available + where(polls: { id: Poll.current_or_incoming }).includes(:polls) + end + end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index eaf6b98f4..a3f351e60 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -287,6 +287,8 @@ Rails.application.routes.draw do end resources :booths do + get :available, on: :collection + resources :shifts end