From f875ded0be8288718f6351fc48faeb8508f89e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Salvador=20P=C3=A9rez=20Garc=C3=ADa?= Date: Thu, 13 Sep 2018 18:22:59 +0200 Subject: [PATCH] Bugfixing and enhancements * Fixed common ability: Retired draft proposal can't be published. * Fixed proposal dashboard view: progress graph is not available for draft proposals. --- app/models/abilities/common.rb | 2 +- app/views/dashboard/progress.html.erb | 60 ++++++++++++++------------- spec/models/abilities/common_spec.rb | 2 + 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index d2d51cfe9..c5f947abf 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -17,7 +17,7 @@ module Abilities proposal.editable_by?(user) end can :publish, Proposal do |proposal| - proposal.draft? && proposal.author.id == user.id + proposal.draft? && proposal.author.id == user.id && !proposal.retired? end can :dashboard, Proposal do |proposal| proposal.author.id == user.id diff --git a/app/views/dashboard/progress.html.erb b/app/views/dashboard/progress.html.erb index f45016cc4..9ffc324ae 100644 --- a/app/views/dashboard/progress.html.erb +++ b/app/views/dashboard/progress.html.erb @@ -1,37 +1,39 @@ -<% content_for :action_title, t("dashboard.progress.title") %> +<% if proposal.published? %> + <% content_for :action_title, t("dashboard.progress.title") %> -
-
-
- <%= link_to t("dashboard.progress.group_by_date"), - progress_proposal_dashboard_index_path(proposal), - class: "button #{daily_selected_class}" %> - <%= link_to t("dashboard.progress.group_by_week"), - progress_proposal_dashboard_index_path(proposal, group_by: 'week'), - class: "button #{weekly_selected_class}" %> - <%= link_to t("dashboard.progress.group_by_month"), - progress_proposal_dashboard_index_path(proposal, group_by: 'month'), - class: "button #{monthly_selected_class}" %> +
+
+
+ <%= link_to t("dashboard.progress.group_by_date"), + progress_proposal_dashboard_index_path(proposal), + class: "button #{daily_selected_class}" %> + <%= link_to t("dashboard.progress.group_by_week"), + progress_proposal_dashboard_index_path(proposal, group_by: 'week'), + class: "button #{weekly_selected_class}" %> + <%= link_to t("dashboard.progress.group_by_month"), + progress_proposal_dashboard_index_path(proposal, group_by: 'month'), + class: "button #{monthly_selected_class}" %> +
-
-
-
" - data-proposal-graph-supports-label="<%= t("dashboard.progress.supports") %>" - data-proposal-graph-success-label="<%= t("dashboard.progress.success") %>" - data-proposal-success="<%= Setting["votes_for_proposal_success"] %>" - data-proposal-resources-url="<%= proposal_dashboard_resources_path(proposal, format: :json) %>" - class="c3 proposal-graph" - style="max-height: 320px; position: relative;">
-
+
+
" + data-proposal-graph-supports-label="<%= t("dashboard.progress.supports") %>" + data-proposal-graph-success-label="<%= t("dashboard.progress.success") %>" + data-proposal-success="<%= Setting["votes_for_proposal_success"] %>" + data-proposal-resources-url="<%= proposal_dashboard_resources_path(proposal, format: :json) %>" + class="c3 proposal-graph" + style="max-height: 320px; position: relative;">
+
-<%= javascript_include_tag 'dashboard_graphs', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'dashboard_graphs', 'data-turbolinks-track' => true %> +<% end %> <%= render 'next_goal' %> <%= render 'recommended_actions' %> diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index 7a19c7d96..4b38258d8 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -187,10 +187,12 @@ describe Abilities::Common do describe 'publishing proposals' do let(:draft_own_proposal) { create(:proposal, :draft, author: user) } + let(:retired_proposal) { create(:proposal, :draft, :retired, author: user) } it { should be_able_to(:publish, draft_own_proposal) } it { should_not be_able_to(:publish, own_proposal) } it { should_not be_able_to(:publish, proposal) } + it { should_not be_able_to(:publish, retired_proposal) } end describe "when level 2 verified" do