diff --git a/app/controllers/admin/poll/officers_controller.rb b/app/controllers/admin/poll/officers_controller.rb
new file mode 100644
index 000000000..5495d390c
--- /dev/null
+++ b/app/controllers/admin/poll/officers_controller.rb
@@ -0,0 +1,32 @@
+class Admin::Poll::OfficersController < Admin::BaseController
+ load_and_authorize_resource :officer, class: "Poll::Officer"
+
+ def index
+ @officers = @officers.page(params[:page])
+ end
+
+ def search
+ @user = User.find_by(email: params[:email])
+
+ respond_to do |format|
+ if @user
+ @officer = Poll::Officer.find_or_initialize_by(user: @user)
+ format.js
+ else
+ format.js { render "user_not_found" }
+ end
+ end
+ end
+
+ def create
+ @officer.user_id = params[:user_id]
+ @officer.save
+
+ redirect_to admin_poll_officers_path
+ end
+
+ def destroy
+ @officer.destroy
+ redirect_to admin_poll_officers_path
+ end
+end
\ No newline at end of file
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb
index 515a54deb..39ab74b96 100644
--- a/app/helpers/admin_helper.rb
+++ b/app/helpers/admin_helper.rb
@@ -19,7 +19,7 @@ module AdminHelper
private
def namespace
- controller.class.parent.name.downcase
+ controller.class.parent.name.downcase.gsub("::", "/")
end
end
diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index 0dfce6d3e..0f1100137 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -38,6 +38,7 @@ module Abilities
can [:search, :create, :index, :destroy], ::Moderator
can [:search, :create, :index, :summary], ::Valuator
can [:search, :create, :index, :destroy], ::Manager
+ can [:search, :create, :index, :destroy], ::Poll::Officer
can :manage, Annotation
diff --git a/app/models/poll.rb b/app/models/poll.rb
new file mode 100644
index 000000000..d815cba49
--- /dev/null
+++ b/app/models/poll.rb
@@ -0,0 +1,2 @@
+class Poll < ActiveRecord::Base
+end
\ No newline at end of file
diff --git a/app/models/poll/officer.rb b/app/models/poll/officer.rb
new file mode 100644
index 000000000..d6fe5730a
--- /dev/null
+++ b/app/models/poll/officer.rb
@@ -0,0 +1,8 @@
+class Poll
+ class Officer < ActiveRecord::Base
+ belongs_to :user
+ delegate :name, :email, to: :user
+
+ validates :user_id, presence: true, uniqueness: true
+ end
+end
\ No newline at end of file
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb
index 7ea48b2c6..40bcc6330 100644
--- a/app/views/admin/_menu.html.erb
+++ b/app/views/admin/_menu.html.erb
@@ -83,6 +83,12 @@
<% end %>
+
>
+ <%= link_to admin_poll_officers_path do %>
+ <%= t('admin.menu.poll_officers') %>
+ <% end %>
+
+
>
<%= link_to admin_activity_path do %>
<%= t('admin.menu.activity') %>
diff --git a/app/views/admin/poll/_menu.html.erb b/app/views/admin/poll/_menu.html.erb
new file mode 100644
index 000000000..08efd87dc
--- /dev/null
+++ b/app/views/admin/poll/_menu.html.erb
@@ -0,0 +1 @@
+<%= render "admin/menu" %>
\ No newline at end of file
diff --git a/app/views/admin/poll/officers/_officer.html.erb b/app/views/admin/poll/officers/_officer.html.erb
new file mode 100644
index 000000000..c9251548d
--- /dev/null
+++ b/app/views/admin/poll/officers/_officer.html.erb
@@ -0,0 +1,26 @@
+
+
+
+
+ |
+ <%= officer.name %>
+ |
+
+ <%= officer.email %>
+ |
+
+ <% if officer.persisted? %>
+ <%= link_to t('admin.poll_officers.officer.delete'),
+ admin_poll_officer_path(officer),
+ method: :delete,
+ class: "button hollow alert" %>
+ <% else %>
+ <%= link_to t('admin.poll_officers.officer.add'),{ controller: "admin/poll/officers", action: :create, user_id: officer.user_id },
+ method: :post,
+ class: "button success" %>
+ <% end %>
+ |
+
+
+
+
diff --git a/app/views/admin/poll/officers/index.html.erb b/app/views/admin/poll/officers/index.html.erb
new file mode 100644
index 000000000..c330741af
--- /dev/null
+++ b/app/views/admin/poll/officers/index.html.erb
@@ -0,0 +1,46 @@
+<%= t("admin.poll_officers.index.title") %>
+
+
+ <%= form_tag search_admin_poll_officers_path, method: :get, remote: true do %>
+
+ <%= text_field_tag :email, '', placeholder: t('admin.poll_officers.search.email_placeholder') %>
+
+
+ <%= submit_tag t('admin.poll_officers.search.search'), class: 'button' %>
+
+ <% end %>
+
+
+
+
+<%= page_entries_info @officers %>
+
+
+ <% @officers.each do |officer| %>
+
+ |
+ <%= officer.name %>
+ |
+
+ <%= officer.email %>
+ |
+
+ <% if officer.persisted? %>
+ <%= link_to t('admin.poll_officers.officer.delete'),
+ admin_poll_officer_path(officer),
+ method: :delete,
+ class: "button hollow alert"
+ %>
+ <% else %>
+ <%= link_to t('admin.poll_officers.officer.add'),
+ { controller: "admin/poll/officers", action: :create,
+ user_id: officer.user_id },
+ method: :post,
+ class: "button success" %>
+ <% end %>
+ |
+
+ <% end %>
+
+
+<%= paginate @officers %>
diff --git a/app/views/admin/poll/officers/search.js.erb b/app/views/admin/poll/officers/search.js.erb
new file mode 100644
index 000000000..bd259f7fb
--- /dev/null
+++ b/app/views/admin/poll/officers/search.js.erb
@@ -0,0 +1 @@
+$("#search-result").html("<%= j render 'officer', officer: @officer %>");
diff --git a/app/views/admin/poll/officers/user_not_found.js.erb b/app/views/admin/poll/officers/user_not_found.js.erb
new file mode 100644
index 000000000..108f75295
--- /dev/null
+++ b/app/views/admin/poll/officers/user_not_found.js.erb
@@ -0,0 +1 @@
+$("#search-result").html("<%= j t('admin.officers.search.user_not_found') %>
");
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 2f73f64d8..97723c9c8 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -105,6 +105,7 @@ en:
managers: Managers
moderators: Moderators
valuators: Valuators
+ poll_officers: Poll officers
officials: Officials
organizations: Organisations
settings: Configuration settings
@@ -140,6 +141,16 @@ en:
in_evaluation_count: In evaluation
total_count: Total
cost: Cost
+ poll_officers:
+ index:
+ title: Poll officers
+ officer:
+ add: Add
+ delete: Delete
+ search:
+ email_placeholder: Search user by email
+ search: Search
+ user_not_found: User not found
officials:
edit:
destroy: Remove 'Official' status
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 5aada1ce1..f71293208 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -103,6 +103,7 @@ es:
managers: Gestores
moderators: Moderadores
valuators: Evaluadores
+ poll_officers: Presidentes de mesa
officials: Cargos públicos
organizations: Organizaciones
settings: Configuración global
@@ -138,6 +139,16 @@ es:
in_evaluation_count: En evaluación
total_count: Total
cost: Coste total
+ poll_officers:
+ index:
+ title: Presidentes de mesa
+ officer:
+ add: Añadir como Presidente de mesa
+ delete: Borrar
+ search:
+ email_placeholder: Buscar usuario por email
+ search: Buscar
+ user_not_found: Usuario no encontrado
officials:
edit:
destroy: Eliminar condición de 'Cargo Público'
diff --git a/config/routes.rb b/config/routes.rb
index df1a7c6fb..1821537e5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -179,6 +179,12 @@ Rails.application.routes.draw do
get :search, on: :collection
end
+ namespace :poll do
+ resources :officers, only: [:index, :create, :destroy] do
+ get :search, on: :collection
+ end
+ end
+
resources :verifications, controller: :verifications, only: :index do
get :search, on: :collection
end
diff --git a/db/migrate/20160914110004_create_polls.rb b/db/migrate/20160914110004_create_polls.rb
new file mode 100644
index 000000000..9dd67d9ba
--- /dev/null
+++ b/db/migrate/20160914110004_create_polls.rb
@@ -0,0 +1,7 @@
+class CreatePolls < ActiveRecord::Migration
+ def change
+ create_table :polls do |t|
+ t.string :name
+ end
+ end
+end
diff --git a/db/migrate/20160914110039_create_poll_officers.rb b/db/migrate/20160914110039_create_poll_officers.rb
new file mode 100644
index 000000000..329220d40
--- /dev/null
+++ b/db/migrate/20160914110039_create_poll_officers.rb
@@ -0,0 +1,7 @@
+class CreatePollOfficers < ActiveRecord::Migration
+ def change
+ create_table :poll_officers do |t|
+ t.integer :user_id
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a93942873..cfaf2a871 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -270,6 +270,14 @@ ActiveRecord::Schema.define(version: 20161102133838) do
add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree
+ create_table "poll_officers", force: :cascade do |t|
+ t.integer "user_id"
+ end
+
+ create_table "polls", force: :cascade do |t|
+ t.string "name"
+ end
+
create_table "proposal_notifications", force: :cascade do |t|
t.string "title"
t.text "body"
diff --git a/spec/factories.rb b/spec/factories.rb
index 13371a504..cd9b2c7fd 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -263,6 +263,10 @@ FactoryGirl.define do
user
end
+ factory :poll_officer, class: 'Poll::Officer' do
+ user
+ end
+
factory :organization do
user
responsible_name "Johnny Utah"
diff --git a/spec/features/admin/poll/officers_spec.rb b/spec/features/admin/poll/officers_spec.rb
new file mode 100644
index 000000000..ed9ec545d
--- /dev/null
+++ b/spec/features/admin/poll/officers_spec.rb
@@ -0,0 +1,36 @@
+require 'rails_helper'
+
+feature 'Admin poll officers' do
+ background do
+ @admin = create(:administrator)
+ @user = create(:user, username: 'Pedro Jose Garcia')
+ @officer = create(:poll_officer)
+ login_as(@admin.user)
+ visit admin_poll_officers_path
+ end
+
+ scenario 'Index' do
+ expect(page).to have_content @officer.name
+ expect(page).to have_content @officer.email
+ expect(page).to_not have_content @user.name
+ end
+
+ scenario 'Create poll officer', :js do
+ fill_in 'email', with: @user.email
+ click_button 'Search'
+
+ expect(page).to have_content @user.name
+ click_link 'Add'
+ within("#officers") do
+ expect(page).to have_content @user.name
+ end
+ end
+
+ scenario 'Delete poll officer' do
+ click_link 'Delete'
+
+ within("#officers") do
+ expect(page).to_not have_content @officer.name
+ end
+ end
+end
\ No newline at end of file