Merge pull request #3603 from consul/admin_stats_before_voting_phase

Avoid error when accessing final voting stats before the balloting phase
This commit is contained in:
Julian Nicolas Herrero
2019-06-11 14:34:42 +02:00
committed by GitHub
6 changed files with 31 additions and 2 deletions

View File

@@ -74,6 +74,9 @@ class Admin::StatsController < Admin::BaseController
def budget_balloting
@budget = Budget.find(params[:budget_id])
authorize! :read_admin_stats, @budget, message: t("admin.stats.budgets.no_data_before_balloting_phase")
@user_count = @budget.ballots.select {|ballot| ballot.lines.any? }.count
@vote_count = @budget.lines.count

View File

@@ -66,6 +66,8 @@ module Abilities
can [:valuate, :comment_valuation], Budget::Investment
can :create, Budget::ValuatorAssignment
can(:read_admin_stats, Budget) { |budget| budget.balloting_or_later? }
can [:search, :edit, :update, :create, :index, :destroy], Banner
can [:index, :create, :edit, :update, :destroy], Geozone

View File

@@ -9,8 +9,15 @@
<strong><%= budget.name %></strong>
</td>
<td>
<%= link_to t("admin.stats.budgets.supporting_phase"), budget_supporting_admin_stats_path(budget_id: budget.id), class: "button hollow" %>
<%= link_to t("admin.stats.budgets.balloting_phase"), budget_balloting_admin_stats_path(budget_id: budget.id), class: "button hollow" %>
<%= link_to t("admin.stats.budgets.supporting_phase"),
budget_supporting_admin_stats_path(budget_id: budget.id),
class: "button hollow" %>
<% if can? :read_admin_stats, budget %>
<%= link_to t("admin.stats.budgets.balloting_phase"),
budget_balloting_admin_stats_path(budget_id: budget.id),
class: "button hollow" %>
<% end %>
</td>
</tr>
</table>