From 5d13bdc15dd65fce32ec2cdf95a96a0db2a415b1 Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 29 Jan 2017 22:25:10 +0100 Subject: [PATCH 1/7] Removes 'manage' from admin permissions in Polls --- app/models/abilities/administrator.rb | 4 ++-- spec/features/admin/poll/booth_assigments_spec.rb | 3 ++- spec/models/abilities/administrator_spec.rb | 3 --- 3 files changed, 4 insertions(+), 6 deletions(-) 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/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/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) } From e39447063495a824dd173638e89acae1a23e19aa Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 29 Jan 2017 22:52:13 +0100 Subject: [PATCH 2/7] Improves order of polls when listing them in index --- app/models/poll.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index c5da9dcd0..1ac73e837 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 From 55ace74c674d409c0ee6f7623b8cce1401bde6f2 Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 29 Jan 2017 22:53:05 +0100 Subject: [PATCH 3/7] Shows geozones when listing polls --- app/controllers/polls_controller.rb | 2 +- app/views/polls/index.html.erb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ce80f8dcc..b77ac22ea 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -5,7 +5,7 @@ class PollsController < ApplicationController has_filters %w{current expired incoming} 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 diff --git a/app/views/polls/index.html.erb b/app/views/polls/index.html.erb index bba805ebb..ad37e4687 100644 --- a/app/views/polls/index.html.erb +++ b/app/views/polls/index.html.erb @@ -21,6 +21,11 @@

<%= poll.name %>

<%= poll_dates(poll) %>

+
    + <% poll.geozones.each do |g| %> +
  • <%= g.name %>
  • + <% end %> +
<%= link_to t("polls.index.button"), From 964da1e6d687d973bf66adebdf8f8f44cdd6e76e Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 29 Jan 2017 22:53:32 +0100 Subject: [PATCH 4/7] Fixes rails autoloader error in development --- app/controllers/polls_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index b77ac22ea..41a038b46 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -4,6 +4,8 @@ class PollsController < ApplicationController has_filters %w{current expired incoming} + ::Poll::Answer # trigger autoload + def index @polls = @polls.send(@current_filter).includes(:geozones).sort_for_list.page(params[:page]) end @@ -12,7 +14,7 @@ class PollsController < ApplicationController @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 From b2a43d84504f1fbeddedc62893e66dffe5852058 Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 29 Jan 2017 22:53:58 +0100 Subject: [PATCH 5/7] Extracts list of reasons to a partial --- .../polls/_reasons_for_not_answering.html.erb | 24 ++++++++++++++++++ app/views/polls/questions/show.html.erb | 25 +------------------ 2 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 app/views/polls/_reasons_for_not_answering.html.erb 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/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 %>
From c1345a1f7d21e0e0739c4c1e14f26be2bc4abe92 Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 29 Jan 2017 22:54:30 +0100 Subject: [PATCH 6/7] Includes reason for not being able to participate in poll index --- app/views/polls/index.html.erb | 10 ++++++---- config/locales/en.yml | 3 ++- config/locales/es.yml | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/views/polls/index.html.erb b/app/views/polls/index.html.erb index ad37e4687..e23fc81ee 100644 --- a/app/views/polls/index.html.erb +++ b/app/views/polls/index.html.erb @@ -28,10 +28,12 @@
- <%= 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/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." From 01039c00e394be44deddd7b3151d3a66bee8cb4f Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 30 Jan 2017 12:58:02 +0100 Subject: [PATCH 7/7] fixes failing spec --- spec/features/polls/polls_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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