diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb
index 3b7455dbc..708d59109 100644
--- a/app/controllers/officing/residence_controller.rb
+++ b/app/controllers/officing/residence_controller.rb
@@ -1,5 +1,8 @@
class Officing::ResidenceController < Officing::BaseController
+ before_action :load_officer_assignment
+ before_action :validate_officer_assignment, only: :create
+
def new
@residence = Officing::Residence.new
end
@@ -18,4 +21,17 @@ class Officing::ResidenceController < Officing::BaseController
def residence_params
params.require(:residence).permit(:document_number, :document_type, :year_of_birth)
end
+
+ def load_officer_assignment
+ @officer_assignments = current_user.poll_officer.
+ officer_assignments.
+ voting_days.
+ where(date: Time.current.to_date)
+ end
+
+ def validate_officer_assignment
+ if @officer_assignments.blank?
+ redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed")
+ end
+ end
end
\ No newline at end of file
diff --git a/app/views/officing/residence/new.html.erb b/app/views/officing/residence/new.html.erb
index 63a543f50..18e19f3b2 100644
--- a/app/views/officing/residence/new.html.erb
+++ b/app/views/officing/residence/new.html.erb
@@ -1,25 +1,31 @@
-
- <%= form_for @residence, as: "residence", url: officing_residence_path do |f| %>
- <%= render "errors" %>
+<% if @officer_assignments.present? %>
+
+
+ <%= form_for @residence, as: "residence", url: officing_residence_path do |f| %>
+ <%= render "errors" %>
-
- <%= f.select :document_type, document_types, prompt: "" %>
+
+ <%= f.select :document_type, document_types, prompt: "" %>
- <%= f.text_field :document_number,
- placeholder: t("officing.residence.new.document_number") %>
-
+ <%= f.text_field :document_number,
+ placeholder: t("officing.residence.new.document_number") %>
+
-
- <%= f.text_field :year_of_birth %>
-
+
+ <%= f.text_field :year_of_birth %>
+
-
- " class="button expanded">
-
- <% end %>
+
+ " class="button expanded">
+
+ <% end %>
+
-
+<% else %>
+
+ <%= t("officing.residence.new.no_assignments") %>
+
+<% end %>
diff --git a/config/locales/officing.en.yml b/config/locales/officing.en.yml
index b739e4375..03336efdd 100644
--- a/config/locales/officing.en.yml
+++ b/config/locales/officing.en.yml
@@ -79,12 +79,14 @@ en:
residence:
flash:
create: "Document verified with Census"
+ not_allowed: "You don't have officing shifts today"
new:
title: Validate document
document_number: "Document number (including letters)"
submit: Validate document
error_verifying_census: "The Census was unable to verify this document."
form_errors: prevented the verification of this document
+ no_assignments: "You don't have officing shifts today"
voters:
new:
title: Polls
diff --git a/config/locales/officing.es.yml b/config/locales/officing.es.yml
index 831ae9a4b..0f8c87067 100644
--- a/config/locales/officing.es.yml
+++ b/config/locales/officing.es.yml
@@ -79,12 +79,14 @@ es:
residence:
flash:
create: "Documento verificado con el Padrón"
+ not_allowed: "Hoy no tienes turno de presidente de mesa"
new:
title: Validar documento
document_number: "Número de documento (incluida letra)"
submit: Validar documento
error_verifying_census: El Padrón no pudo verificar este documento.
form_errors: evitaron verificar este documento
+ no_assignments: "Hoy no tienes turno de presidente de mesa"
voters:
new:
title: Votaciones
diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb
index ef3ce5ab3..b40eb8ca0 100644
--- a/spec/features/officing/residence_spec.rb
+++ b/spec/features/officing/residence_spec.rb
@@ -3,60 +3,86 @@ require 'rails_helper'
feature 'Residence' do
let(:officer) { create(:poll_officer) }
- background do
- login_as(officer.user)
- visit officing_root_path
- end
+ feature "Officers without assignments" do
- scenario "Verify voter" do
- within("#side_menu") do
- click_link "Validate document"
+ scenario "Can not access residence verification" do
+ login_as(officer.user)
+ visit officing_root_path
+
+ within("#side_menu") do
+ click_link "Validate document"
+ end
+
+ expect(page).to have_content("You don't have officing shifts today")
+
+ create(:poll_officer_assignment, officer: officer, date: 1.day.from_now)
+
+ visit new_officing_residence_path
+
+ expect(page).to have_content("You don't have officing shifts today")
end
- select 'DNI', from: 'residence_document_type'
- fill_in 'residence_document_number', with: "12345678Z"
- fill_in 'residence_year_of_birth', with: '1980'
-
- click_button 'Validate document'
-
- expect(page).to have_content 'Document verified with Census'
end
- scenario "Error on verify" do
- within("#side_menu") do
- click_link "Validate document"
+ feature "Assigned officers" do
+
+ background do
+ create(:poll_officer_assignment, officer: officer)
+ login_as(officer.user)
+ visit officing_root_path
end
- click_button 'Validate document'
- expect(page).to have_content /\d errors? prevented the verification of this document/
- end
+ scenario "Verify voter" do
+ within("#side_menu") do
+ click_link "Validate document"
+ end
- scenario "Error on Census (document number)" do
- within("#side_menu") do
- click_link "Validate document"
+ select 'DNI', from: 'residence_document_type'
+ fill_in 'residence_document_number', with: "12345678Z"
+ fill_in 'residence_year_of_birth', with: '1980'
+
+ click_button 'Validate document'
+
+ expect(page).to have_content 'Document verified with Census'
end
- select 'DNI', from: 'residence_document_type'
- fill_in 'residence_document_number', with: "9999999A"
- fill_in 'residence_year_of_birth', with: '1980'
+ scenario "Error on verify" do
+ within("#side_menu") do
+ click_link "Validate document"
+ end
- click_button 'Validate document'
-
- expect(page).to have_content 'The Census was unable to verify this document'
- end
-
- scenario "Error on Census (year of birth)" do
- within("#side_menu") do
- click_link "Validate document"
+ click_button 'Validate document'
+ expect(page).to have_content /\d errors? prevented the verification of this document/
end
- select 'DNI', from: 'residence_document_type'
- fill_in 'residence_document_number', with: "12345678Z"
- fill_in 'residence_year_of_birth', with: '1981'
+ scenario "Error on Census (document number)" do
+ within("#side_menu") do
+ click_link "Validate document"
+ end
- click_button 'Validate document'
+ select 'DNI', from: 'residence_document_type'
+ fill_in 'residence_document_number', with: "9999999A"
+ fill_in 'residence_year_of_birth', with: '1980'
+
+ click_button 'Validate document'
+
+ expect(page).to have_content 'The Census was unable to verify this document'
+ end
+
+ scenario "Error on Census (year of birth)" do
+ within("#side_menu") do
+ click_link "Validate document"
+ end
+
+ select 'DNI', from: 'residence_document_type'
+ fill_in 'residence_document_number', with: "12345678Z"
+ fill_in 'residence_year_of_birth', with: '1981'
+
+ click_button 'Validate document'
+
+ expect(page).to have_content 'The Census was unable to verify this document'
+ end
- expect(page).to have_content 'The Census was unable to verify this document'
end
end
\ No newline at end of file
diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb
index 651538808..1e62df57e 100644
--- a/spec/features/officing/voters_spec.rb
+++ b/spec/features/officing/voters_spec.rb
@@ -13,7 +13,7 @@ feature 'Voters' do
end
scenario "Can vote", :js do
- poll = create(:poll)
+ poll = create(:poll_officer_assignment, officer: officer).booth_assignment.poll
visit new_officing_residence_path
officing_verify_residence