diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb
index d8425c217..ea2a327f7 100644
--- a/app/helpers/budgets_helper.rb
+++ b/app/helpers/budgets_helper.rb
@@ -105,4 +105,18 @@ module BudgetsHelper
ends_at: balloting_phase.ends_at }),
method: :post
end
+
+ def budget_subnav_items_for(budget)
+ {
+ results: t("budgets.results.link"),
+ stats: t("stats.budgets.link"),
+ executions: t("budgets.executions.link")
+ }.select { |section, _| can?(:"read_#{section}", budget) }.map do |section, text|
+ {
+ text: text,
+ url: send("budget_#{section}_path", budget),
+ active: controller_name == section.to_s
+ }
+ end
+ end
end
diff --git a/app/views/budgets/_finished.html.erb b/app/views/budgets/_finished.html.erb
new file mode 100644
index 000000000..60b715917
--- /dev/null
+++ b/app/views/budgets/_finished.html.erb
@@ -0,0 +1,35 @@
+
+
+
<%= t("budgets.index.finished_budgets") %>
+
+
+ <% budgets.each do |budget| %>
+
+
+
+
+
+
<%= budget.name %>
+
+
+
+
+
+ <% 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" %>
+
+
+
+
+
+ <% end %>
+
+
+
diff --git a/app/views/budgets/_subnav.html.erb b/app/views/budgets/_subnav.html.erb
new file mode 100644
index 000000000..f5f960377
--- /dev/null
+++ b/app/views/budgets/_subnav.html.erb
@@ -0,0 +1,17 @@
+
+
+
+ <% budget_subnav_items_for(budget).each do |item| %>
+ <% if item[:active] %>
+ -
+ <%= t("shared.you_are_in") %>
+
+ <%= link_to item[:text], item[:url], class: "is-active" %>
+
+ <% else %>
+ - <%= link_to item[:text], item[:url] %>
+ <% end %>
+ <% end %>
+
+
+
diff --git a/app/views/budgets/executions/show.html.erb b/app/views/budgets/executions/show.html.erb
index a0e3324bc..acab50de4 100644
--- a/app/views/budgets/executions/show.html.erb
+++ b/app/views/budgets/executions/show.html.erb
@@ -25,21 +25,7 @@
-
-
-
- -
- <%= link_to t("budgets.results.link"), budget_results_path(@budget) %>
-
- -
- <%= link_to t("stats.budgets.link"), budget_stats_path(@budget) %>
-
- -
- <%= link_to t("budgets.executions.link"), budget_executions_path(@budget), class: "is-active" %>
-
-
-
-
+<%= render "budgets/subnav", budget: @budget %>
diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb
index 9e198156f..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" %>
@@ -126,38 +126,7 @@
<% if @finished_budgets.present? %>
-
-
-
<%= t("budgets.index.finished_budgets") %>
-
-
- <% @finished_budgets.each do |budget| %>
-
-
-
-
-
-
<%= budget.name %>
-
-
-
-
-
- <%= link_to t("budgets.index.see_results"),
- budget_results_path(budget.id),
- class: "button" %>
- <%= link_to t("budgets.index.milestones"),
- budget_executions_path(budget.id),
- class: "button" %>
-
-
-
-
-
- <% end %>
-
-
-
+ <%= render "finished", budgets: @finished_budgets %>
<% end %>
<% else %>
diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb
index d77f50b77..6a8829437 100644
--- a/app/views/budgets/results/show.html.erb
+++ b/app/views/budgets/results/show.html.erb
@@ -24,22 +24,7 @@
-
-
-
- -
- <%= t("shared.you_are_in") %>
- <%= link_to t("budgets.results.link"), budget_results_path(@budget), class: "is-active" %>
-
- -
- <%= link_to t("stats.budgets.link"), budget_stats_path(@budget) %>
-
- -
- <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %>
-
-
-
-
+<%= render "budgets/subnav", budget: @budget %>
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/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb
index bbbfda4bb..60697135d 100644
--- a/app/views/budgets/stats/show.html.erb
+++ b/app/views/budgets/stats/show.html.erb
@@ -21,22 +21,7 @@
-
-
-
- -
- <%= t("shared.you_are_in") %>
- <%= link_to t("budgets.results.link"), budget_results_path(@budget) %>
-
- -
- <%= link_to t("stats.budgets.link"), budget_stats_path(@budget), class: "is-active" %>
-
- -
- <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %>
-
-
-
-
+ <%= render "budgets/subnav", budget: @budget %>
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)