Skip to content

Commit

Permalink
Merge pull request consuldemocracy#3822 from consul/finished_budgets
Browse files Browse the repository at this point in the history
Fix admin permissions for finished budgets
  • Loading branch information
javierm committed Nov 6, 2019
2 parents 8b6fa65 + 5711bf2 commit 0e61079
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 68 deletions.
2 changes: 2 additions & 0 deletions app/controllers/admin/budget_investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def show
end

def edit
authorize! :admin_update, @investment
load_staff
load_valuator_groups
load_tags
Expand All @@ -52,6 +53,7 @@ def update
end

def toggle_selection
authorize! :toggle_selection, @investment
@investment.toggle :selected
@investment.save!
load_investments
Expand Down
4 changes: 3 additions & 1 deletion app/models/abilities/administrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def initialize(user)
can [:read, :create, :update, :destroy], Budget::Heading
can [:hide, :admin_update, :toggle_selection], Budget::Investment
can [:valuate, :comment_valuation], Budget::Investment
cannot [:comment_valuation], Budget::Investment, budget: { phase: "finished" }
cannot [:admin_update, :toggle_selection, :valuate, :comment_valuation],
Budget::Investment, budget: { phase: "finished" }

can :create, Budget::ValuatorAssignment

can :read_admin_stats, Budget, &:balloting_or_later?
Expand Down
48 changes: 26 additions & 22 deletions app/views/admin/budget_investments/_select_investment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,34 @@

<td id="selection" class="small text-center" data-field="selected">
<% if investment.selected? %>
<%= link_to_unless investment.budget.finished?,
t("admin.budget_investments.index.selected"),
toggle_selection_admin_budget_budget_investment_path(@budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]),
method: :patch,
remote: true,
class: "button small expanded" %>
<%= link_to_if can?(:toggle_selection, investment),
t("admin.budget_investments.index.selected"),
toggle_selection_admin_budget_budget_investment_path(
@budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]
),
method: :patch,
remote: true,
class: "button small expanded" %>
<% elsif investment.feasible? && investment.valuation_finished? %>
<% unless investment.budget.finished? %>
<% if can?(:toggle_selection, investment) %>
<%= link_to t("admin.budget_investments.index.select"),
toggle_selection_admin_budget_budget_investment_path(@budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]),
toggle_selection_admin_budget_budget_investment_path(
@budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]
),
method: :patch,
remote: true,
class: "button small hollow expanded" %>
Expand Down
43 changes: 26 additions & 17 deletions app/views/admin/budget_investments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
<%= render "written_by_author" %>

<h2 class="inline-block"><%= t("admin.budget_investments.show.preview") %></h2>
<div class="float-right">
<%= link_to t("admin.budget_investments.show.edit"),
edit_admin_budget_budget_investment_path(
@budget,
@investment,
Budget::Investment.filter_params(params).to_h
),
class: "button hollow" unless @budget.finished? %>
</div>
<% if can?(:admin_update, @investment) %>
<div class="float-right">
<%= link_to t("admin.budget_investments.show.edit"),
edit_admin_budget_budget_investment_path(
@budget,
@investment,
Budget::Investment.filter_params(params).to_h
),
class: "button hollow" %>
</div>
<% end %>

<hr>
<%= render "/budgets/investments/investment_detail", investment: @investment, preview: true %>
Expand Down Expand Up @@ -50,19 +52,26 @@
<% end %>
</p>

<p>
<%= link_to t("admin.budget_investments.show.edit_classification"),
edit_admin_budget_budget_investment_path(@budget, @investment,
{ anchor: "classification" }.merge(Budget::Investment.filter_params(params).to_h)) unless @budget.finished? %>
</p>
<% if can?(:admin_update, @investment) %>
<p>
<%= link_to t("admin.budget_investments.show.edit_classification"),
edit_admin_budget_budget_investment_path(
@budget,
@investment,
{ anchor: "classification" }.merge(Budget::Investment.filter_params(params).to_h)
) %>
</p>
<% end %>

<hr>

<h2><%= t("admin.budget_investments.show.dossier") %></h2>
<%= render "valuation/budget_investments/dossier" %>
<p>
<%= link_to t("admin.budget_investments.show.edit_dossier"), edit_valuation_budget_budget_investment_path(@budget, @investment) unless @budget.finished? %>
</p>
<% if can?(:valuate, @investment) %>
<p>
<%= link_to t("admin.budget_investments.show.edit_dossier"), edit_valuation_budget_budget_investment_path(@budget, @investment) %>
</p>
<% end %>
<%= render "valuation/budget_investments/valuation_comments" %>
Expand Down
20 changes: 11 additions & 9 deletions app/views/valuation/budget_investments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
<br>

<h2 class="inline-block"><%= t("admin.budget_investments.show.preview") %></h2>
<div class="float-right">
<%= link_to t("admin.budget_investments.show.edit"),
edit_valuation_budget_budget_investment_path(
@budget,
@investment,
Budget::Investment.filter_params(params)
),
class: "button hollow" unless @budget.finished? %>
</div>
<% if can?(:valuate, @investment) %>
<div class="float-right">
<%= link_to t("admin.budget_investments.show.edit"),
edit_valuation_budget_budget_investment_path(
@budget,
@investment,
Budget::Investment.filter_params(params)
),
class: "button hollow" %>
</div>
<% end %>

<hr>
<%= render "/budgets/investments/investment_detail", investment: @investment, preview: true %>
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@
expect(page).to have_content("Ana ([email protected])")
end

scenario "Not show related content or hide links on preview" do
scenario "Does not show related content or hide links on preview" do
budget_investment = create(:budget_investment,
:unfeasible,
price: 1234,
Expand Down
17 changes: 0 additions & 17 deletions spec/features/valuation/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,6 @@
visit valuation_budget_budget_investment_path(budget, investment)
end.to raise_error "Not Found"
end

scenario "preview is visible" do
logout
login_as create(:administrator).user

visit valuation_budget_budget_investment_path(budget, investment)

expect(page).to have_content("Investment preview")
expect(page).to have_content(investment.title)
expect(page).to have_content(investment.description)
expect(page).to have_content(investment.author.name)
expect(page).to have_content(investment.heading.name)
expect(page).to have_content("1234")
expect(page).to have_content("Unfeasible")
expect(page).to have_content("It is impossible")
expect(page).to have_content("Ana ([email protected])")
end
end

describe "Valuate" do
Expand Down
6 changes: 5 additions & 1 deletion spec/models/abilities/administrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
let(:comment) { create(:comment) }
let(:proposal) { create(:proposal, author: user) }
let(:budget_investment) { create(:budget_investment) }
let(:finished_investment) { create(:budget_investment, budget: create(:budget, :finished)) }
let(:legislation_question) { create(:legislation_question) }
let(:poll_question) { create(:poll_question) }

Expand Down Expand Up @@ -77,7 +78,10 @@
it { should be_able_to(:hide, Budget::Investment) }

it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, :valuating))) }
it { should be_able_to(:valuate, create(:budget_investment, budget: create(:budget, :finished))) }
it { should_not be_able_to(:admin_update, finished_investment) }
it { should_not be_able_to(:valuate, finished_investment) }
it { should_not be_able_to(:comment_valuation, finished_investment) }
it { should_not be_able_to(:toggle_selection, finished_investment) }

it { should be_able_to(:destroy, proposal_image) }
it { should be_able_to(:destroy, proposal_document) }
Expand Down

0 comments on commit 0e61079

Please sign in to comment.