Merge branch 'master' into 1786-poll_results

This commit is contained in:
María Checa
2017-10-23 13:43:58 +02:00
25 changed files with 341 additions and 153 deletions

View File

@@ -23,18 +23,24 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
end end
def create def create
@booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll_id], @poll = Poll.find(booth_assignment_params[:poll_id])
booth_id: booth_assignment_params[:booth_id]) @booth = Poll::Booth.find(booth_assignment_params[:booth_id])
@booth_assignment = ::Poll::BoothAssignment.new(poll: @poll,
booth: @booth)
if @booth_assignment.save if @booth_assignment.save
notice = t("admin.poll_booth_assignments.flash.create") notice = t("admin.poll_booth_assignments.flash.create")
else else
notice = t("admin.poll_booth_assignments.flash.error_create") notice = t("admin.poll_booth_assignments.flash.error_create")
end end
redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice respond_to do |format|
format.js { render layout: false }
end
end end
def destroy def destroy
@poll = Poll.find(booth_assignment_params[:poll_id])
@booth = Poll::Booth.find(booth_assignment_params[:booth_id])
@booth_assignment = ::Poll::BoothAssignment.find(params[:id]) @booth_assignment = ::Poll::BoothAssignment.find(params[:id])
if @booth_assignment.destroy if @booth_assignment.destroy
@@ -42,7 +48,14 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
else else
notice = t("admin.poll_booth_assignments.flash.error_destroy") notice = t("admin.poll_booth_assignments.flash.error_destroy")
end end
redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice respond_to do |format|
format.js { render layout: false }
end
end
def manage
@booths = ::Poll::Booth.all
@poll = Poll.find(params[:poll_id])
end end
private private

View File

@@ -47,6 +47,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
redirect_to admin_poll_path(@poll), notice: notice redirect_to admin_poll_path(@poll), notice: notice
end end
def booth_assignments
@polls = Poll.current_or_incoming
end
private private
def load_geozones def load_geozones
@@ -54,7 +58,8 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
end end
def poll_params def poll_params
params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description, params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted,
:summary, :description, :results_enabled, :stats_enabled,
geozone_ids: [], geozone_ids: [],
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end end

View File

@@ -7,6 +7,6 @@ class Officing::BaseController < ApplicationController
skip_authorization_check skip_authorization_check
def verify_officer def verify_officer
raise CanCan::AccessDenied unless current_user.try(:poll_officer?) || current_user.try(:administrator?) raise CanCan::AccessDenied unless current_user.try(:poll_officer?)
end end
end end

View File

@@ -52,12 +52,8 @@ module UsersHelper
current_user && current_user.manager? current_user && current_user.manager?
end end
def current_poll_officer?
current_user && current_user.poll_officer?
end
def show_admin_menu? def show_admin_menu?
current_administrator? || current_moderator? || current_valuator? || current_manager? || current_poll_officer? current_administrator? || current_moderator? || current_valuator? || current_manager?
end end
def interests_title_text(user) def interests_title_text(user)

View File

@@ -56,10 +56,10 @@ module Abilities
can [:index, :create, :edit, :update, :destroy], Geozone can [:index, :create, :edit, :update, :destroy], Geozone
can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers], Poll can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers, :booth_assignments], Poll
can [:read, :create, :update, :destroy, :available], Poll::Booth can [:read, :create, :update, :destroy, :available], Poll::Booth
can [:search, :create, :index, :destroy], ::Poll::Officer can [:search, :create, :index, :destroy], ::Poll::Officer
can [:create, :destroy], ::Poll::BoothAssignment can [:create, :destroy, :manage], ::Poll::BoothAssignment
can [:create, :destroy], ::Poll::OfficerAssignment can [:create, :destroy], ::Poll::OfficerAssignment
can [:read, :create, :update], Poll::Question can [:read, :create, :update], Poll::Question
can :destroy, Poll::Question # , comments_count: 0, votes_up: 0 can :destroy, Poll::Question # , comments_count: 0, votes_up: 0

View File

@@ -15,5 +15,8 @@ class Poll
where(polls: { id: Poll.current_or_incoming }).includes(:polls) where(polls: { id: Poll.current_or_incoming }).includes(:polls)
end end
def assignment_on_poll(poll)
booth_assignments.where(poll: poll).first
end
end end
end end

View File

