Add setting to allow remove investments supports
This commit is contained in:
@@ -11,11 +11,13 @@
|
|||||||
<div class="callout success">
|
<div class="callout success">
|
||||||
<%= t("budgets.investments.votes.already_supported") %>
|
<%= t("budgets.investments.votes.already_supported") %>
|
||||||
</div>
|
</div>
|
||||||
<%= button_to t("budgets.investments.votes.remove_support"), remove_support_path,
|
<% if feature?(:remove_investments_supports) %>
|
||||||
class: "button button-remove-support expanded",
|
<%= button_to t("budgets.investments.votes.remove_support"), remove_support_path,
|
||||||
method: "delete",
|
class: "button button-remove-support expanded",
|
||||||
remote: true,
|
method: "delete",
|
||||||
"aria-label": remove_support_aria_label %>
|
remote: true,
|
||||||
|
"aria-label": remove_support_aria_label %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= button_to t("budgets.investments.votes.support"), support_path,
|
<%= button_to t("budgets.investments.votes.support"), support_path,
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
module Budgets
|
module Budgets
|
||||||
module Investments
|
module Investments
|
||||||
class VotesController < ApplicationController
|
class VotesController < ApplicationController
|
||||||
|
include FeatureFlags
|
||||||
|
feature_flag :remove_investments_supports, only: :destroy
|
||||||
|
|
||||||
load_and_authorize_resource :budget
|
load_and_authorize_resource :budget
|
||||||
load_and_authorize_resource :investment, through: :budget, class: "Budget::Investment"
|
load_and_authorize_resource :investment, through: :budget, class: "Budget::Investment"
|
||||||
load_and_authorize_resource through: :investment, through_association: :votes_for, only: :destroy
|
load_and_authorize_resource through: :investment, through_association: :votes_for, only: :destroy
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ class Setting < ApplicationRecord
|
|||||||
"feature.graphql_api": true,
|
"feature.graphql_api": true,
|
||||||
"feature.sdg": true,
|
"feature.sdg": true,
|
||||||
"feature.machine_learning": false,
|
"feature.machine_learning": false,
|
||||||
|
"feature.remove_investments_supports": false,
|
||||||
"homepage.widgets.feeds.debates": true,
|
"homepage.widgets.feeds.debates": true,
|
||||||
"homepage.widgets.feeds.processes": true,
|
"homepage.widgets.feeds.processes": true,
|
||||||
"homepage.widgets.feeds.proposals": true,
|
"homepage.widgets.feeds.proposals": true,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
investment.author,
|
investment.author,
|
||||||
Flag.flagged?(current_user, investment),
|
Flag.flagged?(current_user, investment),
|
||||||
investment.followed_by?(current_user),
|
investment.followed_by?(current_user),
|
||||||
|
feature?(:remove_investments_supports),
|
||||||
current_user&.voted_for?(investment)] do %>
|
current_user&.voted_for?(investment)] do %>
|
||||||
<section class="budget-investment-show" id="<%= dom_id(investment) %>">
|
<section class="budget-investment-show" id="<%= dom_id(investment) %>">
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ en:
|
|||||||
dashboard:
|
dashboard:
|
||||||
notification_emails: "Dashboard notification emails"
|
notification_emails: "Dashboard notification emails"
|
||||||
notification_emails_description: "Enable sending dashboard notification emails to proposal's authors"
|
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: SDG
|
||||||
sdg_description: Enable Sustainable Development Goals sections in the administration menu and in the Global Settings.
|
sdg_description: Enable Sustainable Development Goals sections in the administration menu and in the Global Settings.
|
||||||
remote_census:
|
remote_census:
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ es:
|
|||||||
dashboard:
|
dashboard:
|
||||||
notification_emails: "Emails del panel de progreso"
|
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"
|
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: 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.
|
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:
|
remote_census:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ section "Creating Settings" do
|
|||||||
"facebook_handle": "CONSUL",
|
"facebook_handle": "CONSUL",
|
||||||
"feature.featured_proposals": "true",
|
"feature.featured_proposals": "true",
|
||||||
"feature.map": "true",
|
"feature.map": "true",
|
||||||
|
"feature.remove_investments_supports": true,
|
||||||
"instagram_handle": "CONSUL",
|
"instagram_handle": "CONSUL",
|
||||||
"mailer_from_address": "noreply@consul.dev",
|
"mailer_from_address": "noreply@consul.dev",
|
||||||
"mailer_from_name": "CONSUL",
|
"mailer_from_name": "CONSUL",
|
||||||
|
|||||||
@@ -25,16 +25,31 @@ describe Budgets::Investments::VotesComponent do
|
|||||||
expect(page).to have_button "Support", disabled: true
|
expect(page).to have_button "Support", disabled: true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shows the button to remove support when users have supported the investment" do
|
describe "button to remove support" do
|
||||||
user = create(:user)
|
let(:user) { create(:user) }
|
||||||
user.up_votes(investment)
|
|
||||||
sign_in(user)
|
|
||||||
|
|
||||||
render_inline component
|
before do
|
||||||
|
user.up_votes(investment)
|
||||||
|
sign_in(user)
|
||||||
|
end
|
||||||
|
|
||||||
expect(page).to have_button count: 1, disabled: :all
|
it "is shown when the setting is enabled" do
|
||||||
expect(page).to have_button "Remove your support"
|
Setting["feature.remove_investments_supports"] = true
|
||||||
expect(page).to have_button "Remove your support to Renovate sidewalks in Main Street"
|
|
||||||
|
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
|
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
|
end
|
||||||
|
|
||||||
scenario "Show supports only if the support has not been removed" do
|
scenario "Show supports only if the support has not been removed" do
|
||||||
|
Setting["feature.remove_investments_supports"] = true
|
||||||
voter = create(:user, :level_two)
|
voter = create(:user, :level_two)
|
||||||
budget = create(:budget, phase: "selecting")
|
budget = create(:budget, phase: "selecting")
|
||||||
investment = create(:budget_investment, :selected, budget: budget)
|
investment = create(:budget_investment, :selected, budget: budget)
|
||||||
|
|||||||
@@ -1230,6 +1230,7 @@ describe "Budget Investments" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Remove a support from show view" do
|
scenario "Remove a support from show view" do
|
||||||
|
Setting["feature.remove_investments_supports"] = true
|
||||||
investment = create(:budget_investment, budget: budget)
|
investment = create(:budget_investment, budget: budget)
|
||||||
|
|
||||||
login_as(author)
|
login_as(author)
|
||||||
@@ -1251,6 +1252,7 @@ describe "Budget Investments" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Remove a support from index view" do
|
scenario "Remove a support from index view" do
|
||||||
|
Setting["feature.remove_investments_supports"] = true
|
||||||
investment = create(:budget_investment, budget: budget)
|
investment = create(:budget_investment, budget: budget)
|
||||||
|
|
||||||
login_as(author)
|
login_as(author)
|
||||||
|
|||||||
@@ -334,6 +334,7 @@ describe "Budget Investments" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Remove support on behalf of someone else in index view" do
|
scenario "Remove support on behalf of someone else in index view" do
|
||||||
|
Setting["feature.remove_investments_supports"] = true
|
||||||
create(:budget_investment, heading: heading)
|
create(:budget_investment, heading: heading)
|
||||||
|
|
||||||
login_managed_user(user)
|
login_managed_user(user)
|
||||||
@@ -354,6 +355,7 @@ describe "Budget Investments" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Remove support on behalf of someone else in show view" do
|
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!")
|
create(:budget_investment, heading: heading, title: "Don't support me!")
|
||||||
|
|
||||||
login_managed_user(user)
|
login_managed_user(user)
|
||||||
|
|||||||
Reference in New Issue
Block a user