From 142c981cdfcf5bb3288ed5327e756b9562c8173d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 12:51:58 +0100 Subject: [PATCH 01/36] adds ability to level 2 users to delete owned sps --- app/models/abilities/common.rb | 3 ++- spec/models/abilities/common_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 002518dac..92eacea52 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -25,7 +25,7 @@ module Abilities can :suggest, Debate can :suggest, Proposal - + can [:flag, :unflag], Comment cannot [:flag, :unflag], Comment, user_id: user.id @@ -44,6 +44,7 @@ module Abilities can :vote, Proposal can :vote_featured, Proposal can :create, SpendingProposal + can :destroy, SpendingProposal, author_id: user.id end can :create, Annotation diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index d942e2d18..8c90f7cea 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -30,6 +30,7 @@ describe "Abilities::Common" do it { should be_able_to(:index, SpendingProposal) } it { should_not be_able_to(:create, SpendingProposal) } + it { should_not be_able_to(:destroy, SpendingProposal) } it { should_not be_able_to(:comment_as_administrator, debate) } it { should_not be_able_to(:comment_as_moderator, debate) } @@ -83,20 +84,26 @@ describe "Abilities::Common" do end describe "when level 2 verified" do + let(:own_spending_proposal) { create(:spending_proposal, author: user) } before{ user.update(residence_verified_at: Time.now, confirmed_phone: "1") } it { should be_able_to(:vote, Proposal) } it { should be_able_to(:vote_featured, Proposal) } it { should be_able_to(:create, SpendingProposal) } + it { should_not be_able_to(:destroy, create(:spending_proposal)) } + it { should be_able_to(:destroy, own_spending_proposal) } end describe "when level 3 verified" do + let(:own_spending_proposal) { create(:spending_proposal, author: user) } before{ user.update(verified_at: Time.now) } it { should be_able_to(:vote, Proposal) } it { should be_able_to(:vote_featured, Proposal) } it { should be_able_to(:create, SpendingProposal) } + it { should_not be_able_to(:destroy, create(:spending_proposal)) } + it { should be_able_to(:destroy, own_spending_proposal) } end end From c09e6f95d72b9341435bfc6f3bff6b83390fdc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 12:53:00 +0100 Subject: [PATCH 02/36] users can now delete their own spending proposals via the 'my activity' page --- .../spending_proposals_controller.rb | 6 ++++++ app/models/user.rb | 1 + app/views/users/_spending_proposals.html.erb | 12 ++++++++--- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/locales/responders.en.yml | 4 +++- config/locales/responders.es.yml | 4 +++- config/routes.rb | 2 +- spec/features/spending_proposals_spec.rb | 20 +++++++++++++++++++ spec/features/users_spec.rb | 18 ++++++++++++++++- 10 files changed, 64 insertions(+), 7 deletions(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 7e32b0a93..9b64c462d 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -28,6 +28,12 @@ class SpendingProposalsController < ApplicationController end end + def destroy + spending_proposal = current_user.spending_proposals.find(params[:id]) + spending_proposal.destroy + redirect_to user_path(current_user, filter: 'spending_proposals'), notice: t('flash.actions.destroy.spending_proposal') + end + private def spending_proposal_params diff --git a/app/models/user.rb b/app/models/user.rb index 3bf54b3ca..3b58fb607 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -20,6 +20,7 @@ class User < ActiveRecord::Base has_many :debates, -> { with_hidden }, foreign_key: :author_id has_many :proposals, -> { with_hidden }, foreign_key: :author_id has_many :comments, -> { with_hidden } + has_many :spending_proposals, foreign_key: :author_id has_many :failed_census_calls has_many :notifications belongs_to :geozone diff --git a/app/views/users/_spending_proposals.html.erb b/app/views/users/_spending_proposals.html.erb index 479688f86..491f5c831 100644 --- a/app/views/users/_spending_proposals.html.erb +++ b/app/views/users/_spending_proposals.html.erb @@ -1,10 +1,16 @@ - +
<% @spending_proposals.each do |spending_proposal| %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 468889c28..550225fa8 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -445,6 +445,8 @@ en: deleted: Deleted deleted_debate: This debate has been deleted deleted_proposal: This proposal has been deleted + delete_spending_proposal: Delete + confirm_deletion_spending_proposal: Are you sure? This action can not be undone filters: comments: one: 1 Comment diff --git a/config/locales/es.yml b/config/locales/es.yml index b9701cbf5..7e66e1c14 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -445,6 +445,8 @@ es: deleted: Eliminado deleted_debate: Este debate ha sido eliminado deleted_proposal: Este propuesta ha sido eliminada + delete_spending_proposal: Eliminar + confirm_deletion_spending_proposal: "¿Seguro que desea eliminar esta propuesta?" filters: comments: one: 1 Comentario diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml index 03a8f0ec8..3f83f746a 100755 --- a/config/locales/responders.en.yml +++ b/config/locales/responders.en.yml @@ -13,4 +13,6 @@ en: notice: "%{resource_name} updated successfully." debate: "Debate updated successfully." proposal: "Proposal updated successfully." - spending_proposal: "Investment project updated succesfully." \ No newline at end of file + spending_proposal: "Investment project updated succesfully." + destroy: + spending_proposal: "Spending proposal deleted succesfully." \ No newline at end of file diff --git a/config/locales/responders.es.yml b/config/locales/responders.es.yml index ee6e011f8..e57dacd31 100644 --- a/config/locales/responders.es.yml +++ b/config/locales/responders.es.yml @@ -13,4 +13,6 @@ es: notice: "%{resource_name} actualizado correctamente." debate: "Debate actualizado correctamente." proposal: "Propuesta actualizada correctamente." - spending_proposal: "Propuesta de inversión actualizada correctamente." \ No newline at end of file + spending_proposal: "Propuesta de inversión actualizada correctamente." + destroy: + spending_proposal: "Propuesta de inversión eliminada." \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f150db339..680f657ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,7 @@ Rails.application.routes.draw do end scope '/participatory_budget' do - resources :spending_proposals, only: [:index, :new, :create, :show], path: 'investment_projects' + resources :spending_proposals, only: [:index, :new, :create, :show, :destroy], path: 'investment_projects' end resources :stats, only: [:index] diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index 12d692fcf..0fd31f5f7 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -163,4 +163,24 @@ feature 'Spending proposals' do expect(page).to have_content("You do not have permission to access this page") end + context "Destroy" do + + scenario "User can destroy owned spending proposals" do + user = create(:user, :level_two) + spending_proposal = create(:spending_proposal, author: user) + login_as(user) + + visit user_path(user) + within("#spending_proposal_#{spending_proposal.id}") do + click_link "Delete" + end + + expect(page).to have_content("Spending proposal deleted succesfully.") + + visit user_path(user) + expect(page).not_to have_css("spending_proposal_list") + end + + end + end diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 4fbaf1937..fdb092856 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -203,7 +203,7 @@ feature 'Users' do background do @author = create(:user) - create(:spending_proposal, author: @author, title: 'Build a school') + @spending_proposal = create(:spending_proposal, author: @author, title: 'Build a school') end scenario 'is not shown if no user logged in' do @@ -240,6 +240,22 @@ feature 'Users' do expect(page).to have_content('Build a school') end + scenario 'delete button is shown if logged in user is author' do + login_as(@author) + visit user_path(@author) + within("#spending_proposal_#{@spending_proposal.id}") do + expect(page).to have_content('Delete') + end + end + + scenario 'delete button is not shown if logged in user is admin' do + login_as(create(:administrator).user) + visit user_path(@author) + within("#spending_proposal_#{@spending_proposal.id}") do + expect(page).to_not have_content('Delete') + end + end + end end From 5aa9cf9c50e6762a57ef0e25d0d101fe95879f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 13:17:29 +0100 Subject: [PATCH 03/36] changes links in 'My activity' to point to comment (instead of to commentable) Closes #947 --- app/helpers/users_helper.rb | 2 +- spec/helpers/users_helper_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 068c17b71..10da73712 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -20,7 +20,7 @@ module UsersHelper commentable.title + "".html_safe else - link_to(commentable.title, commentable) + link_to(commentable.title, comment) end end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 2094cea04..f1a72cd36 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -31,9 +31,9 @@ describe UsersHelper do end describe '#comment_commentable_title' do - it "should return a link to the commentable" do + it "should return a link to the comment" do comment = create(:comment) - expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment.commentable + expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment end it "should return a hint if the commentable has been deleted" do From 6ad7fca22d0d7a21cf8940c2582601f676b2e933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 13:17:46 +0100 Subject: [PATCH 04/36] corrects css ids --- app/views/users/_comments.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_comments.html.erb b/app/views/users/_comments.html.erb index 4a2ca5da7..25bd1fd5b 100644 --- a/app/views/users/_comments.html.erb +++ b/app/views/users/_comments.html.erb @@ -1,6 +1,6 @@
<%= link_to spending_proposal.title, spending_proposal %> -
- <%= spending_proposal.description %> + + <% if current_user && current_user.id == spending_proposal.author_id %> + <%= link_to t("users.show.delete_spending_proposal"), + spending_proposal, + method: :delete, + data: { confirm: t("users.show.confirm_deletion_spending_proposal") }, + class: 'button small warning' %> + <% end %>
<% @comments.each do |comment| %> - +
<%= comment_commentable_title(comment) %>
From decf0f2683357c9221e230796934bc65c4addafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 14:35:57 +0100 Subject: [PATCH 05/36] changes admin/valuator permissions not allowed to create/destroy spending proposals anymore --- app/models/abilities/administrator.rb | 2 +- app/models/abilities/valuator.rb | 2 +- spec/models/abilities/administrator_spec.rb | 4 +++- spec/models/abilities/valuator_spec.rb | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 49184c447..78cb60806 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -37,7 +37,7 @@ module Abilities can :manage, Annotation - can :manage, SpendingProposal + can [:read, :update], SpendingProposal end end end diff --git a/app/models/abilities/valuator.rb b/app/models/abilities/valuator.rb index edb542e4b..15add866a 100644 --- a/app/models/abilities/valuator.rb +++ b/app/models/abilities/valuator.rb @@ -3,7 +3,7 @@ module Abilities include CanCan::Ability def initialize(user) - can :manage, SpendingProposal + can [:read, :update, :valuate], SpendingProposal end end end \ No newline at end of file diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index 8df88a46f..b5ee78dd0 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -52,5 +52,7 @@ describe "Abilities::Administrator" do it { should be_able_to(:manage, Annotation) } - it { should be_able_to(:manage, SpendingProposal) } + it { should be_able_to(:read, SpendingProposal) } + it { should be_able_to(:update, SpendingProposal) } + it { should be_able_to(:valuate, SpendingProposal) } end diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb index d9542220d..ce108200c 100644 --- a/spec/models/abilities/valuator_spec.rb +++ b/spec/models/abilities/valuator_spec.rb @@ -6,5 +6,7 @@ describe "Abilities::Valuator" do let(:user) { valuator.user } let(:valuator) { create(:valuator) } - it { should be_able_to(:manage, SpendingProposal) } + it { should be_able_to(:read, SpendingProposal) } + it { should be_able_to(:update, SpendingProposal) } + it { should be_able_to(:valuate, SpendingProposal) } end From b660702787e64aebe246f99d65b20dcd72148543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 14:36:13 +0100 Subject: [PATCH 06/36] specifies permission the right way --- app/views/users/_spending_proposals.html.erb | 2 +- spec/features/users_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/_spending_proposals.html.erb b/app/views/users/_spending_proposals.html.erb index 491f5c831..04bfa7867 100644 --- a/app/views/users/_spending_proposals.html.erb +++ b/app/views/users/_spending_proposals.html.erb @@ -4,7 +4,7 @@
<%= link_to spending_proposal.title, spending_proposal %> - <% if current_user && current_user.id == spending_proposal.author_id %> + <% if can?(:destroy, spending_proposal) %> <%= link_to t("users.show.delete_spending_proposal"), spending_proposal, method: :delete, diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index fdb092856..eff63b18b 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -202,7 +202,7 @@ feature 'Users' do feature 'Spending proposals' do background do - @author = create(:user) + @author = create(:user, :level_two) @spending_proposal = create(:spending_proposal, author: @author, title: 'Build a school') end From 905136b9e033bdc792be320018811618b6a4526e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 13:17:29 +0100 Subject: [PATCH 07/36] changes links in 'My activity' to point to comment (instead of to commentable) Closes #947 --- app/helpers/users_helper.rb | 2 +- spec/helpers/users_helper_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 068c17b71..10da73712 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -20,7 +20,7 @@ module UsersHelper commentable.title + "".html_safe else - link_to(commentable.title, commentable) + link_to(commentable.title, comment) end end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 2094cea04..f1a72cd36 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -31,9 +31,9 @@ describe UsersHelper do end describe '#comment_commentable_title' do - it "should return a link to the commentable" do + it "should return a link to the comment" do comment = create(:comment) - expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment.commentable + expect(comment_commentable_title(comment)).to eq link_to comment.commentable.title, comment end it "should return a hint if the commentable has been deleted" do From 788ec7b09c1d6b22a256003f0d3861c8dddc62e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 14 Mar 2016 13:17:46 +0100 Subject: [PATCH 08/36] corrects css ids --- app/views/users/_comments.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_comments.html.erb b/app/views/users/_comments.html.erb index 4a2ca5da7..25bd1fd5b 100644 --- a/app/views/users/_comments.html.erb +++ b/app/views/users/_comments.html.erb @@ -1,6 +1,6 @@ <% @comments.each do |comment| %> - + <% if organization.verified? %> <% end %> @@ -42,7 +42,7 @@ <% end %> <% if organization.rejected? %> <% end %> diff --git a/app/views/admin/organizations/search.html.erb b/app/views/admin/organizations/search.html.erb index 877f5b6e6..9e90975ab 100644 --- a/app/views/admin/organizations/search.html.erb +++ b/app/views/admin/organizations/search.html.erb @@ -24,7 +24,7 @@ <% if organization.verified? %> <% end %> @@ -38,7 +38,7 @@ <% end %> <% if organization.rejected? %> <% end %> diff --git a/app/views/admin/spending_proposals/_written_by_author.html.erb b/app/views/admin/spending_proposals/_written_by_author.html.erb index 52331e987..8440666e5 100644 --- a/app/views/admin/spending_proposals/_written_by_author.html.erb +++ b/app/views/admin/spending_proposals/_written_by_author.html.erb @@ -36,7 +36,7 @@ <% end %> <% if @spending_proposal.external_url.present? %> -

<%= text_with_links @spending_proposal.external_url %> 

+

<%= text_with_links @spending_proposal.external_url %> 

<% end %> <%= safe_html_with_links @spending_proposal.description %> diff --git a/app/views/admin/spending_proposals/edit.html.erb b/app/views/admin/spending_proposals/edit.html.erb index 67160b926..1dcf5c109 100644 --- a/app/views/admin/spending_proposals/edit.html.erb +++ b/app/views/admin/spending_proposals/edit.html.erb @@ -1,5 +1,5 @@ <%= link_to admin_spending_proposal_path(@spending_proposal, SpendingProposal.filter_params(params)), class: 'back' do %> - <%= t("admin.spending_proposals.show.back") %> + <%= t("admin.spending_proposals.show.back") %> <% end %> <%= render 'written_by_author' %> diff --git a/app/views/admin/spending_proposals/show.html.erb b/app/views/admin/spending_proposals/show.html.erb index 750d8b257..bbcf4b4fc 100644 --- a/app/views/admin/spending_proposals/show.html.erb +++ b/app/views/admin/spending_proposals/show.html.erb @@ -1,5 +1,5 @@ <%= link_to admin_spending_proposals_path(SpendingProposal.filter_params(params)) do %> - <%= t("admin.spending_proposals.show.back") %> + <%= t("admin.spending_proposals.show.back") %> <% end %> <%= render 'written_by_author' %> diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index f73e581d5..3747fa15d 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -15,7 +15,7 @@ <%= image_tag("moderator_avatar.png", size: 32, class: "moderator-avatar float-left") %> <% else %> <% if comment.user.hidden? || comment.user.erased? %> - + <% elsif comment.user.organization? %> <%= image_tag("collective_avatar.png", size: 32, class: "avatar float-left") %> <% else %> @@ -74,7 +74,7 @@ <% if comment.children.size > 0 %> <%= link_to "", class: "js-toggle-children", data: {'id': "#{dom_id(comment)}"} do %> - <%= t("comments.comment.responses", count: comment.children.size) %> + <%= t("comments.comment.responses", count: comment.children.size) %> <% end %> <% else %> <%= t("comments.comment.responses", count: 0) %> diff --git a/app/views/comments/_flag_actions.html.erb b/app/views/comments/_flag_actions.html.erb index b7f0e6ef8..87698af06 100644 --- a/app/views/comments/_flag_actions.html.erb +++ b/app/views/comments/_flag_actions.html.erb @@ -4,7 +4,7 @@ - +
<%= comment_commentable_title(comment) %>
From f4f491748f2361a449b8dea3572b75831a1f922d Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 14 Mar 2016 15:00:49 +0100 Subject: [PATCH 09/36] adds tags to spending proposals in dev_seeds --- db/dev_seeds.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 14af135da..ac4695d0f 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -252,6 +252,8 @@ end puts "Creating Spending Proposals" +tags = Faker::Lorem.words(10) + (1..30).each do |i| geozone = Geozone.reorder("RANDOM()").first author = User.reorder("RANDOM()").first @@ -262,6 +264,7 @@ puts "Creating Spending Proposals" description: description, created_at: rand((Time.now - 1.week) .. Time.now), geozone: [geozone, nil].sample, + tag_list: tags.sample(3).join(','), terms_of_service: "1") puts " #{spending_proposal.title}" end @@ -295,4 +298,4 @@ puts "Confirming hiding in debates, comments & proposals" Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide) Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) -Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) \ No newline at end of file +Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) From 769780e2cd928dde0276c26030f984f41b787598 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 14 Mar 2016 16:15:13 +0100 Subject: [PATCH 10/36] Implements SpendingProposal.filter_params(params) --- app/models/spending_proposal.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 27842fa91..237da73f7 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -35,6 +35,10 @@ class SpendingProposal < ActiveRecord::Base super.try :html_safe end + def self.filter_params(params) + params.select{|x,_| %w{geozone_id administrator_id tag_name valuator_id}.include? x.to_s } + end + def self.search(params, current_filter) results = self results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present? From 11bcf375d2ef0869c3b0370621fd6ca602c637d4 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 14 Mar 2016 16:16:29 +0100 Subject: [PATCH 11/36] Uses SpendingProposal.filter_params in all admin views --- .../admin/spending_proposals/edit.html.erb | 23 ++++++++++--------- .../admin/spending_proposals/index.html.erb | 2 +- .../admin/spending_proposals/show.html.erb | 5 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/views/admin/spending_proposals/edit.html.erb b/app/views/admin/spending_proposals/edit.html.erb index 22510765a..a0fd82a3d 100644 --- a/app/views/admin/spending_proposals/edit.html.erb +++ b/app/views/admin/spending_proposals/edit.html.erb @@ -1,4 +1,4 @@ -<%= link_to admin_spending_proposals_path(@spending_proposal), class: 'back' do %> +<%= link_to admin_spending_proposals_path(@spending_proposal, SpendingProposal.filter_params(params)), class: 'back' do %> <%= t("admin.spending_proposals.show.back") %> <% end %> @@ -6,7 +6,12 @@