@@ -60,7 +60,8 @@
<strong><%= t("admin.menu.title_polls") %></strong> <strong><%= t("admin.menu.title_polls") %></strong>
</a> </a>
<ul id="polls_menu" <%= "class=is-active" if menu_polls? || controller.class.parent == Admin::Poll::Questions::Answers %>> <ul id="polls_menu" <%= "class=is-active" if menu_polls? || controller.class.parent == Admin::Poll::Questions::Answers %>>
<li <%= "class=active" if ["polls", "officer_assignments", "booth_assignments", "recounts", "results"].include? controller_name %>> <li <%= "class=active" if controller_name == "polls" && action_name != "booth_assignments" ||
(["booth_assignments", "officer_assignments", "recounts", "results"].include? controller_name) %>>
<%= link_to t('admin.menu.polls'), admin_polls_path %> <%= link_to t('admin.menu.polls'), admin_polls_path %>
</li> </li>
@@ -79,6 +80,10 @@
<%= link_to t('admin.menu.poll_booths'), admin_booths_path %> <%= link_to t('admin.menu.poll_booths'), admin_booths_path %>
</li> </li>
<li <%= "class=active" if (controller_name == "polls" && action_name == "booth_assignments") || (controller_name == "booth_assignments" && action_name == "manage") %>>
<%= link_to t('admin.menu.poll_booth_assignments'), booth_assignments_admin_polls_path %>
</li>
<li <%= "class=active" if controller_name == "shifts" || <li <%= "class=active" if controller_name == "shifts" ||
controller_name == "booths" && controller_name == "booths" &&
action_name == "available" %>> action_name == "available" %>>

View File

@@ -0,0 +1,31 @@
<td>
<%= link_to booth.name, admin_booth_path(booth) %>
</td>
<td>
<%= booth.location || t("admin.booths.index.no_location") %>
</td>
<% if booth_assignment.present? %>
<td>
<span class="verified"><%= t("admin.booth_assignments.manage.status.assigned") %></span>
</td>
<td class="text-right">
<%= link_to t("admin.booth_assignments.manage.actions.unassign"),
admin_poll_booth_assignment_path(@poll, booth_assignment, booth_id: booth.id),
method: :delete,
remote: true,
title: t("admin.booth_assignments.manage.actions.unassign"),
class: "button hollow alert" %>
</td>
<% else %>
<td>
<span class="delete"><%= t("admin.booth_assignments.manage.status.unassigned") %></span>
</td>
<td class="text-right">
<%= link_to t("admin.booth_assignments.manage.actions.assign"),
admin_poll_booth_assignments_path(@poll, booth_id: booth.id),
method: :post,
remote: true,
title: t("admin.booth_assignments.manage.actions.assign"),
class: "button" %>
</td>
<% end %>

View File

@@ -12,7 +12,6 @@
<tr> <tr>
<th><%= t("admin.poll_booth_assignments.index.table_name") %></th> <th><%= t("admin.poll_booth_assignments.index.table_name") %></th>
<th><%= t("admin.poll_booth_assignments.index.table_location") %></th> <th><%= t("admin.poll_booth_assignments.index.table_location") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.index.table_assignment") %></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -24,14 +23,6 @@
<td> <td>
<%= booth.location %> <%= booth.location %>
</td> </td>
<td class="text-center">
<% unless @poll.booth_ids.include?(booth.id) %>
<%= link_to t("admin.poll_booth_assignments.index.add_booth"),
admin_poll_booth_assignments_path(@poll, booth_id: booth.id),
method: :post,
class: "button hollow" %>
<% end %>
</td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@booth) %>").html('<%= j render("booth_assignment", booth: @booth, booth_assignment: @booth.assignment_on_poll(@poll)) %>');

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@booth) %>").html('<%= j render("booth_assignment", booth: @booth, booth_assignment: @booth.assignment_on_poll(@poll)) %>');

View File

