Hides sidebar menus if officer has no shifts assigned

This commit is contained in:
decabeza
2018-06-19 12:18:48 +02:00
parent 1de0cf083f
commit 16ff5c4400
7 changed files with 74 additions and 18 deletions

View File

@@ -4,4 +4,12 @@ module OfficersHelper
truncate([officer.name, officer.email].compact.join(' - '), length: 100) truncate([officer.name, officer.email].compact.join(' - '), length: 100)
end end
def vote_collection_shift?
current_user.poll_officer.officer_assignments.where(date: Time.current.to_date).any?
end
def final_recount_shift?
current_user.poll_officer.officer_assignments.final.where(date: Time.current.to_date).any?
end
end end

View File

@@ -1,18 +1,21 @@
<div class="admin-sidebar" data-equalizer-watch> <div class="admin-sidebar" data-equalizer-watch>
<ul id="officing_menu"> <ul id="officing_menu">
<% if vote_collection_shift? %>
<li <%= "class=is-active" if controller_name == "voters" %>>
<%= link_to new_officing_residence_path do %>
<span class="icon-user"></span>
<%= t("officing.menu.voters") %>
<% end %>
</li>
<% end %>
<li <%= "class=is-active" if controller_name == "voters" %>> <% if final_recount_shift? %>
<%= link_to new_officing_residence_path do %> <li <%= "class=is-active" if ["results"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>>
<span class="icon-user"></span> <%= link_to final_officing_polls_path do %>
<%= t("officing.menu.voters") %> <span class="icon-user"></span>
<% end %> <%= t("officing.menu.total_recounts") %>
</li> <% end %>
</li>
<li <%= "class=is-active" if ["results"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>> <% end%>
<%= link_to final_officing_polls_path do %>
<span class="icon-user"></span>
<%= t("officing.menu.total_recounts") %>
<% end %>
</li>
</ul> </ul>
</div> </div>

View File

@@ -2,4 +2,10 @@
<h2><%= t("officing.dashboard.index.title") %></h2> <h2><%= t("officing.dashboard.index.title") %></h2>
<p><%= t("officing.dashboard.index.info") %></p> <p><%= t("officing.dashboard.index.info") %></p>
<% unless final_recount_shift? && vote_collection_shift? %>
<div class="callout warning">
<%= t("officing.dashboard.index.no_shifts") %>
</div>
<% end %>
</div> </div>

View File

@@ -6,6 +6,7 @@ en:
index: index:
title: Poll officing title: Poll officing
info: Here you can validate user documents and store voting results info: Here you can validate user documents and store voting results
no_shifts: You don't have officing shifts today.
menu: menu:
voters: Validate document voters: Validate document
total_recounts: Total recounts and results total_recounts: Total recounts and results

View File

@@ -6,6 +6,7 @@ es:
index: index:
title: Presidir mesa de votaciones title: Presidir mesa de votaciones
info: Aquí puedes validar documentos de ciudadanos y guardar los resultados de las urnas info: Aquí puedes validar documentos de ciudadanos y guardar los resultados de las urnas
no_shifts: No tienes turnos de presidente de mesa asignados hoy.
menu: menu:
voters: Validar documento y votar voters: Validar documento y votar
total_recounts: Recuento total y escrutinio total_recounts: Recuento total y escrutinio

View File

@@ -0,0 +1,40 @@
require 'rails_helper'
feature 'Budget Poll Officing' do
scenario 'Show sidebar menu if officer has shifts assigned' do
budget = create(:budget)
poll = create(:poll, budget: budget)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
user = create(:user)
officer = create(:poll_officer, user: user)
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :recount_scrutiny)
officer_assignment = create(:poll_officer_assignment,
booth_assignment: booth_assignment,
officer: officer)
login_as user
visit officing_root_path
expect(page).not_to have_content("You don't have officing shifts today")
expect(page).to have_content("Validate document")
expect(page).to have_content("Total recounts and results")
end
scenario 'Do not show sidebar menu if officer has no shifts assigned' do
user = create(:user)
officer = create(:poll_officer, user: user)
login_as user
visit officing_root_path
expect(page).to have_content("You don't have officing shifts today")
expect(page).not_to have_content("Validate document")
expect(page).not_to have_content("Total recounts and results")
end
end

View File

@@ -9,10 +9,7 @@ feature 'Residence' do
login_as(officer.user) login_as(officer.user)
visit officing_root_path visit officing_root_path
within("#side_menu") do expect(page).not_to have_link("Validate document")
click_link "Validate document"
end
expect(page).to have_content("You don't have officing shifts today") expect(page).to have_content("You don't have officing shifts today")
create(:poll_officer_assignment, officer: officer, date: 1.day.from_now) create(:poll_officer_assignment, officer: officer, date: 1.day.from_now)