Edit Budget Investment only in accepting phase (#3716)
This way users who made a typo can fix it before the investment is reviewed.
This commit is contained in:
committed by
Javier Martín
parent
970c3238fb
commit
bb627a7117
@@ -44,6 +44,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
authorize! :admin_update, @investment
|
||||||
if @investment.update(budget_investment_params)
|
if @investment.update(budget_investment_params)
|
||||||
redirect_to admin_budget_budget_investment_path(@budget,
|
redirect_to admin_budget_budget_investment_path(@budget,
|
||||||
@investment,
|
@investment,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module Budgets
|
|||||||
before_action :load_ballot, only: [:index, :show]
|
before_action :load_ballot, only: [:index, :show]
|
||||||
before_action :load_heading, only: [:index, :show]
|
before_action :load_heading, only: [:index, :show]
|
||||||
before_action :set_random_seed, only: :index
|
before_action :set_random_seed, only: :index
|
||||||
before_action :load_categories, only: [:index, :new, :create]
|
before_action :load_categories, only: [:index, :new, :create, :edit, :update]
|
||||||
before_action :set_default_budget_filter, only: :index
|
before_action :set_default_budget_filter, only: :index
|
||||||
before_action :set_view, only: :index
|
before_action :set_view, only: :index
|
||||||
before_action :load_content_blocks, only: :index
|
before_action :load_content_blocks, only: :index
|
||||||
@@ -76,6 +76,15 @@ module Budgets
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @investment.update(investment_params)
|
||||||
|
redirect_to budget_investment_path(@budget, @investment),
|
||||||
|
notice: t("flash.actions.update.budget_investment")
|
||||||
|
else
|
||||||
|
render "edit"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@investment.destroy
|
@investment.destroy
|
||||||
redirect_to user_path(current_user, filter: "budget_investments"), notice: t("flash.actions.destroy.budget_investment")
|
redirect_to user_path(current_user, filter: "budget_investments"), notice: t("flash.actions.destroy.budget_investment")
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ module Abilities
|
|||||||
can [:index, :read, :new, :create, :update, :destroy, :calculate_winners, :assigned_users_translation], Budget
|
can [:index, :read, :new, :create, :update, :destroy, :calculate_winners, :assigned_users_translation], Budget
|
||||||
can [:read, :create, :update, :destroy], Budget::Group
|
can [:read, :create, :update, :destroy], Budget::Group
|
||||||
can [:read, :create, :update, :destroy], Budget::Heading
|
can [:read, :create, :update, :destroy], Budget::Heading
|
||||||
can [:hide, :update, :toggle_selection], Budget::Investment
|
can [:hide, :admin_update, :toggle_selection], Budget::Investment
|
||||||
can [:valuate, :comment_valuation], Budget::Investment
|
can [:valuate, :comment_valuation], Budget::Investment
|
||||||
can :create, Budget::ValuatorAssignment
|
can :create, Budget::ValuatorAssignment
|
||||||
can [:edit_dossier], Budget::Investment
|
can [:edit_dossier], Budget::Investment
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ module Abilities
|
|||||||
can :create, Legislation::Answer
|
can :create, Legislation::Answer
|
||||||
|
|
||||||
can :create, Budget::Investment, budget: { phase: "accepting" }
|
can :create, Budget::Investment, budget: { phase: "accepting" }
|
||||||
|
can :edit, Budget::Investment, budget: { phase: "accepting" }, author_id: user.id
|
||||||
|
can :update, Budget::Investment, budget: { phase: "accepting" }, author_id: user.id
|
||||||
can :suggest, Budget::Investment, budget: { phase: "accepting" }
|
can :suggest, Budget::Investment, budget: { phase: "accepting" }
|
||||||
can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id
|
can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id
|
||||||
can :vote, Budget::Investment, budget: { phase: "selecting" }
|
can :vote, Budget::Investment, budget: { phase: "selecting" }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<%= translatable_form_for(@investment, url: form_url, method: :post, html: { multipart: true }) do |f| %>
|
<%= translatable_form_for(@investment, url: form_url, html: { multipart: true }) do |f| %>
|
||||||
|
|
||||||
<%= render "shared/errors", resource: @investment %>
|
<%= render "shared/errors", resource: @investment %>
|
||||||
|
|
||||||
|
|||||||
6
app/views/budgets/investments/edit.html.erb
Normal file
6
app/views/budgets/investments/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<div class="budget-investment-new row">
|
||||||
|
<div class="small-12 medium-9 column">
|
||||||
|
<h1><%= t("management.budget_investments.edit") %></h1>
|
||||||
|
<%= render "/budgets/investments/form", form_url: budget_investment_path(@budget, @investment) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -8,5 +8,9 @@
|
|||||||
method: :delete, class: "button hollow alert expanded",
|
method: :delete, class: "button hollow alert expanded",
|
||||||
data: { confirm: "#{t("users.show.delete_alert")}" } %>
|
data: { confirm: "#{t("users.show.delete_alert")}" } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if can? :update, budget_investment %>
|
||||||
|
<%= link_to t("shared.edit"), edit_budget_investment_path(budget_investment.budget, budget_investment),
|
||||||
|
class: "button hollow expanded" %>
|
||||||
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ en:
|
|||||||
alert:
|
alert:
|
||||||
unverified_user: User is not verified
|
unverified_user: User is not verified
|
||||||
create: Create a budget investment
|
create: Create a budget investment
|
||||||
|
edit: Edit budget investment
|
||||||
filters:
|
filters:
|
||||||
heading: Concept
|
heading: Concept
|
||||||
unfeasible: Unfeasible investment
|
unfeasible: Unfeasible investment
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ es:
|
|||||||
alert:
|
alert:
|
||||||
unverified_user: Usuario no verificado
|
unverified_user: Usuario no verificado
|
||||||
create: Crear nuevo proyecto
|
create: Crear nuevo proyecto
|
||||||
|
edit: Editar proyecto de gasto
|
||||||
filters:
|
filters:
|
||||||
heading: Concepto
|
heading: Concepto
|
||||||
unfeasible: Proyectos no factibles
|
unfeasible: Proyectos no factibles
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
resources :budgets, only: [:show, :index] do
|
resources :budgets, only: [:show, :index] do
|
||||||
resources :groups, controller: "budgets/groups", only: [:show]
|
resources :groups, controller: "budgets/groups", only: [:show]
|
||||||
resources :investments, controller: "budgets/investments", only: [:index, :new, :create, :show, :destroy] do
|
resources :investments, controller: "budgets/investments" do
|
||||||
member do
|
member do
|
||||||
post :vote
|
post :vote
|
||||||
put :flag
|
put :flag
|
||||||
|
|||||||
@@ -927,6 +927,54 @@ describe "Budget Investments" do
|
|||||||
expect(page).to have_content "Build a skyscraper"
|
expect(page).to have_content "Build a skyscraper"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Edit", :js do
|
||||||
|
daniel = create(:user, :level_two)
|
||||||
|
|
||||||
|
create(:budget_investment, heading: heading,title: "Get Schwifty", author: daniel, created_at: 1.day.ago)
|
||||||
|
|
||||||
|
login_as(daniel)
|
||||||
|
|
||||||
|
visit user_path(daniel, filter: "budget_investments")
|
||||||
|
|
||||||
|
click_link("Edit", match: :first)
|
||||||
|
fill_in "Title", with: "Park improvements"
|
||||||
|
check "budget_investment_terms_of_service"
|
||||||
|
|
||||||
|
click_button "Update Investment"
|
||||||
|
|
||||||
|
expect(page).to have_content "Investment project updated succesfully"
|
||||||
|
expect(page).to have_content "Park improvements"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Trigger validation errors in edit view" do
|
||||||
|
daniel = create(:user, :level_two)
|
||||||
|
message_error = "is too short (minimum is 4 characters), can't be blank"
|
||||||
|
create(:budget_investment, heading: heading,title: "Get SH", author: daniel, created_at: 1.day.ago)
|
||||||
|
|
||||||
|
login_as(daniel)
|
||||||
|
|
||||||
|
visit user_path(daniel, filter: "budget_investments")
|
||||||
|
click_link("Edit", match: :first)
|
||||||
|
fill_in "Title", with: ""
|
||||||
|
check "budget_investment_terms_of_service"
|
||||||
|
|
||||||
|
click_button "Update Investment"
|
||||||
|
|
||||||
|
expect(page).to have_content message_error
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Another User can't edit budget investment" do
|
||||||
|
message_error = "You do not have permission to carry out the action 'edit' on budget/investment"
|
||||||
|
admin = create(:administrator)
|
||||||
|
daniel = create(:user, :level_two)
|
||||||
|
investment = create(:budget_investment, heading: heading, author: daniel)
|
||||||
|
|
||||||
|
login_as(admin.user)
|
||||||
|
visit edit_budget_investment_path(budget, investment)
|
||||||
|
|
||||||
|
expect(page).to have_content message_error
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Errors on create" do
|
scenario "Errors on create" do
|
||||||
login_as(author)
|
login_as(author)
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ describe Abilities::Administrator do
|
|||||||
|
|
||||||
it { should be_able_to(:create, Budget::ValuatorAssignment) }
|
it { should be_able_to(:create, Budget::ValuatorAssignment) }
|
||||||
|
|
||||||
it { should be_able_to(:update, Budget::Investment) }
|
it { should be_able_to(:admin_update, Budget::Investment) }
|
||||||
it { should be_able_to(:hide, Budget::Investment) }
|
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, :valuating))) }
|
||||||
|
|||||||
@@ -259,6 +259,11 @@ describe Abilities::Common do
|
|||||||
it { should_not be_able_to(:destroy, own_investment_in_selecting_budget) }
|
it { should_not be_able_to(:destroy, own_investment_in_selecting_budget) }
|
||||||
it { should_not be_able_to(:destroy, own_investment_in_balloting_budget) }
|
it { should_not be_able_to(:destroy, own_investment_in_balloting_budget) }
|
||||||
|
|
||||||
|
it { should be_able_to(:edit, own_investment_in_accepting_budget) }
|
||||||
|
it { should_not be_able_to(:edit, own_investment_in_reviewing_budget) }
|
||||||
|
it { should_not be_able_to(:edit, own_investment_in_selecting_budget) }
|
||||||
|
it { should_not be_able_to(:edit, own_investment_in_balloting_budget) }
|
||||||
|
|
||||||
it { should be_able_to(:create, ballot_in_balloting_budget) }
|
it { should be_able_to(:create, ballot_in_balloting_budget) }
|
||||||
it { should_not be_able_to(:create, ballot_in_accepting_budget) }
|
it { should_not be_able_to(:create, ballot_in_accepting_budget) }
|
||||||
it { should_not be_able_to(:create, ballot_in_selecting_budget) }
|
it { should_not be_able_to(:create, ballot_in_selecting_budget) }
|
||||||
|
|||||||
Reference in New Issue
Block a user