@@ -1,10 +1,15 @@
<%= render "/admin/poll/polls/poll_header" %> <%= render "/admin/poll/polls/poll_header" %>
<div id="poll-resources"> <div id="poll-resources">
<%= render "/admin/poll/polls/subnav" %> <%= render "/admin/poll/polls/subnav" %>
<%= render "search_booths" %> <%= render "search_booths" %>
<h3><%= t("admin.poll_booth_assignments.index.booths_title") %></h3> <h3><%= t("admin.poll_booth_assignments.index.booths_title") %></h3>
<%= link_to t("admin.booth_assignments.manage_assignments"),
manage_admin_poll_booth_assignments_path(@poll),
class: "button hollow float-right" %>
<% if @booth_assignments.empty? %> <% if @booth_assignments.empty? %>
<div class="callout primary margin-top"> <div class="callout primary margin-top">
<%= t("admin.poll_booth_assignments.index.no_booths") %> <%= t("admin.poll_booth_assignments.index.no_booths") %>
@@ -14,7 +19,6 @@
<thead> <thead>
<th><%= t("admin.poll_booth_assignments.index.table_name") %></th> <th><%= t("admin.poll_booth_assignments.index.table_name") %></th>
<th><%= t("admin.poll_booth_assignments.index.table_location") %></th> <th><%= t("admin.poll_booth_assignments.index.table_location") %></th>
<th class="text-right"><%= t("admin.poll_booth_assignments.index.table_assignment") %></th>
</thead> </thead>
<tbody> <tbody>
<% @booth_assignments.each do |booth_assignment| %> <% @booth_assignments.each do |booth_assignment| %>
@@ -25,13 +29,7 @@
</strong> </strong>
</td> </td>
<td> <td>
<%= booth_assignment.booth.location %> <%= booth_assignment.booth.location || t("admin.booths.index.no_location") %>
</td>
<td class="text-right">
<%= link_to t("admin.poll_booth_assignments.index.remove_booth"),
admin_poll_booth_assignment_path(@poll, booth_assignment),
method: :delete,
class: "button hollow alert" %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -0,0 +1,28 @@
<%= link_to booth_assignments_admin_polls_path do %>
<span class="icon-angle-left"></span> <%= t("shared.back") %>
<% end %>
<hr>
<h2 class="inline-block"><%= t("admin.booth_assignments.manage.assignments_list", poll: @poll.name) %></h2>
<% if @booths.empty? %>
<div class="callout primary">
<%= t("admin.booths.index.no_booths") %>
</div>
<% else %>
<table>
<thead>
<th><%= t("admin.booths.index.name") %></th>
<th><%= t("admin.booths.index.location") %></th>
<th><%= t("admin.booth_assignments.manage.status.assign_status") %></th>
<th class="text-right"><%= t("admin.actions.actions") %></th>
</thead>
<tbody>
<% @booths.each do |booth| %>
<tr id="<%= dom_id(booth) %>" class="booth">
<%= render partial: "booth_assignment", locals: { booth: booth, booth_assignment: booth.assignment_on_poll(@poll) } %>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -53,6 +53,17 @@
</div> </div>
</div> </div>
<% if controller_name == "polls" && action_name == "edit" %>
<div class="row">
<fieldset class="fieldset">
<legend><%= t('admin.polls.new.show_results_and_stats') %></legend>
<%= f.check_box :results_enabled, checked: @poll.results_enabled?, label: t('admin.polls.new.show_results') %>
<%= f.check_box :stats_enabled, checked: @poll.stats_enabled?, label: t('admin.polls.new.show_stats') %>
<p class="small"><%= t('admin.polls.new.results_and_stats_reminder') %></p>
</fieldset>
</div>
<% end %>
<div class="row"> <div class="row">
<div class="small-12 medium-4 column"> <div class="small-12 medium-4 column">
<%= f.submit t("admin.polls.#{admin_submit_action(@poll)}.submit_button"), <%= f.submit t("admin.polls.#{admin_submit_action(@poll)}.submit_button"),

View File

@@ -0,0 +1,32 @@
<h2 class="inline-block"><%= t("admin.polls.index.title") %></h2>
<% if @polls.any? %>
<table>
<thead>
<th class="medium-6"><%= t("admin.polls.index.name") %></th>
<th><%= t("admin.polls.index.dates") %></th>
<th class="text-right"><%= t("admin.actions.actions") %></th>
</thead>
<tbody>
<% @polls.each do |poll| %>
<tr id="<%= dom_id(poll) %>" class="poll">
<td>
<strong><%= link_to poll.name, admin_poll_path(poll) %></strong>
</td>
<td>
<%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %>
</td>
<td class="text-right">
<%= link_to t("admin.booth_assignments.manage_assignments"),
manage_admin_poll_booth_assignments_path(poll),
class: "button hollow" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout primary">
<%= t("admin.polls.index.no_polls") %>
</div>
<% end %>

View File

