Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Budget Investment only in accepting phase #3716

Next Next commit
Edit Budget Investment only in accepting phase
  • Loading branch information
denialtorres committed Sep 22, 2019
commit d75742c6116af6b7b0de2729fc20544d2511482e
19 changes: 17 additions & 2 deletions app/controllers/budgets/investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InvestmentsController < ApplicationController
before_action :load_ballot, only: [:index, :show]
before_action :load_heading, only: [:index, :show]
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_view, only: :index
before_action :load_content_blocks, only: :index
Expand Down Expand Up @@ -77,6 +77,21 @@ def create
end
end

def edit
if @investment.author == current_user
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
return true
else
redirect_to root_path,
notice: 'You have to be the original author of the project to edit it'
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
end
end

def update
@investment.update(investment_params)
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
redirect_to budget_investment_path(@budget, @investment),
notice: 'It was updated successfully.'
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
end

def destroy
@investment.destroy
redirect_to user_path(current_user, filter: "budget_investments"), notice: t("flash.actions.destroy.budget_investment")
Expand Down Expand Up @@ -125,7 +140,7 @@ def load_investment_votes(investments)
end

def investment_params
attributes = [:heading_id, :tag_list,
attributes = [:title, :description, :heading_id, :tag_list,
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
:organization_name, :location, :terms_of_service, :skip_map,
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
Expand Down
2 changes: 2 additions & 0 deletions app/models/abilities/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def initialize(user)
can :create, Legislation::Answer

can :create, Budget::Investment, budget: { phase: "accepting" }
can :edit, Budget::Investment, budget: { phase: "accepting" }
can :update, Budget::Investment, budget: { phase: "accepting" }
javierm marked this conversation as resolved.
Show resolved Hide resolved
can :suggest, Budget::Investment, budget: { phase: "accepting" }
can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id
can :vote, Budget::Investment, budget: { phase: "selecting" }
Expand Down
95 changes: 95 additions & 0 deletions app/views/budgets/investments/_form_edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<%= form_for(@investment, url: budget_investment_path(@budget, @investment), html: { multipart: true }) do |f| %>
<%= render 'shared/errors', resource: @investment %>

<div class="row">
<div class="small-12 medium-8 column">
<h3><%= @investment.heading.name %></h3>
</div>

<div class="small-12 column">
<%= f.text_field :title, maxlength: Budget::Investment.title_max_length, data: { js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_budget_investments_path(@budget) }%>
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div id="js-suggest"></div>

<%= f.invisible_captcha :subtitle %>

<div class="ckeditor small-12 column">
<%= f.cktext_area :description, maxlength: Budget::Investment.description_max_length, ckeditor: { language: I18n.locale } %>
</div>

<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render 'images/nested_image', imageable: @investment, f: f %>
</div>
<% end %>

<% if feature?(:allow_attached_documents) %>
<div class="documents small-12 column">
<%= render 'documents/nested_documents', documentable: @investment, f: f %>
</div>
<% end %>

<% if feature?(:map) %>
<div class="small-12 column">

<%= render 'map_locations/form_fields',
form: f,
map_location: @investment.map_location || MapLocation.new,
label: t("budgets.investments.form.map_location"),
help: t("budgets.investments.form.map_location_instructions"),
remove_marker_label: t("budgets.investments.form.map_remove_marker"),
parent_class: "budget_investment",
i18n_namespace: "budgets.investments" %>

</div>
<% end %>

<div class="small-12 column">
<%= f.label :location, t("budgets.investments.form.location") %>
<%= f.text_field :location, label: false %>
</div>

<div class="small-12 column">
<%= f.text_field :organization_name %>
</div>

<div class="small-12 column">
<%= f.label :tag_list, t("budgets.investments.form.tags_label") %>
<p class="help-text" id="tags-list-help-text"><%= t("budgets.investments.form.tags_instructions") %></p>

<div id="category_tags" class="tags">
<%= f.label :category_tag_list, t("budgets.investments.form.tag_category_label") %>
<% @categories.each do |tag| %>
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
</div>

<br>
<%= f.text_field :tag_list, value: @investment.tag_list.to_s,
label: false,
placeholder: t("budgets.investments.form.tags_placeholder"),
aria: {describedby: "tags-list-help-text"},
class: 'js-tag-list tag-autocomplete',
data: {js_url: suggest_tags_path} %>
</div>

<% unless current_user.manager? %>

<div class="small-12 column">
<%= f.label :terms_of_service do %>
<%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %>
<span class="checkbox">
<%= t("form.accept_terms",
policy: link_to(t("form.policy"), "/privacy", target: "blank"),
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %>
</span>
<% end %>
</div>

<% end %>

<div class="actions small-12 medium-6 large-4 end column">
<%= f.submit(nil, class: "button expanded") %>
</div>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/budgets/investments/edit.html.erb
Original file line number Diff line number Diff line change
@@ -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_edit', form_url: budget_investments_path(@budget) %>
javierm marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
4 changes: 4 additions & 0 deletions app/views/users/_budget_investment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
method: :delete, class: "button hollow alert expanded",
data: {confirm: "#{t("users.show.delete_alert")}"} %>
<% end %>
<% if can? :update, budget_investment %>
<%= link_to t("shared.edit"), edit_budget_investment_path(budget_investment.budget, budget_investment),
method: :get, class: "button hollow expanded" %>
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
<% end %>
</td>
</tr>
2 changes: 1 addition & 1 deletion config/routes/budget.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resources :budgets, only: [:show, :index] do
resources :groups, controller: "budgets/groups", only: [:show]
resources :investments, controller: "budgets/investments", only: [:index, :new, :create, :show, :destroy] do
resources :investments, controller: "budgets/investments", only: [:index, :new, :create, :show, :destroy, :edit, :update] do
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
denialtorres marked this conversation as resolved.
Show resolved Hide resolved
member do
post :vote
put :flag
Expand Down