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.
This commit is contained in:
Javi Martín
2020-10-23 14:03:55 +02:00
parent 37e7eeb6e1
commit 01cfed8882
2 changed files with 31 additions and 5 deletions

View File

@@ -51,11 +51,15 @@
</td> </td>
<td class="small text-center" data-field="visible_to_valuators"> <td class="small text-center" data-field="visible_to_valuators">
<%= form_for [:admin, investment.budget, investment], remote: true, format: :json do |f| %> <% if can?(:admin_update, investment) %>
<%= f.check_box :visible_to_valuators, <%= form_for [:admin, investment.budget, investment], remote: true, format: :json do |f| %>
label: false, <%= f.check_box :visible_to_valuators,
class: "js-submit-on-change", label: false,
id: "budget_investment_visible_to_valuators" %> class: "js-submit-on-change",
id: "budget_investment_visible_to_valuators" %>
<% end %>
<% else %>
<%= investment.visible_to_valuators? ? t("shared.yes") : t("shared.no") %>
<% end %> <% end %>
</td> </td>

View File

@@ -1651,6 +1651,28 @@ describe "Admin budget investments" do
end end
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 scenario "Showing the valuating checkbox" do
investment1 = create(:budget_investment, :with_administrator, :with_valuator, :visible_to_valuators, investment1 = create(:budget_investment, :with_administrator, :with_valuator, :visible_to_valuators,
budget: budget) budget: budget)