Add setting to allow remove investments supports
This commit is contained in:
@@ -11,11 +11,13 @@
|
||||
<div class="callout success">
|
||||
<%= t("budgets.investments.votes.already_supported") %>
|
||||
</div>
|
||||
<% 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 %>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= button_to t("budgets.investments.votes.support"), support_path,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 %>
|
||||
<section class="budget-investment-show" id="<%= dom_id(investment) %>">
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -25,10 +25,16 @@ 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)
|
||||
describe "button to remove support" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
user.up_votes(investment)
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it "is shown when the setting is enabled" do
|
||||
Setting["feature.remove_investments_supports"] = true
|
||||
|
||||
render_inline component
|
||||
|
||||
@@ -36,6 +42,15 @@ describe Budgets::Investments::VotesComponent do
|
||||
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
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user