From a08886fcf4bffcce238b59f551c62c7d7f7a40cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 8 Nov 2021 01:14:45 +0100 Subject: [PATCH 1/3] Remove obsolete investment-projects-list selector It isn't used since we deleted spending proposals in commit d0b8fef6b. --- app/assets/stylesheets/admin.scss | 7 ------- app/assets/stylesheets/participation.scss | 2 -- 2 files changed, 9 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 4fdfca770..51dfe510c 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -593,13 +593,6 @@ code { } } -.admin { - - .investment-projects-list.medium-9 { - width: 100%; - } -} - .investment-projects-summary { th, diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index f60dd05fb..a3dae8a94 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -503,7 +503,6 @@ .debates-list, .proposals-list, -.investment-projects-list, .budget-investments-list { @include breakpoint(medium) { @@ -511,7 +510,6 @@ } } -.investment-projects-list, .budget-investments-list { @include breakpoint(medium) { From 1a73b20d9bb688d56c50ea651423003753bc13b7 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 5 Nov 2021 23:32:51 +0100 Subject: [PATCH 2/3] Fix supported investments layout --- app/assets/stylesheets/participation.scss | 5 +++++ .../budgets/investments/_investment.html.erb | 22 +++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index a3dae8a94..1f6e47636 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -515,6 +515,10 @@ @include breakpoint(medium) { min-height: $line-height * 15; } + + .with-image > .row { + display: flex; + } } .budget-investments-list .budget-investment, @@ -543,6 +547,7 @@ } img { + height: 100%; max-width: 12rem; } } diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index 86c66d9fe..ce342c8a2 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -2,13 +2,10 @@
"> <% if feature?(:allow_images) && investment.image.present? %> -
+
-
- <%= image_tag investment.image_url(:thumb), - alt: investment.image.title.unicode_normalize %> -
+ <%= image_tag investment.image_url(:thumb), alt: investment.image.title.unicode_normalize %>
@@ -36,14 +33,12 @@ <% if investment.should_show_votes? %>
> + class="small-12 medium-3 column text-center"> <%= render Budgets::Investments::VotesComponent.new(investment) %>
<% elsif investment.should_show_vote_count? %>
> + class="small-12 medium-3 column text-center">
<%= t("budgets.investments.investment.supports", @@ -53,8 +48,7 @@
<% elsif investment.should_show_ballots? && !management_controller? %>
> + class="small-12 medium-3 column text-center"> <%= render "/budgets/investments/ballot", investment: investment, investment_ids: investment_ids, @@ -62,18 +56,14 @@
<% elsif investment.should_show_price? %>
> + class="supports small-12 medium-3 column text-center">
<%= investment.formatted_price %>
- <% else %> -
>
<% end %> - <% end %>
From 9979b539943447051f96ee20d347366b2248e96a Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 6 Nov 2021 00:38:02 +0100 Subject: [PATCH 3/3] Add setting to allow remove investments supports --- .../investments/votes_component.html.erb | 12 ++++--- .../budgets/investments/votes_controller.rb | 3 ++ app/models/setting.rb | 1 + .../investments/_investment_show.html.erb | 1 + config/locales/en/settings.yml | 2 ++ config/locales/es/settings.yml | 2 ++ db/dev_seeds/settings.rb | 1 + .../investments/votes_component_spec.rb | 31 ++++++++++++++----- .../investments/votes_controller_spec.rb | 29 +++++++++++++++++ spec/system/budgets/budgets_spec.rb | 1 + spec/system/budgets/investments_spec.rb | 2 ++ .../management/budget_investments_spec.rb | 2 ++ 12 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 spec/controllers/budgets/investments/votes_controller_spec.rb diff --git a/app/components/budgets/investments/votes_component.html.erb b/app/components/budgets/investments/votes_component.html.erb index 0aedbe37e..0535d9815 100644 --- a/app/components/budgets/investments/votes_component.html.erb +++ b/app/components/budgets/investments/votes_component.html.erb @@ -11,11 +11,13 @@
<%= t("budgets.investments.votes.already_supported") %>
- <%= button_to t("budgets.investments.votes.remove_support"), remove_support_path, - class: "button button-remove-support expanded", - method: "delete", - remote: true, - "aria-label": remove_support_aria_label %> + <% if feature?(:remove_investments_supports) %> + <%= button_to t("budgets.investments.votes.remove_support"), remove_support_path, + class: "button button-remove-support expanded", + method: "delete", + remote: true, + "aria-label": remove_support_aria_label %> + <% end %>
<% else %> <%= button_to t("budgets.investments.votes.support"), support_path, diff --git a/app/controllers/budgets/investments/votes_controller.rb b/app/controllers/budgets/investments/votes_controller.rb index 5b30a17c7..b48715c5b 100644 --- a/app/controllers/budgets/investments/votes_controller.rb +++ b/app/controllers/budgets/investments/votes_controller.rb @@ -1,6 +1,9 @@ module Budgets module Investments class VotesController < ApplicationController + include FeatureFlags + feature_flag :remove_investments_supports, only: :destroy + load_and_authorize_resource :budget load_and_authorize_resource :investment, through: :budget, class: "Budget::Investment" load_and_authorize_resource through: :investment, through_association: :votes_for, only: :destroy diff --git a/app/models/setting.rb b/app/models/setting.rb index f4b709ed3..7fe170e33 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -102,6 +102,7 @@ class Setting < ApplicationRecord "feature.graphql_api": true, "feature.sdg": true, "feature.machine_learning": false, + "feature.remove_investments_supports": false, "homepage.widgets.feeds.debates": true, "homepage.widgets.feeds.processes": true, "homepage.widgets.feeds.proposals": true, diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index f2d73e421..2b31e476f 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -12,6 +12,7 @@ investment.author, Flag.flagged?(current_user, investment), investment.followed_by?(current_user), + feature?(:remove_investments_supports), current_user&.voted_for?(investment)] do %>
diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index fb6fe0613..24679d5a0 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -132,6 +132,8 @@ en: dashboard: notification_emails: "Dashboard notification emails" notification_emails_description: "Enable sending dashboard notification emails to proposal's authors" + remove_investments_supports: "Allow removing supports on budget investments" + remove_investments_supports_description: "Allow users to remove supports on participatory budgets investments during the selecting projects phase." sdg: SDG sdg_description: Enable Sustainable Development Goals sections in the administration menu and in the Global Settings. remote_census: diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index 4e2086216..820aa25f8 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -132,6 +132,8 @@ es: dashboard: notification_emails: "Emails del panel de progreso" notification_emails_description: "Activar el envío de emails de notificaciones a los autores de las propuestas en la sección de panel de progreso" + remove_investments_supports: "Permitir retirar los apoyos en los proyectos de gasto" + remove_investments_supports_description: "Permite que los usuarios retiren su apoyo en los proyectos de gasto de los presupuestos participativos durante la fase de apoyos." sdg: ODS sdg_description: Habilitar secciones relacionadas con Objetivos de Desarrollo Sostenible en el menú de administración y en la sección de Configuración Global. remote_census: diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 364773ab6..bf76c3eb4 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -5,6 +5,7 @@ section "Creating Settings" do "facebook_handle": "CONSUL", "feature.featured_proposals": "true", "feature.map": "true", + "feature.remove_investments_supports": true, "instagram_handle": "CONSUL", "mailer_from_address": "noreply@consul.dev", "mailer_from_name": "CONSUL", diff --git a/spec/components/budgets/investments/votes_component_spec.rb b/spec/components/budgets/investments/votes_component_spec.rb index 83221b7a0..b2c3dab35 100644 --- a/spec/components/budgets/investments/votes_component_spec.rb +++ b/spec/components/budgets/investments/votes_component_spec.rb @@ -25,16 +25,31 @@ describe Budgets::Investments::VotesComponent do expect(page).to have_button "Support", disabled: true end - it "shows the button to remove support when users have supported the investment" do - user = create(:user) - user.up_votes(investment) - sign_in(user) + describe "button to remove support" do + let(:user) { create(:user) } - render_inline component + before do + user.up_votes(investment) + sign_in(user) + end - expect(page).to have_button count: 1, disabled: :all - expect(page).to have_button "Remove your support" - expect(page).to have_button "Remove your support to Renovate sidewalks in Main Street" + it "is shown when the setting is enabled" do + Setting["feature.remove_investments_supports"] = true + + render_inline component + + expect(page).to have_button count: 1, disabled: :all + expect(page).to have_button "Remove your support" + expect(page).to have_button "Remove your support to Renovate sidewalks in Main Street" + end + + it "is not shown when the setting is disabled" do + Setting["feature.remove_investments_supports"] = false + + render_inline component + + expect(page).not_to have_button disabled: :all + end end end end diff --git a/spec/controllers/budgets/investments/votes_controller_spec.rb b/spec/controllers/budgets/investments/votes_controller_spec.rb new file mode 100644 index 000000000..464ac2bd9 --- /dev/null +++ b/spec/controllers/budgets/investments/votes_controller_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +describe Budgets::Investments::VotesController do + let(:user) { create(:user) } + let(:budget) { create(:budget, :selecting) } + let(:investment) { create(:budget_investment, budget: budget) } + let(:vote) { create(:vote, votable: investment, voter: user) } + before { sign_in user } + + describe "DELETE destroy" do + it "raises an exception when the remove supports feature is disabled" do + Setting["feature.remove_investments_supports"] = false + + expect do + delete :destroy, xhr: true, params: { budget_id: budget, investment_id: investment, id: vote } + end.to raise_exception(FeatureFlags::FeatureDisabled) + end + end + + describe "POST create" do + it "is not affected by the remove supports feature" do + Setting["feature.remove_investments_supports"] = false + + post :create, params: { budget_id: budget, investment_id: investment } + + expect(response).to redirect_to budget_investments_path(heading_id: investment.heading.id) + end + end +end diff --git a/spec/system/budgets/budgets_spec.rb b/spec/system/budgets/budgets_spec.rb index bb6474b8d..84ce2f6c3 100644 --- a/spec/system/budgets/budgets_spec.rb +++ b/spec/system/budgets/budgets_spec.rb @@ -404,6 +404,7 @@ describe "Budgets" do end scenario "Show supports only if the support has not been removed" do + Setting["feature.remove_investments_supports"] = true voter = create(:user, :level_two) budget = create(:budget, phase: "selecting") investment = create(:budget_investment, :selected, budget: budget) diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index 615cf78ec..3fee7d277 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -1230,6 +1230,7 @@ describe "Budget Investments" do end scenario "Remove a support from show view" do + Setting["feature.remove_investments_supports"] = true investment = create(:budget_investment, budget: budget) login_as(author) @@ -1251,6 +1252,7 @@ describe "Budget Investments" do end scenario "Remove a support from index view" do + Setting["feature.remove_investments_supports"] = true investment = create(:budget_investment, budget: budget) login_as(author) diff --git a/spec/system/management/budget_investments_spec.rb b/spec/system/management/budget_investments_spec.rb index b0229241a..857a1f146 100644 --- a/spec/system/management/budget_investments_spec.rb +++ b/spec/system/management/budget_investments_spec.rb @@ -334,6 +334,7 @@ describe "Budget Investments" do end scenario "Remove support on behalf of someone else in index view" do + Setting["feature.remove_investments_supports"] = true create(:budget_investment, heading: heading) login_managed_user(user) @@ -354,6 +355,7 @@ describe "Budget Investments" do end scenario "Remove support on behalf of someone else in show view" do + Setting["feature.remove_investments_supports"] = true create(:budget_investment, heading: heading, title: "Don't support me!") login_managed_user(user)