@@ -1,10 +1,12 @@
<li> <% if current_user.administrator? %>
<li>
<%= link_to admin_stats_path, title: t("admin.menu.stats") do %> <%= link_to admin_stats_path, title: t("admin.menu.stats") do %>
<span class="icon-stats"></span> <span class="icon-stats"></span>
<% end %> <% end %>
</li> </li>
<li> <li>
<%= link_to admin_settings_path, title: t("admin.menu.settings") do %> <%= link_to admin_settings_path, title: t("admin.menu.settings") do %>
<span class="icon-settings"></span> <span class="icon-settings"></span>
<% end %> <% end %>
</li> </li>
<% end %>

View File

@@ -26,12 +26,11 @@
<%= link_to t("layouts.header.management"), management_sign_in_path %> <%= link_to t("layouts.header.management"), management_sign_in_path %>
</li> </li>
<% end %> <% end %>
<% if current_user.administrator? || current_user.poll_officer? %>
<li>
<%= link_to t("layouts.header.officing"), officing_root_path %>
</li>
<% end %>
</ul> </ul>
</li> </li>
<% end %> <% end %>
<% if current_user && current_user.poll_officer? %>
<li>
<%= link_to t("layouts.header.officing"), officing_root_path %>
</li>
<% end %>

View File

@@ -409,6 +409,7 @@ en:
poll_officers: Poll officers poll_officers: Poll officers
polls: Polls polls: Polls
poll_booths: Booths location poll_booths: Booths location
poll_booth_assignments: Booths Assignments
poll_shifts: Manage shifts poll_shifts: Manage shifts
officials: Officials officials: Officials
organizations: Organisations organizations: Organisations
@@ -524,6 +525,17 @@ en:
date_missing: "A date must be selected" date_missing: "A date must be selected"
vote_collection: Collect Votes vote_collection: Collect Votes
recount_scrutiny: Recount & Scrutiny recount_scrutiny: Recount & Scrutiny
booth_assignments:
manage_assignments: Manage assignments
manage:
assignments_list: "Assignments for poll '%{poll}'"
status:
assign_status: Assignment
assigned: Assigned
unassigned: Unassigned
actions:
assign: Assign booth
unassign: Unassign booth
poll_booth_assignments: poll_booth_assignments:
flash: flash:
destroy: "Booth not assigned anymore" destroy: "Booth not assigned anymore"
@@ -547,9 +559,6 @@ en:
no_booths: "There are no booths assigned to this poll." no_booths: "There are no booths assigned to this poll."
table_name: "Name" table_name: "Name"
table_location: "Location" table_location: "Location"
table_assignment: "Assignment"
remove_booth: "Remove booth from poll"
add_booth: "Assign booth"
polls: polls:
index: index:
title: "List of polls" title: "List of polls"
@@ -560,6 +569,10 @@ en:
geozone_restricted: "Restricted to districts" geozone_restricted: "Restricted to districts"
new: new:
title: "New poll" title: "New poll"
show_results_and_stats: "Show results and stats"
show_results: "Show results"
show_stats: "Show stats"
results_and_stats_reminder: "Marking these checkboxes the results and/or stats of this poll will be publicly available and every user will see them."
submit_button: "Create poll" submit_button: "Create poll"
edit: edit:
title: "Edit poll" title: "Edit poll"
@@ -666,6 +679,7 @@ en:
add_booth: "Add booth" add_booth: "Add booth"
name: "Name" name: "Name"
location: "Location" location: "Location"
no_location: "No Location"
new: new:
title: "New booth" title: "New booth"
name: "Name" name: "Name"

View File

