diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ce80f8dcc..41a038b46 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -4,15 +4,17 @@ class PollsController < ApplicationController has_filters %w{current expired incoming} + ::Poll::Answer # trigger autoload + def index - @polls = @polls.send(@current_filter).sort_for_list.page(params[:page]) + @polls = @polls.send(@current_filter).includes(:geozones).sort_for_list.page(params[:page]) end def show @questions = @poll.questions.for_render.sort_for_list @answers_by_question_id = {} - poll_answers = Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id)) + poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id)) poll_answers.each do |answer| @answers_by_question_id[answer.question_id] = answer.answer end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index a45eef73e..34adac19b 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -53,8 +53,8 @@ module Abilities can [:index, :create, :edit, :update, :destroy], Geozone - can [:manage], Poll - can [:manage], Poll::Booth + can [:read, :create, :update, :destroy, :add_question, :remove_question, :search_booths, :search_questions, :search_officers], Poll + can [:read, :create, :update, :destroy], Poll::Booth can [:search, :create, :index, :destroy], ::Poll::Officer can [:create, :destroy], ::Poll::BoothAssignment can [:create, :destroy], ::Poll::OfficerAssignment diff --git a/app/models/poll.rb b/app/models/poll.rb index 761a4561f..6acb5af03 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -18,7 +18,7 @@ class Poll < ActiveRecord::Base scope :published, -> { where('published = ?', true) } scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) } - scope :sort_for_list, -> { order(:starts_at) } + scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) } def current?(timestamp = DateTime.current) starts_at <= timestamp && timestamp <= ends_at diff --git a/app/views/polls/_reasons_for_not_answering.html.erb b/app/views/polls/_reasons_for_not_answering.html.erb new file mode 100644 index 000000000..374d319d9 --- /dev/null +++ b/app/views/polls/_reasons_for_not_answering.html.erb @@ -0,0 +1,24 @@ +<% if poll.incoming? %> +
+ <%= t('poll_questions.show.cant_answer_incoming') %> +
+<% elsif poll.expired? %> +
+ <%= t('poll_questions.show.cant_answer_expired') %> +
+<% elsif current_user.nil? %> +
+ <%= t("poll_questions.show.not_logged_in", + signin: link_to(t("poll_questions.show.signin"), new_user_session_path, class: "probe-message"), + signup: link_to(t("poll_questions.show.signup"), new_user_registration_path, class: "probe-message")).html_safe %> +
+<% elsif current_user.unverified? %> +
+ <%= t('poll_questions.show.cant_answer_verify_html', + verify_link: link_to(t('poll_questions.show.verify_link'), verification_path)) %> +
+<% else %> +
+ <%= t('poll_questions.show.cant_answer_wrong_geozone') %> +
+<% end %> diff --git a/app/views/polls/index.html.erb b/app/views/polls/index.html.erb index bba805ebb..e23fc81ee 100644 --- a/app/views/polls/index.html.erb +++ b/app/views/polls/index.html.erb @@ -21,12 +21,19 @@

<%= poll.name %>

<%= poll_dates(poll) %>

+
- <%= link_to t("polls.index.button"), - poll, - class: "button", - title: t("polls.index.button") + ": " + (poll.name) %> + <% if can? :answer, poll %> + <%= link_to t("polls.index.participate_button"), poll, class: "button" %> + <% else %> + <%= render 'polls/reasons_for_not_answering', poll: poll %> + <%= link_to t("polls.index.view_button"), poll, class: "button info small" %> + <% end %>
diff --git a/app/views/polls/questions/show.html.erb b/app/views/polls/questions/show.html.erb index c04490f7d..f743d89a9 100644 --- a/app/views/polls/questions/show.html.erb +++ b/app/views/polls/questions/show.html.erb @@ -54,30 +54,7 @@ %> <% else %> - <% if @question.poll.incoming? %> -
- <%= t('poll_questions.show.cant_answer_incoming') %> -
- <% elsif @question.poll.expired? %> -
- <%= t('poll_questions.show.cant_answer_expired') %> -
- <% elsif current_user.nil? %> -
- <%= t("poll_questions.show.not_logged_in", - signin: link_to(t("poll_questions.show.signin"), new_user_session_path, class: "probe-message"), - signup: link_to(t("poll_questions.show.signup"), new_user_registration_path, class: "probe-message")).html_safe %> -
- <% elsif current_user.unverified? %> -
- <%= t('poll_questions.show.cant_answer_verify_html', - verify_link: link_to(t('poll_questions.show.verify_link'), verification_path)) %> -
- <% else %> -
- <%= t('poll_questions.show.cant_answer_wrong_geozone') %> -
- <% end %> + <%= render 'polls/reasons_for_not_answering', poll: @question.poll %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index b778c4166..a5b671809 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -401,7 +401,8 @@ en: incoming: "Incoming" expired: "Expired" title: "Polls" - button: "Participate in this poll" + participate_button: "Participate in this poll" + view_button: "View details about this poll" show: dates_title: "Participation dates" cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate." diff --git a/config/locales/es.yml b/config/locales/es.yml index abbe23ddf..388cbbbe7 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -401,7 +401,8 @@ es: incoming: "Próximamente" expired: "Terminadas" title: "Votaciones" - button: "Participar en esta votación" + participate_button: "Participar en esta votación" + view_button: "Ver detalles de la votación" show: dates_title: "Fechas de participación" cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar." diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index 28d612257..14a8ba1e1 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -20,6 +20,7 @@ feature 'Admin booths assignments' do fill_in 'search-booths', with: booth.name click_button 'Search' + expect(page).to have_content(booth.name) within('#search-booths-results') do click_link 'Assign booth' @@ -167,4 +168,4 @@ feature 'Admin booths assignments' do end end -end \ No newline at end of file +end diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index fe5957181..7293d6682 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -11,7 +11,7 @@ feature 'Polls' do polls.each do |poll| expect(page).to have_content(poll.name) - expect(page).to have_link("Participate in this poll") + expect(page).to have_link("View details about this poll") end end diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index c368667dd..5312221b8 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -57,9 +57,6 @@ describe "Abilities::Administrator" do it { should be_able_to(:valuate, SpendingProposal) } it { should be_able_to(:destroy, SpendingProposal) } - it { should be_able_to(:manage, Poll) } - it { should be_able_to(:manage, Poll::Booth) } - it { should be_able_to(:create, Budget) } it { should be_able_to(:update, Budget) }