From 01cfed8882b464815a1523c4322e32be57ef1e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 23 Oct 2020 14:03:55 +0200 Subject: [PATCH] Hide checkbox when investments cannot be updated We were allowing users to check/uncheck the "Visible to valuators" checkbox even when the budget is finished and so the investments cannot be edited. So users were still able to check/uncheck this attribute, but the server was silently rejecting these changes. We've considered removing the column in this case but decided to keep it since users can already control which columns they'd like to display. --- .../_select_investment.html.erb | 14 +++++++----- spec/system/admin/budget_investments_spec.rb | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/views/admin/budget_investments/_select_investment.html.erb b/app/views/admin/budget_investments/_select_investment.html.erb index a7593a0c5..320abc579 100644 --- a/app/views/admin/budget_investments/_select_investment.html.erb +++ b/app/views/admin/budget_investments/_select_investment.html.erb @@ -51,11 +51,15 @@ - <%= form_for [:admin, investment.budget, investment], remote: true, format: :json do |f| %> - <%= f.check_box :visible_to_valuators, - label: false, - class: "js-submit-on-change", - id: "budget_investment_visible_to_valuators" %> + <% if can?(:admin_update, investment) %> + <%= form_for [:admin, investment.budget, investment], remote: true, format: :json do |f| %> + <%= f.check_box :visible_to_valuators, + label: false, + class: "js-submit-on-change", + id: "budget_investment_visible_to_valuators" %> + <% end %> + <% else %> + <%= investment.visible_to_valuators? ? t("shared.yes") : t("shared.no") %> <% end %> diff --git a/spec/system/admin/budget_investments_spec.rb b/spec/system/admin/budget_investments_spec.rb index ec8d4c9ec..165b15aea 100644 --- a/spec/system/admin/budget_investments_spec.rb +++ b/spec/system/admin/budget_investments_spec.rb @@ -1651,6 +1651,28 @@ describe "Admin budget investments" do end end + scenario "Cannot mark/unmark visible to valuators on finished budgets" do + budget.update!(phase: "finished") + create(:budget_investment, budget: budget, title: "Visible", visible_to_valuators: true) + create(:budget_investment, budget: budget, title: "Invisible", visible_to_valuators: false) + + visit admin_budget_budget_investments_path(budget) + + within "tr", text: "Visible" do + within "td[data-field=visible_to_valuators]" do + expect(page).to have_text "Yes" + expect(page).not_to have_field "budget_investment_visible_to_valuators" + end + end + + within "tr", text: "Invisible" do + within "td[data-field=visible_to_valuators]" do + expect(page).to have_text "No" + expect(page).not_to have_field "budget_investment_visible_to_valuators" + end + end + end + scenario "Showing the valuating checkbox" do investment1 = create(:budget_investment, :with_administrator, :with_valuator, :visible_to_valuators, budget: budget)