@@ -420,6 +420,7 @@ es:
poll_officers: Presidentes de mesa poll_officers: Presidentes de mesa
polls: Votaciones polls: Votaciones
poll_booths: Ubicación de urnas poll_booths: Ubicación de urnas
poll_booth_assignments: Asignación de urnas
poll_shifts: Asignar turnos poll_shifts: Asignar turnos
officials: Cargos públicos officials: Cargos públicos
organizations: Organizaciones organizations: Organizaciones
@@ -524,6 +525,17 @@ es:
date_missing: "Debe seleccionarse una fecha" date_missing: "Debe seleccionarse una fecha"
vote_collection: Recoger Votos vote_collection: Recoger Votos
recount_scrutiny: Recuento & Escrutinio recount_scrutiny: Recuento & Escrutinio
booth_assignments:
manage_assignments: Gestionar asignaciones
manage:
assignments_list: "Asignaciones para la votación '%{poll}'"
status:
assign_status: Asignación
assigned: Asignada
unassigned: No asignada
actions:
assign: Assign booth
unassign: Unassign booth
poll_booth_assignments: poll_booth_assignments:
flash: flash:
destroy: "Urna desasignada" destroy: "Urna desasignada"
@@ -547,9 +559,6 @@ es:
no_booths: "No hay urnas asignadas a esta votación." no_booths: "No hay urnas asignadas a esta votación."
table_name: "Nombre" table_name: "Nombre"
table_location: "Ubicación" table_location: "Ubicación"
table_assignment: "Asignación"
remove_booth: "Desasignar urna"
add_booth: "Asignar urna"
polls: polls:
index: index:
title: "Listado de votaciones" title: "Listado de votaciones"
@@ -560,6 +569,10 @@ es:
geozone_restricted: "Restringida a los distritos" geozone_restricted: "Restringida a los distritos"
new: new:
title: "Nueva votación" title: "Nueva votación"
show_results_and_stats: "Mostrar resultados y estadísticas"
show_results: "Mostrar resultados"
show_stats: "Mostrar estadísticas"
results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas de esta votación serán públicos y podrán verlos todos los usuarios."
submit_button: "Crear votación" submit_button: "Crear votación"
edit: edit:
title: "Editar votación" title: "Editar votación"
@@ -668,6 +681,7 @@ es:
add_booth: "Añadir urna" add_booth: "Añadir urna"
name: "Nombre" name: "Nombre"
location: "Ubicación" location: "Ubicación"
no_location: "Sin Ubicación"
new: new:
title: "Nueva urna" title: "Nueva urna"
name: "Nombre" name: "Nombre"

View File

@@ -275,10 +275,12 @@ Rails.application.routes.draw do
scope module: :poll do scope module: :poll do
resources :polls do resources :polls do
get :booth_assignments, on: :collection
patch :add_question, on: :member patch :add_question, on: :member
resources :booth_assignments, only: [:index, :show, :create, :destroy] do resources :booth_assignments, only: [:index, :show, :create, :destroy] do
get :search_booths, on: :collection get :search_booths, on: :collection
get :manage, on: :collection
end end
resources :officer_assignments, only: [:index, :create, :destroy] do resources :officer_assignments, only: [:index, :create, :destroy] do

View File

@@ -0,0 +1,6 @@
class AddResultsAndStatsToPolls < ActiveRecord::Migration
def change
add_column :polls, :results_enabled, :boolean, default: false
add_column :polls, :stats_enabled, :boolean, default: false
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171019095042) do ActiveRecord::Schema.define(version: 20171020163240) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -486,10 +486,6 @@ ActiveRecord::Schema.define(version: 20171019095042) do
t.boolean "draft_publication_enabled", default: false t.boolean "draft_publication_enabled", default: false
t.boolean "result_publication_enabled", default: false t.boolean "result_publication_enabled", default: false
t.boolean "published", default: true t.boolean "published", default: true
t.date "proposals_phase_start_date"
t.date "proposals_phase_end_date"
t.boolean "proposals_phase_enabled"
t.text "proposals_description"
end end
add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree
@@ -502,36 +498,6 @@ ActiveRecord::Schema.define(version: 20171019095042) do
add_index "legislation_processes", ["result_publication_date"], name: "index_legislation_processes_on_result_publication_date", using: :btree add_index "legislation_processes", ["result_publication_date"], name: "index_legislation_processes_on_result_publication_date", using: :btree
add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree
create_table "legislation_proposals", force: :cascade do |t|
t.integer "legislation_process_id"
t.string "title", limit: 80
t.text "description"
t.string "question"
t.string "external_url"
t.integer "author_id"
t.datetime "hidden_at"
t.integer "flags_count", default: 0
t.datetime "ignored_flag_at"
t.integer "cached_votes_up", default: 0
t.integer "comments_count", default: 0
t.datetime "confirmed_hide_at"
t.integer "hot_score", limit: 8, default: 0
t.integer "confidence_score", default: 0
t.string "responsible_name", limit: 60
t.text "summary"
t.string "video_url"
t.tsvector "tsv"
t.integer "geozone_id"
t.datetime "retired_at"
t.string "retired_reason"
t.text "retired_explanation"
t.integer "community_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree
create_table "legislation_question_options", force: :cascade do |t| create_table "legislation_question_options", force: :cascade do |t|
t.integer "legislation_question_id" t.integer "legislation_question_id"
t.string "value" t.string "value"
@@ -794,6 +760,8 @@ ActiveRecord::Schema.define(version: 20171019095042) do
t.integer "comments_count", default: 0 t.integer "comments_count", default: 0
t.integer "author_id" t.integer "author_id"
t.datetime "hidden_at" t.datetime "hidden_at"
t.boolean "results_enabled", default: false
t.boolean "stats_enabled", default: false
end end
add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree
@@ -960,13 +928,9 @@ ActiveRecord::Schema.define(version: 20171019095042) do
t.integer "spending_proposals_count", default: 0 t.integer "spending_proposals_count", default: 0
t.string "kind" t.string "kind"
t.integer "budget/investments_count", default: 0 t.integer "budget/investments_count", default: 0
t.integer "legislation/proposals_count", default: 0
t.integer "legislation/processes_count", default: 0
end end
add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree
add_index "tags", ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count", using: :btree
add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree
add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree
@@ -1144,7 +1108,6 @@ ActiveRecord::Schema.define(version: 20171019095042) do
add_foreign_key "identities", "users" add_foreign_key "identities", "users"
add_foreign_key "images", "users" add_foreign_key "images", "users"
add_foreign_key "legislation_draft_versions", "legislation_processes" add_foreign_key "legislation_draft_versions", "legislation_processes"
add_foreign_key "legislation_proposals", "legislation_processes"
add_foreign_key "locks", "users" add_foreign_key "locks", "users"
add_foreign_key "managers", "users" add_foreign_key "managers", "users"
add_foreign_key "moderators", "users" add_foreign_key "moderators", "users"

