restricts access to residence validations to assigned officers
This commit is contained in:
@@ -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
|
||||
@@ -1,25 +1,31 @@
|
||||
<h2><%= t("officing.residence.new.title") %></h2>
|
||||
|
||||
<div class="row verification account">
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= form_for @residence, as: "residence", url: officing_residence_path do |f| %>
|
||||
<%= render "errors" %>
|
||||
<% if @officer_assignments.present? %>
|
||||
<div class="row verification account">
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= form_for @residence, as: "residence", url: officing_residence_path do |f| %>
|
||||
<%= render "errors" %>
|
||||
|
||||
<div class="small-12 medium-6">
|
||||
<%= f.select :document_type, document_types, prompt: "" %>
|
||||
<div class="small-12 medium-6">
|
||||
<%= f.select :document_type, document_types, prompt: "" %>
|
||||
|
||||
|
||||
<%= f.text_field :document_number,
|
||||
placeholder: t("officing.residence.new.document_number") %>
|
||||
</div>
|
||||
<%= f.text_field :document_number,
|
||||
placeholder: t("officing.residence.new.document_number") %>
|
||||
</div>
|
||||
|
||||
<div class="date-of-birth small-12 medium-6">
|
||||
<%= f.text_field :year_of_birth %>
|
||||
</div>
|
||||
<div class="date-of-birth small-12 medium-6">
|
||||
<%= f.text_field :year_of_birth %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6">
|
||||
<input type="submit" value="<%= t("officing.residence.new.submit") %>" class="button expanded">
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="small-12 medium-6">
|
||||
<input type="submit" value="<%= t("officing.residence.new.submit") %>" class="button expanded">
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="callout primary">
|
||||
<%= t("officing.residence.new.no_assignments") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user