From da59315530de15d4ab5c2f36b395938655a92f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 4 Jun 2019 12:24:20 +0200 Subject: [PATCH] Don't show links to budget results if disabled --- app/helpers/budgets_helper.rb | 2 +- app/views/budgets/_finished.html.erb | 9 ++++++--- app/views/budgets/index.html.erb | 2 +- app/views/budgets/show.html.erb | 2 +- spec/features/budgets/results_spec.rb | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 5ac9b12a1..ea2a327f7 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -111,7 +111,7 @@ module BudgetsHelper results: t("budgets.results.link"), stats: t("stats.budgets.link"), executions: t("budgets.executions.link") - }.map do |section, text| + }.select { |section, _| can?(:"read_#{section}", budget) }.map do |section, text| { text: text, url: send("budget_#{section}_path", budget), diff --git a/app/views/budgets/_finished.html.erb b/app/views/budgets/_finished.html.erb index f7c17fc58..60b715917 100644 --- a/app/views/budgets/_finished.html.erb +++ b/app/views/budgets/_finished.html.erb @@ -15,9 +15,12 @@
- <%= link_to t("budgets.index.see_results"), - budget_results_path(budget), - class: "button" %> + <% if can?(:read_results, budget) %> + <%= link_to t("budgets.index.see_results"), + budget_results_path(budget), + class: "button" %> + <% end %> + <%= link_to t("budgets.index.milestones"), budget_executions_path(budget), class: "button" %> diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index e19a13416..5a7dde0ba 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -53,7 +53,7 @@ <% end %> <% end %> - <% if current_budget.finished? %> + <% if can?(:read_results, current_budget) %> <%= link_to t("budgets.show.see_results"), budget_results_path(current_budget, heading_id: current_budget.headings.first), class: "button margin-top expanded" %> diff --git a/app/views/budgets/show.html.erb b/app/views/budgets/show.html.erb index 89e4e146c..26af33856 100644 --- a/app/views/budgets/show.html.erb +++ b/app/views/budgets/show.html.erb @@ -36,7 +36,7 @@ <% end %> <% end %> - <% if @budget.finished? %> + <% if can?(:read_results, @budget) %> <%= link_to t("budgets.show.see_results"), budget_results_path(@budget), class: "button margin-top expanded" %> diff --git a/spec/features/budgets/results_spec.rb b/spec/features/budgets/results_spec.rb index e10e9e7b2..5b9277d56 100644 --- a/spec/features/budgets/results_spec.rb +++ b/spec/features/budgets/results_spec.rb @@ -15,6 +15,22 @@ describe "Results" do Budget::Result.new(budget, heading).calculate_winners end + scenario "No links to budget results with results disabled" do + budget.update(results_enabled: false) + + visit budgets_path + + expect(page).not_to have_link "See results" + + visit budget_path(budget) + + expect(page).not_to have_link "See results" + + visit budget_executions_path(budget) + + expect(page).not_to have_link "See results" + end + scenario "Diplays winner investments" do create(:budget_heading, group: group)