View File

@@ -7,55 +7,31 @@ feature 'Admin booths assignments' do
login_as(admin.user) login_as(admin.user)
end end
scenario 'Assign booth to poll', :js do feature 'Admin Booth Assignment management' do
poll = create(:poll)
booth = create(:poll_booth)
visit admin_poll_path(poll) let!(:poll) { create(:poll) }
within('#poll-resources') do let!(:booth) { create(:poll_booth) }
click_link 'Booths (0)'
scenario 'List Polls and Booths to manage', :js do
second_poll = create(:poll)
second_booth = create(:poll_booth)
visit booth_assignments_admin_polls_path
expect(page).to have_content(poll.name)
expect(page).to have_content(second_poll.name)
within("#poll_#{second_poll.id}") do
click_link 'Manage assignments'
end end
expect(page).to have_content 'There are no booths assigned to this poll.' expect(page).to have_content "Assignments for poll '#{second_poll.name}'"
fill_in 'search-booths', with: booth.name
click_button 'Search'
expect(page).to have_content(booth.name) expect(page).to have_content(booth.name)
expect(page).to have_content(second_booth.name)
within('#search-booths-results') do
click_link 'Assign booth'
end end
expect(page).to have_content 'Booth assigned' scenario 'Assign booth to poll', :js do
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
end
expect(page).to_not have_content 'There are no booths assigned to this poll.'
expect(page).to have_content booth.name
end
scenario 'Remove booth from poll', :js do
poll = create(:poll)
booth = create(:poll_booth)
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
end
expect(page).to_not have_content 'There are no booths assigned to this poll.'
expect(page).to have_content booth.name
within("#poll_booth_assignment_#{assignment.id}") do
click_link 'Remove booth from poll'
end
expect(page).to have_content 'Booth not assigned anymore'
visit admin_poll_path(poll) visit admin_poll_path(poll)
within('#poll-resources') do within('#poll-resources') do
click_link 'Booths (0)' click_link 'Booths (0)'
@@ -63,10 +39,77 @@ feature 'Admin booths assignments' do
expect(page).to have_content 'There are no booths assigned to this poll.' expect(page).to have_content 'There are no booths assigned to this poll.'
expect(page).to_not have_content booth.name expect(page).to_not have_content booth.name
fill_in 'search-booths', with: booth.name
click_button 'Search'
expect(page).to have_content(booth.name)
visit manage_admin_poll_booth_assignments_path(poll)
expect(page).to have_content "Assignments for poll '#{poll.name}'"
within("#poll_booth_#{booth.id}") do
expect(page).to have_content(booth.name)
expect(page).to have_content "Unassigned"
click_link 'Assign booth'
expect(page).not_to have_content "Unassigned"
expect(page).to have_content "Assigned"
expect(page).to have_link "Unassign booth"
end
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
end
expect(page).to_not have_content 'There are no booths assigned to this poll.'
expect(page).to have_content booth.name
end
scenario 'Unassign booth from poll', :js do
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (1)'
end
expect(page).not_to have_content 'There are no booths assigned to this poll.'
expect(page).to have_content booth.name
fill_in 'search-booths', with: booth.name
click_button 'Search'
expect(page).to have_content(booth.name)
visit manage_admin_poll_booth_assignments_path(poll)
expect(page).to have_content "Assignments for poll '#{poll.name}'"
within("#poll_booth_#{booth.id}") do
expect(page).to have_content(booth.name)
expect(page).to have_content "Assigned"
click_link 'Unassign booth'
expect(page).to have_content "Unassigned"
expect(page).not_to have_content "Assigned"
expect(page).to have_link "Assign booth"
end
visit admin_poll_path(poll)
within('#poll-resources') do
click_link 'Booths (0)'
end
expect(page).to have_content 'There are no booths assigned to this poll.'
expect(page).not_to have_content booth.name
end
end end
feature 'Show' do feature 'Show' do
scenario 'Lists all assigned poll oficers' do scenario 'Lists all assigned poll officers' do
poll = create(:poll) poll = create(:poll)
booth = create(:poll_booth) booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)