<%= t("admin.spending_proposals.edit.classification") %>

-<%= form_for @spending_proposal, url: admin_spending_proposal_path(@spending_proposal) do |f| %> +<%= form_for @spending_proposal, + url: admin_spending_proposal_path(@spending_proposal) do |f| %> + + <% SpendingProposal.filter_params(params).each do |filter_name, filter_value| %> + <%= hidden_field_tag filter_name, filter_value %> + <% end %> <%= f.select(:administrator_id, @admins.collect{ |a| [a.name_and_email, a.id ] }, @@ -24,15 +29,11 @@ placeholder: t("admin.spending_proposals.edit.tags_placeholder"), class: 'js-tag-list' %> -
- <%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %> + <%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %> - <%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %> -
- <%= b.label(title: b.object.name) { b.check_box + b.text } %> -
- <% end %> -
+ <%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %> + <%= b.label(title: b.object.name) { b.check_box + b.text } %> + <% end %>

<%= f.submit(class: "button", value: t("admin.spending_proposals.edit.submit_button")) %> @@ -41,4 +42,4 @@ <% end %>


-<%= render 'valuation/spending_proposals/written_by_valuators' %> \ No newline at end of file +<%= render 'valuation/spending_proposals/written_by_valuators' %> diff --git a/app/views/admin/spending_proposals/index.html.erb b/app/views/admin/spending_proposals/index.html.erb index 83903cc2e..f50dea628 100644 --- a/app/views/admin/spending_proposals/index.html.erb +++ b/app/views/admin/spending_proposals/index.html.erb @@ -37,7 +37,7 @@ <%= spending_proposal.id %>
- <%= link_to spending_proposal.title, admin_spending_proposal_path(spending_proposal) %> + <%= link_to spending_proposal.title, admin_spending_proposal_path(spending_proposal, SpendingProposal.filter_params(params)) %> <% if spending_proposal.administrator.present? %> diff --git a/app/views/admin/spending_proposals/show.html.erb b/app/views/admin/spending_proposals/show.html.erb index 187e53c63..750d8b257 100644 --- a/app/views/admin/spending_proposals/show.html.erb +++ b/app/views/admin/spending_proposals/show.html.erb @@ -1,4 +1,4 @@ -<%= link_to :back, class: 'back' do %> +<%= link_to admin_spending_proposals_path(SpendingProposal.filter_params(params)) do %> <%= t("admin.spending_proposals.show.back") %> <% end %> @@ -8,7 +8,8 @@

<%= link_to t("admin.spending_proposals.show.edit_classification"), - edit_admin_spending_proposal_path(@spending_proposal, anchor: "form") %> + edit_admin_spending_proposal_path(@spending_proposal, + {anchor: 'form'}.merge(SpendingProposal.filter_params(params))) %>

<%= t("admin.spending_proposals.show.assigned_admin") %>: From b44aad0798185068dd62dd165509c86e46d2a48c Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 14 Mar 2016 16:16:47 +0100 Subject: [PATCH 12/36] Uses SpendingProposal.filter_params in admin/sp controller --- app/controllers/admin/spending_proposals_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/spending_proposals_controller.rb b/app/controllers/admin/spending_proposals_controller.rb index 3ae4872db..afa24f54c 100644 --- a/app/controllers/admin/spending_proposals_controller.rb +++ b/app/controllers/admin/spending_proposals_controller.rb @@ -21,7 +21,10 @@ class Admin::SpendingProposalsController < Admin::BaseController def update if @spending_proposal.update(spending_proposal_params) - redirect_to admin_spending_proposal_path(@spending_proposal, anchor: 'classification'), notice: t("flash.actions.update.spending_proposal") + path = admin_spending_proposal_path( @spending_proposal, + { anchor: 'classification' }.merge(SpendingProposal.filter_params(params))) + + redirect_to path, notice: t("flash.actions.update.spending_proposal") else render :edit end From 072faf928f15067e995698f66895a43caaa5ae2b Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 14 Mar 2016 16:58:57 +0100 Subject: [PATCH 13/36] adds specs for preserving filtering params when using the admin links for spending proposals changes the order in which specs are executed for travis another change for travis another change for travis --- .../admin/spending_proposals/edit.html.erb | 2 +- .../features/admin/spending_proposals_spec.rb | 70 +++++++++++++++++-- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/app/views/admin/spending_proposals/edit.html.erb b/app/views/admin/spending_proposals/edit.html.erb index a0fd82a3d..67160b926 100644 --- a/app/views/admin/spending_proposals/edit.html.erb +++ b/app/views/admin/spending_proposals/edit.html.erb @@ -1,4 +1,4 @@ -<%= link_to admin_spending_proposals_path(@spending_proposal, SpendingProposal.filter_params(params)), class: 'back' do %> +<%= link_to admin_spending_proposal_path(@spending_proposal, SpendingProposal.filter_params(params)), class: 'back' do %> <%= t("admin.spending_proposals.show.back") %> <% end %> diff --git a/spec/features/admin/spending_proposals_spec.rb b/spec/features/admin/spending_proposals_spec.rb index 6530400c1..fcfec8638 100644 --- a/spec/features/admin/spending_proposals_spec.rb +++ b/spec/features/admin/spending_proposals_spec.rb @@ -66,11 +66,6 @@ feature 'Admin spending proposals' do expect(page).to have_link("Realocate visitors") expect(page).to have_link("Destroy the city") - select "District 9", from: "geozone_id" - - expect(page).to have_link("Realocate visitors") - expect(page).to_not have_link("Destroy the city") - select "All city", from: "geozone_id" expect(page).to have_link("Destroy the city") @@ -79,6 +74,28 @@ feature 'Admin spending proposals' do select "All zones", from: "geozone_id" expect(page).to have_link("Realocate visitors") expect(page).to have_link("Destroy the city") + + select "District 9", from: "geozone_id" + + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + click_link("Realocate visitors") + click_link("Back") + + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + click_link("Realocate visitors") + click_on("Edit classification") + expect(page).to have_button("Update") + click_on("Back") + expect(page).to_not have_button("Update") + click_on("Back") + + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + end scenario "Filtering by admin", :js do @@ -94,13 +111,36 @@ feature 'Admin spending proposals' do select "Admin 1", from: "administrator_id" - expect(page).to have_link("Realocate visitors") + expect(page).to have_content('There is 1 spending proposal') expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") select "All administrators", from: "administrator_id" + expect(page).to have_content('There are 2 spending proposals') expect(page).to have_link("Destroy the city") expect(page).to have_link("Realocate visitors") + + select "Admin 1", from: "administrator_id" + expect(page).to have_content('There is 1 spending proposal') + click_link("Realocate visitors") + click_link("Back") + + expect(page).to have_content('There is 1 spending proposal') + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + click_link("Realocate visitors") + click_on("Edit classification") + expect(page).to have_button("Update") + click_on("Back") + expect(page).to_not have_button("Update") + click_on("Back") + + expect(page).to have_content('There is 1 spending proposal') + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + end scenario "Current filter is properly highlighted" do @@ -183,10 +223,28 @@ feature 'Admin spending proposals' do visit admin_spending_proposals_path(tag_name: 'Education') + expect(page).to_not have_content("More hospitals") expect(page).to have_css(".spending_proposal", count: 2) expect(page).to have_content("Educate the children") expect(page).to have_content("More schools") + + click_link("Educate the children") + click_link("Back") + expect(page).to_not have_content("More hospitals") + expect(page).to have_content("Educate the children") + expect(page).to have_content("More schools") + + click_link("Educate the children") + click_on("Edit classification") + expect(page).to have_button("Update") + click_on("Back") + expect(page).to_not have_button("Update") + click_on("Back") + + expect(page).to_not have_content("More hospitals") + expect(page).to have_content("Educate the children") + expect(page).to have_content("More schools") end end From 97db98fd3e674678cd0e9dd5f6738691324cd5f0 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Fri, 11 Mar 2016 16:26:44 +0100 Subject: [PATCH 14/36] Removes html role attributes --- app/views/debates/index.html.erb | 4 ++-- app/views/kaminari/_paginator.html.erb | 2 +- app/views/layouts/management.html.erb | 2 +- app/views/management/proposals/index.html.erb | 4 ++-- app/views/management/proposals/print.html.erb | 4 ++-- app/views/pages/opendata.html.erb | 2 +- app/views/proposals/index.html.erb | 4 ++-- app/views/proposals/summary.html.erb | 4 ++-- app/views/users/show.html.erb | 4 ++-- app/views/welcome/index.html.erb | 6 +++--- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 2ed045df1..6488b5844 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -5,7 +5,7 @@ i18n_namespace: "debates.index.search_form" %> <% end %> -

+
@@ -50,4 +50,4 @@
-
+ diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb index ca9bc4bea..f129b1b9d 100644 --- a/app/views/kaminari/_paginator.html.erb +++ b/app/views/kaminari/_paginator.html.erb @@ -1,7 +1,7 @@ <%= paginator.render do -%>
-
- \ No newline at end of file + \ No newline at end of file diff --git a/app/views/management/proposals/print.html.erb b/app/views/management/proposals/print.html.erb index 33d8cccc3..7399376f1 100644 --- a/app/views/management/proposals/print.html.erb +++ b/app/views/management/proposals/print.html.erb @@ -1,4 +1,4 @@ -
+
-
+ diff --git a/app/views/pages/opendata.html.erb b/app/views/pages/opendata.html.erb index 9c8094535..ad16c2c14 100644 --- a/app/views/pages/opendata.html.erb +++ b/app/views/pages/opendata.html.erb @@ -9,7 +9,7 @@
- <%= image_tag("icon_home.png", size: "330x240", alt:"", role:"presentation") %> + <%= image_tag("icon_home.png", size: "330x240", alt:"") %>
diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index 1dc301d9b..970e1cb3e 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -5,7 +5,7 @@ i18n_namespace: "proposals.index.search_form" %> <% end %> -
+
@@ -61,4 +61,4 @@
-
+ diff --git a/app/views/proposals/summary.html.erb b/app/views/proposals/summary.html.erb index 3827c73bd..960c9e618 100644 --- a/app/views/proposals/summary.html.erb +++ b/app/views/proposals/summary.html.erb @@ -1,4 +1,4 @@ -
+
@@ -54,4 +54,4 @@
-
\ No newline at end of file + \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 9b3e69415..563b145dd 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,4 +1,4 @@ -
+
@@ -38,4 +38,4 @@
-
+ diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 32780e9c1..c7ed38d8c 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -12,13 +12,13 @@
- <%= image_tag("icon_home.png", size: "330x240", alt:"", role:"presentation") %> + <%= image_tag("icon_home.png", size: "330x240", alt:"") %>
<% cache [locale_and_user_status, @featured_debates, @featured_proposals, 'featured'] do %> -
+
<%= image_tag("icon_home_debate.png", size: "168x168", alt: t("welcome.debates.alt"), title: t("welcome.debates.title")) %> @@ -43,5 +43,5 @@

<%= t("welcome.do.description") %>

-
+ <% end %> From 3ec0971b375093668219f016405984b16bb91850 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 14 Mar 2016 12:25:46 +0100 Subject: [PATCH 15/36] Replaces icons i tags for span --- app/views/account/show.html.erb | 14 +++++----- app/views/admin/_menu.html.erb | 28 +++++++++---------- app/views/admin/organizations/index.html.erb | 4 +-- app/views/admin/organizations/search.html.erb | 4 +-- .../_written_by_author.html.erb | 2 +- .../admin/spending_proposals/edit.html.erb | 2 +- .../admin/spending_proposals/show.html.erb | 2 +- app/views/comments/_comment.html.erb | 4 +-- app/views/comments/_flag_actions.html.erb | 4 +-- app/views/comments/_votes.html.erb | 20 ++++++------- app/views/comments/show.html.erb | 2 +- app/views/debates/_debate.html.erb | 4 +-- app/views/debates/_flag_actions.html.erb | 4 +-- app/views/debates/_votes.html.erb | 4 +-- app/views/debates/edit.html.erb | 2 +- app/views/debates/new.html.erb | 4 +-- app/views/debates/show.html.erb | 6 ++-- app/views/devise/menu/_login_items.html.erb | 8 +++--- app/views/layouts/_footer.html.erb | 8 +++--- app/views/legislations/show.html.erb | 2 +- app/views/management/_menu.html.erb | 10 +++---- .../management/_user_permissions.html.erb | 2 +- app/views/moderation/_menu.html.erb | 8 +++--- app/views/moderation/comments/index.html.erb | 2 +- app/views/moderation/debates/index.html.erb | 2 +- app/views/moderation/proposals/index.html.erb | 2 +- app/views/pages/faq.html.erb | 20 ++++++------- app/views/pages/how_it_works.html.erb | 2 +- app/views/pages/how_to_use.html.erb | 2 +- app/views/pages/participation.html.erb | 2 +- app/views/pages/participation_facts.html.erb | 2 +- app/views/pages/participation_world.html.erb | 2 +- app/views/pages/proposals_info.html.erb | 2 +- .../pages/spending_proposals_info.html.erb | 2 +- app/views/proposals/_flag_actions.html.erb | 4 +-- app/views/proposals/_proposal.html.erb | 4 +-- app/views/proposals/edit.html.erb | 2 +- app/views/proposals/new.html.erb | 4 +-- app/views/proposals/show.html.erb | 6 ++-- app/views/proposals/summary.html.erb | 2 +- app/views/shared/_author_info.html.erb | 2 +- app/views/shared/_search_form.html.erb | 2 +- app/views/spending_proposals/new.html.erb | 4 +-- .../users/registrations/delete_form.html.erb | 2 +- app/views/users/registrations/edit.html.erb | 2 +- app/views/valuation/_menu.html.erb | 2 +- .../spending_proposals/show.html.erb | 2 +- app/views/verification/letter/edit.html.erb | 4 +-- app/views/verification/letter/new.html.erb | 12 ++++---- app/views/verification/letter/show.html.erb | 2 +- app/views/verification/residence/new.html.erb | 10 +++---- app/views/verification/sms/edit.html.erb | 2 +- app/views/verification/sms/new.html.erb | 2 +- .../verification/verified_user/show.html.erb | 2 +- app/views/welcome/welcome.html.erb | 8 +++--- 55 files changed, 134 insertions(+), 134 deletions(-) diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 99931e4ac..f13916d77 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -70,21 +70,21 @@

<%= t("account.show.user_permission_info") %>

    -
  •  <%= t("account.show.user_permission_debates") %>
  • -
  •  <%= t("account.show.user_permission_proposal") %>
  • +
  •  <%= t("account.show.user_permission_debates") %>
  • +
  •  <%= t("account.show.user_permission_proposal") %>
  • <% if current_user.level_two_or_three_verified? %> - + <% else %> - + <% end %> <%= t("account.show.user_permission_support_proposal") %>
  • <% if current_user.level_three_verified? %> - + <% else %> - + <% end %> <%= t("account.show.user_permission_votes") %>
  • @@ -101,7 +101,7 @@
<%= organization.responsible_name %> - + <%= t("admin.organizations.index.verified") %> - + <%= t("admin.organizations.index.rejected") %> <%= organization.responsible_name %> - + <%= t("admin.organizations.index.verified") %> - + <%= t("admin.organizations.index.rejected") %>