diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index dbfcfea65..1efdc69b7 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -49,7 +49,6 @@ //= require forms //= require tracks //= require valuation_budget_investment_form -//= require valuation_spending_proposal_form //= require embed_video //= require fixed_bar //= require banners @@ -105,7 +104,6 @@ var initialize_modules = function() { App.Forms.initialize(); App.Tracks.initialize(); App.ValuationBudgetInvestmentForm.initialize(); - App.ValuationSpendingProposalForm.initialize(); App.EmbedVideo.initialize(); App.FixedBar.initialize(); App.Banners.initialize(); diff --git a/app/assets/javascripts/valuation_spending_proposal_form.js.coffee b/app/assets/javascripts/valuation_spending_proposal_form.js.coffee deleted file mode 100644 index 804077287..000000000 --- a/app/assets/javascripts/valuation_spending_proposal_form.js.coffee +++ /dev/null @@ -1,32 +0,0 @@ -App.ValuationSpendingProposalForm = - - showFeasibleFields: -> - $("#valuation_spending_proposal_edit_form #not_feasible_fields").hide("down") - $("#valuation_spending_proposal_edit_form #feasible_fields").show() - - showNotFeasibleFields: -> - $("#valuation_spending_proposal_edit_form #feasible_fields").hide("down") - $("#valuation_spending_proposal_edit_form #not_feasible_fields").show() - - showAllFields: -> - $("#valuation_spending_proposal_edit_form #feasible_fields").show("down") - $("#valuation_spending_proposal_edit_form #not_feasible_fields").show("down") - - showFeasibilityFields: -> - feasible = $("#valuation_spending_proposal_edit_form input[type=radio][name='spending_proposal[feasible]']:checked").val() - if feasible == "true" - App.ValuationSpendingProposalForm.showFeasibleFields() - else if feasible == "false" - App.ValuationSpendingProposalForm.showNotFeasibleFields() - - - showFeasibilityFieldsOnChange: -> - $("#valuation_spending_proposal_edit_form input[type=radio][name='spending_proposal[feasible]']").change -> - App.ValuationSpendingProposalForm.showAllFields() - App.ValuationSpendingProposalForm.showFeasibilityFields() - - - initialize: -> - App.ValuationSpendingProposalForm.showFeasibilityFields() - App.ValuationSpendingProposalForm.showFeasibilityFieldsOnChange() - false diff --git a/app/controllers/admin/valuators_controller.rb b/app/controllers/admin/valuators_controller.rb index cb1960529..10a5c6fdd 100644 --- a/app/controllers/admin/valuators_controller.rb +++ b/app/controllers/admin/valuators_controller.rb @@ -43,10 +43,6 @@ class Admin::ValuatorsController < Admin::BaseController redirect_to admin_valuators_path end - def summary - @valuators = Valuator.order(spending_proposals_count: :desc) - end - private def valuator_params diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb deleted file mode 100644 index 04000f8f8..000000000 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ /dev/null @@ -1,85 +0,0 @@ -class Valuation::SpendingProposalsController < Valuation::BaseController - include FeatureFlags - feature_flag :spending_proposals - - before_action :restrict_access_to_assigned_items, only: [:show, :edit, :valuate] - - has_filters %w{valuating valuation_finished}, only: :index - - load_and_authorize_resource - - def index - @geozone_filters = geozone_filters - @spending_proposals = if current_user.valuator? - SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter) - .order(cached_votes_up: :desc) - .page(params[:page]) - else - SpendingProposal.none.page(params[:page]) - end - end - - def valuate - if valid_price_params? && @spending_proposal.update(valuation_params) - - if @spending_proposal.unfeasible_email_pending? - @spending_proposal.send_unfeasible_email - end - - redirect_to valuation_spending_proposal_path(@spending_proposal), notice: t("valuation.spending_proposals.notice.valuate") - else - render action: :edit - end - end - - private - - def geozone_filters - spending_proposals = SpendingProposal.by_valuator(current_user.valuator.try(:id)).valuation_open.all.to_a - - [ { name: t("valuation.spending_proposals.index.geozone_filter_all"), - id: nil, - pending_count: spending_proposals.size - }, - { name: t("geozones.none"), - id: "all", - pending_count: spending_proposals.count{|x| x.geozone_id.nil?} - } - ] + Geozone.all.order(name: :asc).collect do |g| - { name: g.name, - id: g.id, - pending_count: spending_proposals.count{|x| x.geozone_id == g.id} - } - end.select{ |x| x[:pending_count] > 0 } - end - - def valuation_params - params[:spending_proposal][:feasible] = nil if params[:spending_proposal][:feasible] == "nil" - - params.require(:spending_proposal).permit(:price, :price_first_year, :price_explanation, :feasible, :feasible_explanation, - :time_scope, :valuation_finished, :internal_comments) - end - - def params_for_current_valuator - params.merge(valuator_id: current_user.valuator.id) - end - - def restrict_access_to_assigned_items - return if current_user.administrator? || - ValuationAssignment.exists?(spending_proposal_id: params[:id], valuator_id: current_user.valuator.id) - raise ActionController::RoutingError.new("Not Found") - end - - def valid_price_params? - if /\D/.match params[:spending_proposal][:price] - @spending_proposal.errors.add(:price, I18n.t("spending_proposals.wrong_price_format")) - end - - if /\D/.match params[:spending_proposal][:price_first_year] - @spending_proposal.errors.add(:price_first_year, I18n.t("spending_proposals.wrong_price_format")) - end - - @spending_proposal.errors.empty? - end - -end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index a72997dbf..c37e06f65 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -59,7 +59,6 @@ module Abilities can :manage, Dashboard::Action - can [:read, :update, :valuate, :destroy, :summary], SpendingProposal can [:index, :read, :new, :create, :update, :destroy, :calculate_winners], Budget can [:read, :create, :update, :destroy], Budget::Group can [:read, :create, :update, :destroy], Budget::Heading diff --git a/app/models/abilities/valuator.rb b/app/models/abilities/valuator.rb index 0e1213070..fcfa0a0c7 100644 --- a/app/models/abilities/valuator.rb +++ b/app/models/abilities/valuator.rb @@ -5,7 +5,6 @@ module Abilities def initialize(user) valuator = user.valuator - can [:read, :update, :valuate], SpendingProposal can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.assigned_investment_ids can [:valuate], Budget::Investment, { id: valuator.assigned_investment_ids, valuation_finished: false } cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: "finished" } diff --git a/app/models/valuation_assignment.rb b/app/models/valuation_assignment.rb deleted file mode 100644 index 2aaea14fb..000000000 --- a/app/models/valuation_assignment.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ValuationAssignment < ApplicationRecord - belongs_to :valuator, counter_cache: :spending_proposals_count - belongs_to :spending_proposal, counter_cache: true -end diff --git a/app/models/valuator.rb b/app/models/valuator.rb index 70c0a8201..985984a78 100644 --- a/app/models/valuator.rb +++ b/app/models/valuator.rb @@ -4,8 +4,6 @@ class Valuator < ApplicationRecord delegate :name, :email, :name_and_email, to: :user - has_many :valuation_assignments, dependent: :destroy - has_many :spending_proposals, through: :valuation_assignments has_many :valuator_assignments, dependent: :destroy, class_name: "Budget::ValuatorAssignment" has_many :investments, through: :valuator_assignments, class_name: "Budget::Investment" diff --git a/app/views/admin/spending_proposals/_assigned_valuators.html.erb b/app/views/admin/spending_proposals/_assigned_valuators.html.erb deleted file mode 100644 index 09e144dcd..000000000 --- a/app/views/admin/spending_proposals/_assigned_valuators.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -
- <%= f.submit(class: "button", value: t("admin.spending_proposals.edit.submit_button")) %> -
-<% end %> - -<%= t("admin.spending_proposals.show.assigned_admin") %>: - <%= @spending_proposal.administrator.try(:name_and_email) || t("admin.spending_proposals.show.undefined") %> -
- - - -- <%= t("admin.spending_proposals.show.assigned_valuators") %>: - <% if @spending_proposal.valuators.any? %> - <%= @spending_proposal.valuators.collect(&:name_and_email).join(", ") %> - <% else %> - <%= t("admin.spending_proposals.show.undefined") %> - <% end %> -
- -- <%= link_to t("admin.spending_proposals.show.edit_classification"), - edit_admin_spending_proposal_path(@spending_proposal, - {anchor: 'classification'}.merge(@filter_params.to_h)) %> -
- -- <%= link_to t("admin.spending_proposals.show.edit_dossier"), - edit_valuation_spending_proposal_path(@spending_proposal) %> -
- diff --git a/app/views/admin/spending_proposals/summary.html.erb b/app/views/admin/spending_proposals/summary.html.erb deleted file mode 100644 index 3bd1da060..000000000 --- a/app/views/admin/spending_proposals/summary.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -<%= link_to admin_spending_proposals_path, class: "back" do %> - - <%= t("shared.back") %> -<% end %> - -| <%= t("admin.valuators.summary.valuator_name") %> | -<%= t("admin.valuators.summary.finished_and_feasible_count") %> | -<%= t("admin.valuators.summary.finished_and_unfeasible_count") %> | -<%= t("admin.valuators.summary.finished_count") %> | -<%= t("admin.valuators.summary.in_evaluation_count") %> | -<%= t("admin.valuators.summary.total_count") %> | -<%= t("admin.valuators.summary.cost") %> | - - <% @valuators.each do |valuator| %> -
|---|---|---|---|---|---|---|
| - <%= valuator.description_or_email %> - | -- <%= valuator.spending_proposals.finished_and_feasible.count %> - | -- <%= valuator.spending_proposals.finished_and_unfeasible.count %> - | -- <%= valuator.spending_proposals.valuation_finished.count %> - | -- <%= valuator.spending_proposals.valuating.count %> - | -- <%= valuator.spending_proposals.count %> - | -- <%= number_to_currency(valuator.spending_proposals.sum(:price)) %> - | -
- - <%= t("valuation.spending_proposals.show.price") %> - (<%= t("valuation.spending_proposals.show.currency") %>): - - <% if @spending_proposal.price.present? %> - <%= @spending_proposal.price %> - <% else %> - <%= t("valuation.spending_proposals.show.undefined") %> - <% end %> -
- -- - <%= t("valuation.spending_proposals.show.price_first_year") %> - (<%= t("valuation.spending_proposals.show.currency") %>): - - - <% if @spending_proposal.price_first_year.present? %> - <%= @spending_proposal.price_first_year %> - <% else %> - <%= t("valuation.spending_proposals.show.undefined") %> - <% end %> -
- -<%= explanation_field @spending_proposal.price_explanation %> - -- <%= t("valuation.spending_proposals.show.time_scope") %>: - <% if @spending_proposal.time_scope.present? %> - <%= @spending_proposal.time_scope %> - <% else %> - <%= t("valuation.spending_proposals.show.undefined") %> - <% end %> -
- -- <%= t("valuation.spending_proposals.show.feasibility") %>: - <%= t("valuation.spending_proposals.show.#{@spending_proposal.feasibility}") %> -
- -<%= explanation_field @spending_proposal.feasible_explanation %> - -<% if @spending_proposal.valuation_finished %> -- <%= t("valuation.spending_proposals.show.valuation_finished") %> -
-<% end %> - -<% if @spending_proposal.internal_comments.present? %> -<%= text_with_links @spending_proposal.external_url %>
-<% end %> - -<%= t("valuation.spending_proposals.show.by") %>: - <%= link_to @spending_proposal.author.name, user_path(@spending_proposal.author) %> -
- -<% if @spending_proposal.association_name.present? %> -<%= t("valuation.spending_proposals.show.association_name") %>: - <%= @spending_proposal.association_name %> -
-<% end %> - -<%= t("valuation.spending_proposals.show.geozone") %>: - <%= geozone_name(@spending_proposal) %> -
- -<%= t("valuation.spending_proposals.show.sent") %>: - <%= l @spending_proposal.created_at, format: :datetime %> -
- -<%= t("valuation.spending_proposals.show.assigned_admin") %>: - <% if @spending_proposal.administrator.present? %> - <%= @spending_proposal.administrator.name %> (<%= @spending_proposal.administrator.email %>) - <% else %> - <%= t("valuation.spending_proposals.show.undefined") %> - <% end %> -
- -<%= t("valuation.spending_proposals.show.assigned_valuators") %>:
-| - <%= spending_proposal.id %> - | -- <%= link_to spending_proposal.title, valuation_spending_proposal_path(spending_proposal) %> - | -- <%= link_to t("valuation.spending_proposals.index.edit"), edit_valuation_spending_proposal_path(spending_proposal) %> - | -- <%= assigned_valuators_info(spending_proposal.valuators) %> - | -- <%= geozone_name(spending_proposal) %> - | -
<%= text_with_links @spending_proposal.external_url %>
-<% end %> - -<%= t("valuation.spending_proposals.show.by") %>: - <%= link_to @spending_proposal.author.name, user_path(@spending_proposal.author) %> -
- -<% if @spending_proposal.association_name.present? %> -<%= t("valuation.spending_proposals.show.association_name") %>: - <%= @spending_proposal.association_name %> -
-<% end %> - -<%= t("valuation.spending_proposals.show.geozone") %>: - <%= geozone_name(@spending_proposal) %> -
- -<%= t("valuation.spending_proposals.show.sent") %>: - <%= l @spending_proposal.created_at, format: :datetime %> -
- -<%= t("valuation.spending_proposals.show.assigned_admin") %>: - <% if @spending_proposal.administrator.present? %> - <%= @spending_proposal.administrator.name_and_email %> - <% else %> - <%= t("valuation.spending_proposals.show.undefined") %> - <% end %> -
- -<%= t("valuation.spending_proposals.show.assigned_valuators") %>:
-- <%= link_to t("valuation.spending_proposals.show.edit_dossier"), edit_valuation_spending_proposal_path(@spending_proposal) %> -
- -<%= render "written_by_valuators" %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index c4c4b55e6..0f8a228b9 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -168,7 +168,6 @@ ignore_unused: - "moderation.budget_investments.index.order*" - "moderation.proposal_notifications.index.filter*" - "moderation.proposal_notifications.index.order*" - - "valuation.spending_proposals.index.filter*" - "valuation.budgets.index.filter*" - "valuation.budget_investments.index.filter*" - "users.show.filters.*" diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 5653a0712..b33e5dd84 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -715,7 +715,6 @@ en: content_block: update: "Update Block" title_moderated_content: Moderated content - title_budgets: Budgets title_profiles: Profiles title_settings: Settings title_site_customization: Site content @@ -906,15 +905,6 @@ en: delete: Delete search: title: "Valuators: User search" - summary: - title: Valuator summary for investment projects - valuator_name: Valuator - finished_and_feasible_count: Finished and feasible - finished_and_unfeasible_count: Finished and unfeasible - finished_count: Finished - in_evaluation_count: In evaluation - total_count: Total - cost: Cost form: edit_title: "Valuators: Edit valuator" update: "Update valuator" @@ -1378,16 +1368,6 @@ en: tags: Tags tags_placeholder: "Write the tags you want separated by commas (,)" undefined: Undefined - summary: - title: Summary for investment projects - title_proposals_with_supports: Summary for investment projects with supports - geozone_name: Scope - finished_and_feasible_count: Finished and feasible - finished_and_unfeasible_count: Finished and unfeasible - finished_count: Finished - in_evaluation_count: In evaluation - total_count: Total - cost_for_geozone: Cost geozones: index: title: Geozone diff --git a/config/locales/en/valuation.yml b/config/locales/en/valuation.yml index b918020af..fbf8c9359 100644 --- a/config/locales/en/valuation.yml +++ b/config/locales/en/valuation.yml @@ -5,7 +5,6 @@ en: menu: title: Valuation budgets: Participatory budgets - spending_proposals: Spending proposals budgets: index: title: Participatory budgets @@ -77,52 +76,3 @@ en: valuate: "Dossier updated" valuation_comments: Valuation comments not_in_valuating_phase: Investments can only be valuated when Budget is in valuating phase - spending_proposals: - index: - geozone_filter_all: All zones - filters: - valuation_open: Open - valuating: Under valuation - valuation_finished: Valuation finished - title: Investment projects for participatory budgeting - edit: Edit - show: - back: Back - heading: Investment project - info: Author info - association_name: Association - by: Sent by - sent: Sent at - geozone: Scope - dossier: Dossier - edit_dossier: Edit dossier - price: Price - price_first_year: Cost during the first year - currency: "€" - feasibility: Feasibility - feasible: Feasible - not_feasible: Not feasible - undefined: Undefined - valuation_finished: Valuation finished - time_scope: Time scope - internal_comments: Internal comments - responsibles: Responsibles - assigned_admin: Assigned admin - assigned_valuators: Assigned valuators - edit: - dossier: Dossier - price_html: "Price (%{currency})" - price_first_year_html: "Cost during the first year (%{currency})" - currency: "€" - price_explanation_html: Price explanation - feasibility: Feasibility - feasible: Feasible - not_feasible: Not feasible - undefined_feasible: Pending - feasible_explanation_html: Feasibility explanation - valuation_finished: Valuation finished - time_scope_html: Time scope - internal_comments_html: Internal comments - save: Save changes - notice: - valuate: "Dossier updated" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 05183ebc6..68f9099b9 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -905,15 +905,6 @@ es: delete: Borrar search: title: "Evaluadores: Búsqueda de usuarios" - summary: - title: Resumen de evaluación de proyectos de gasto - valuator_name: Evaluador - finished_and_feasible_count: Finalizadas viables - finished_and_unfeasible_count: Finalizadas inviables - finished_count: Finalizadas - in_evaluation_count: En evaluación - total_count: Total - cost: Coste total form: edit_title: "Evaluadores: Editar evaluador" update: "Actualizar evaluador" diff --git a/config/locales/es/valuation.yml b/config/locales/es/valuation.yml index 9d33bea2b..5117c43c9 100644 --- a/config/locales/es/valuation.yml +++ b/config/locales/es/valuation.yml @@ -5,7 +5,6 @@ es: menu: title: Evaluación budgets: Presupuestos participativos - spending_proposals: Propuestas de inversión budgets: index: title: Presupuestos participativos @@ -77,52 +76,3 @@ es: valuate: "Dossier actualizado" valuation_comments: Comentarios de evaluación not_in_valuating_phase: Los proyectos sólo pueden ser evaluados cuando el Presupuesto esté en fase de evaluación - spending_proposals: - index: - geozone_filter_all: Todos los ámbitos de actuación - filters: - valuation_open: Abiertas - valuating: En evaluación - valuation_finished: Evaluación finalizada - title: Propuestas de inversión para presupuestos participativos - edit: Editar - show: - back: Volver - heading: Propuesta de inversión - info: Datos de envío - association_name: Asociación - by: Enviada por - sent: Fecha de creación - geozone: Ámbito de actuación - dossier: Informe - edit_dossier: Editar informe - price: Coste - price_first_year: Coste en el primer año - currency: "€" - feasibility: Viabilidad - feasible: Viable - not_feasible: No viable - undefined: Sin definir - valuation_finished: Informe finalizado - time_scope: Plazo de ejecución - internal_comments: Comentarios internos - responsibles: Responsables - assigned_admin: Administrador asignado - assigned_valuators: Evaluadores asignados - edit: - dossier: Informe - price_html: "Coste (%{currency}) (dato público)" - price_first_year_html: "Coste en el primer año (%{currency}) (opcional, privado)" - currency: "€" - price_explanation_html: Informe de coste (opcional, dato público) - feasibility: Viabilidad - feasible: Viable - not_feasible: Inviable - undefined_feasible: Sin decidir - feasible_explanation_html: Informe de inviabilidad (en caso de que lo sea, dato público) - valuation_finished: Informe finalizado - time_scope_html: Plazo de ejecución (opcional, dato no público) - internal_comments_html: Comentarios y observaciones (para responsables internos, dato no público) - save: Guardar cambios - notice: - valuate: "Informe actualizado" diff --git a/config/routes/valuation.rb b/config/routes/valuation.rb index 743bc1c72..560e26bef 100644 --- a/config/routes/valuation.rb +++ b/config/routes/valuation.rb @@ -1,10 +1,6 @@ namespace :valuation do root to: "budgets#index" - resources :spending_proposals, only: [:index, :show, :edit] do - patch :valuate, on: :member - end - resources :budgets, only: :index do resources :budget_investments, only: [:index, :show, :edit] do patch :valuate, on: :member diff --git a/db/dev_seeds/spending_proposals.rb b/db/dev_seeds/spending_proposals.rb index 149b56ee5..3e140561d 100644 --- a/db/dev_seeds/spending_proposals.rb +++ b/db/dev_seeds/spending_proposals.rb @@ -22,9 +22,3 @@ section "Creating Spending Proposals" do terms_of_service: "1") end end - -section "Creating Valuation Assignments" do - (1..17).to_a.sample.times do - SpendingProposal.all.sample.valuators << Valuator.first - end -end diff --git a/db/migrate/20190311220711_destroy_spending_proposal_valuations.rb b/db/migrate/20190311220711_destroy_spending_proposal_valuations.rb new file mode 100644 index 000000000..5f58e8469 --- /dev/null +++ b/db/migrate/20190311220711_destroy_spending_proposal_valuations.rb @@ -0,0 +1,5 @@ +class DestroySpendingProposalValuations < ActiveRecord::Migration + def change + drop_table :valuation_assignments + end +end diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index ab15b8956..1d1acb222 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -67,11 +67,6 @@ describe Abilities::Administrator do it { should be_able_to(:comment_as_administrator, legislation_question) } it { should_not be_able_to(:comment_as_moderator, legislation_question) } - it { should be_able_to(:read, SpendingProposal) } - it { should be_able_to(:update, SpendingProposal) } - it { should be_able_to(:valuate, SpendingProposal) } - it { should be_able_to(:destroy, SpendingProposal) } - it { should be_able_to(:create, Budget) } it { should be_able_to(:update, Budget) } it { should be_able_to(:read_results, Budget) } diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb index c9764c831..096206389 100644 --- a/spec/models/abilities/valuator_spec.rb +++ b/spec/models/abilities/valuator_spec.rb @@ -21,9 +21,11 @@ describe Abilities::Valuator do finished_assigned_investment.valuators << valuator end - it { should be_able_to(:read, SpendingProposal) } - it { should be_able_to(:update, SpendingProposal) } - it { should be_able_to(:valuate, SpendingProposal) } + it "cannot valuate an assigned investment with a finished valuation" do + assigned_investment.update(valuation_finished: true) + + should_not be_able_to(:valuate, assigned_investment) + end it "cannot valuate an assigned investment with a finished valuation" do assigned_investment.update(valuation_finished: true)