View File

@@ -60,6 +60,10 @@ feature 'Admin polls' do
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..." fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..."
fill_in 'poll_description', with: "Upcomming poll's description. This poll..." fill_in 'poll_description', with: "Upcomming poll's description. This poll..."
expect(page).to_not have_css("#poll_results_enabled")
expect(page).to_not have_css("#poll_stats_enabled")
click_button "Create poll" click_button "Create poll"
expect(page).to have_content "Poll created successfully" expect(page).to have_content "Poll created successfully"
@@ -79,14 +83,25 @@ feature 'Admin polls' do
expect(page).to have_css("img[alt='#{poll.image.title}']") expect(page).to have_css("img[alt='#{poll.image.title}']")
expect(page).to have_css("#poll_results_enabled")
expect(page).to have_css("#poll_stats_enabled")
fill_in "poll_name", with: "Next Poll" fill_in "poll_name", with: "Next Poll"
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
check 'poll_results_enabled'
check 'poll_stats_enabled'
click_button "Update poll" click_button "Update poll"
expect(page).to have_content "Poll updated successfully" expect(page).to have_content "Poll updated successfully"
expect(page).to have_content "Next Poll" expect(page).to have_content "Next Poll"
expect(page).to have_content I18n.l(end_date.to_date) expect(page).to have_content I18n.l(end_date.to_date)
click_link "Edit poll"
expect(page).to have_field('poll_results_enabled', checked: true)
expect(page).to have_field('poll_stats_enabled', checked: true)
end end
scenario 'Edit from index' do scenario 'Edit from index' do

View File

@@ -55,7 +55,22 @@ feature 'Poll Officing' do
expect(page).to have_content "You do not have permission to access this page" expect(page).to have_content "You do not have permission to access this page"
end end
scenario 'Access as an poll officer is authorized' do scenario 'Access as an administrator is not authorized' do
create(:administrator, user: user)
create(:poll)
login_as(user)
visit root_path
expect(page).to_not have_link("Polling officers")
visit officing_root_path
expect(current_path).not_to eq(officing_root_path)
expect(current_path).to eq(root_path)
expect(page).to have_content "You do not have permission to access this page"
end
scenario 'Access as an administrator with poll officer role is authorized' do
create(:administrator, user: user)
create(:poll_officer, user: user) create(:poll_officer, user: user)
create(:poll) create(:poll)
login_as(user) login_as(user)
@@ -68,8 +83,8 @@ feature 'Poll Officing' do
expect(page).to_not have_content "You do not have permission to access this page" expect(page).to_not have_content "You do not have permission to access this page"
end end
scenario 'Access as an administrator is authorized' do scenario 'Access as an poll officer is authorized' do
create(:administrator, user: user) create(:poll_officer, user: user)
create(:poll) create(:poll)
login_as(user) login_as(user)
visit root_path visit root_path