From f7e96067b094375daf5aea533112ad42025231be Mon Sep 17 00:00:00 2001 From: iagirre Date: Mon, 25 Sep 2017 15:40:17 +0200 Subject: [PATCH 01/26] Actions for budgets' headings added. Edit headings, delete headings if not budget investments associated and add link in order to see budgets investments filtered by the heading. Cambios para hacer commit: modificado: app/controllers/admin/budget_headings_controller.rb modificado: app/models/budget/heading.rb nuevo archivo: app/views/admin/budget_headings/_errors.html.erb nuevo archivo: app/views/admin/budget_headings/edit.js.erb nuevo archivo: app/views/admin/budget_headings/update.js.erb modificado: app/views/admin/budgets/_group.html.erb nuevo archivo: app/views/admin/budgets/_heading.html.erb nuevo archivo: app/views/admin/budgets/_heading_form.html.erb modificado: config/locales/en/activerecord.yml modificado: config/locales/es/activerecord.yml modificado: spec/features/admin/budgets_spec.rb modificado: spec/models/budget/heading_spec.rb --- .../admin/budget_headings_controller.rb | 21 ++++++++ app/models/budget/heading.rb | 6 ++- .../admin/budget_headings/_errors.html.erb | 7 +++ app/views/admin/budget_headings/edit.js.erb | 1 + app/views/admin/budget_headings/update.js.erb | 5 ++ app/views/admin/budgets/_group.html.erb | 48 +++---------------- app/views/admin/budgets/_heading.html.erb | 27 +++++++++++ .../admin/budgets/_heading_form.html.erb | 30 ++++++++++++ config/locales/en/activerecord.yml | 4 ++ config/locales/es/activerecord.yml | 4 ++ spec/features/admin/budgets_spec.rb | 38 +++++++++++++++ spec/models/budget/heading_spec.rb | 13 +++++ 12 files changed, 161 insertions(+), 43 deletions(-) create mode 100644 app/views/admin/budget_headings/_errors.html.erb create mode 100644 app/views/admin/budget_headings/edit.js.erb create mode 100644 app/views/admin/budget_headings/update.js.erb create mode 100644 app/views/admin/budgets/_heading.html.erb create mode 100644 app/views/admin/budgets/_heading_form.html.erb diff --git a/app/controllers/admin/budget_headings_controller.rb b/app/controllers/admin/budget_headings_controller.rb index eea93716f..ee1878edf 100644 --- a/app/controllers/admin/budget_headings_controller.rb +++ b/app/controllers/admin/budget_headings_controller.rb @@ -9,6 +9,27 @@ class Admin::BudgetHeadingsController < Admin::BaseController @headings = @budget_group.headings end + def edit + @budget = Budget.find params[:budget_id] + @budget_group = @budget.groups.find params[:budget_group_id] + @heading = Budget::Heading.find params[:id] + end + + def update + @budget = Budget.find params[:budget_id] + @budget_group = @budget.groups.find params[:budget_group_id] + @heading = Budget::Heading.find params[:id] + @heading.assign_attributes(budget_heading_params) + @errors = @heading.errors.full_messages unless @heading.save + end + + def destroy + @heading = Budget::Heading.find params[:id] + @heading.destroy + @budget = Budget.find params[:budget_id] + redirect_to admin_budget_path(@budget) + end + private def budget_heading_params diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index 1a232c75e..10feaa909 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -20,7 +20,11 @@ class Budget end def name_exists_in_budget_headings - group.budget.headings.where(name: name).any? + group.budget.headings.where(name: name).where.not(id: id).any? + end + + def can_be_deleted? + investments.empty? end end diff --git a/app/views/admin/budget_headings/_errors.html.erb b/app/views/admin/budget_headings/_errors.html.erb new file mode 100644 index 000000000..bb3e5482e --- /dev/null +++ b/app/views/admin/budget_headings/_errors.html.erb @@ -0,0 +1,7 @@ +
+ +
diff --git a/app/views/admin/budget_headings/edit.js.erb b/app/views/admin/budget_headings/edit.js.erb new file mode 100644 index 000000000..5f9ac48f8 --- /dev/null +++ b/app/views/admin/budget_headings/edit.js.erb @@ -0,0 +1 @@ +$("#heading-<%=@heading.id%>").html("<%= j render("admin/budgets/heading_form", group: @budget_group, budget: @budget, heading: @heading) %>"); diff --git a/app/views/admin/budget_headings/update.js.erb b/app/views/admin/budget_headings/update.js.erb new file mode 100644 index 000000000..d46e35386 --- /dev/null +++ b/app/views/admin/budget_headings/update.js.erb @@ -0,0 +1,5 @@ +<% if @errors %> + $("#heading-<%=@heading.id%> div#error_explanation").replaceWith("<%= j render("admin/budget_headings/errors", errors: @errors) %>"); +<% else %> + $("#heading-<%=@heading.id%>").html("<%= j render("admin/budgets/heading", group: @budget_group, budget: @budget, heading: @heading) %>"); +<% end %> diff --git a/app/views/admin/budgets/_group.html.erb b/app/views/admin/budgets/_group.html.erb index 8537fa477..d6a648f10 100644 --- a/app/views/admin/budgets/_group.html.erb +++ b/app/views/admin/budgets/_group.html.erb @@ -1,7 +1,7 @@ - @@ -11,7 +11,7 @@ - + @@ -29,51 +30,14 @@ - <% headings.each do |heading| %> - - - - - + <%= render "admin/budgets/heading", group: group, budget: @budget, heading: heading %> <% end %> diff --git a/app/views/admin/budgets/_heading.html.erb b/app/views/admin/budgets/_heading.html.erb new file mode 100644 index 000000000..7ffeca7a0 --- /dev/null +++ b/app/views/admin/budgets/_heading.html.erb @@ -0,0 +1,27 @@ + + + + + + \ No newline at end of file diff --git a/app/views/admin/budgets/_heading_form.html.erb b/app/views/admin/budgets/_heading_form.html.erb new file mode 100644 index 000000000..43a4797a8 --- /dev/null +++ b/app/views/admin/budgets/_heading_form.html.erb @@ -0,0 +1,30 @@ +<%= form_for [:admin, budget, group, heading], remote: true do |f| %> + + <%= f.text_field :name, + label: false, + maxlength: 50, + placeholder: t("admin.budgets.form.heading") %> + +
+
+ + <%= f.text_field :price, + label: false, + maxlength: 8, + placeholder: t("admin.budgets.form.amount") %> +
+
+
+
+ + <%= f.text_field :population, + label: false, + maxlength: 8, + placeholder: t("admin.budgets.form.population") %> +
+
+ + <%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %> + +
+<% end %> \ No newline at end of file diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 79982150c..0008eced6 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -107,6 +107,10 @@ en: budget/investment/milestone: title: "Title" description: "Description" + budget/heading: + name: "Heading name" + price: "Price" + population: "Population" comment: body: "Comment" user: "User" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index d409d1c5e..2315fc65a 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -99,6 +99,10 @@ es: title: "Título" location: "Ubicación" organization_name: "Si estás proponiendo en nombre de una organización o colectivo, escribe su nombre" + budget/heading: + name: "Nombre de la partida" + price: "Cantidad" + population: "Población" comment: body: "Comentario" user: "Usuario" diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index d4ed2d2ac..e21db46df 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -199,5 +199,43 @@ feature 'Admin budgets' do end end + scenario 'Update heading', :js do + budget = create(:budget, name: 'Yearly participatory budget') + group = create(:budget_group, budget: budget, name: 'Districts improvments') + heading = create(:budget_heading, group: group, name: "District 1") + heading = create(:budget_heading, group: group, name: "District 3") + + visit admin_budget_path(budget) + + within("#heading-#{heading.id}") do + click_link 'Edit' + + fill_in 'budget_heading_name', with: 'District 2' + fill_in 'budget_heading_price', with: '10000' + fill_in 'budget_heading_population', with: '6000' + click_button 'Save heading' + end + + expect(page).to have_content 'District 2' + expect(page).to have_content '10000' + expect(page).to have_content '6000' + end + + scenario 'Delete heading', :js do + budget = create(:budget, name: 'Yearly participatory budget') + group = create(:budget_group, budget: budget, name: 'Districts improvments') + heading = create(:budget_heading, group: group, name: "District 1") + + visit admin_budget_path(budget) + + expect(page).to have_content 'District 1' + + within("#heading-#{heading.id}") do + click_link 'Delete' + end + + expect(page).to_not have_content 'District 1' + end + end end diff --git a/spec/models/budget/heading_spec.rb b/spec/models/budget/heading_spec.rb index ee2e4c142..76ac82692 100644 --- a/spec/models/budget/heading_spec.rb +++ b/spec/models/budget/heading_spec.rb @@ -25,4 +25,17 @@ describe Budget::Heading do end end + describe "heading" do + it "can be deleted if not budget's investments associated" do + heading1 = create(:budget_heading, group: group, name: 'name') + heading2 = create(:budget_heading, group: group, name: 'name 2') + + create(:budget_investment, heading: heading1) + + expect(heading1.can_be_deleted?).to eq false + expect(heading2.can_be_deleted?).to eq true + + end + end + end From 1cd47da9d49441f23ff4b0d11279c6420ea5f127 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 21 Sep 2017 17:45:33 -0400 Subject: [PATCH 02/26] Split routes into small files for easier customization (#1852) --- config/initializers/routing.rb | 5 + config/routes.rb | 495 ++----------------------------- config/routes/account.rb | 3 + config/routes/admin.rb | 172 +++++++++++ config/routes/annotation.rb | 3 + config/routes/budget.rb | 19 ++ config/routes/comment.rb | 7 + config/routes/community.rb | 3 + config/routes/debate.rb | 14 + config/routes/devise.rb | 27 ++ config/routes/direct_upload.rb | 2 + config/routes/document.rb | 7 + config/routes/graphql.rb | 3 + config/routes/legislation.rb | 37 +++ config/routes/management.rb | 44 +++ config/routes/moderation.rb | 25 ++ config/routes/notification.rb | 5 + config/routes/officing.rb | 10 + config/routes/poll.rb | 10 + config/routes/proposal.rb | 17 ++ config/routes/related_content.rb | 6 + config/routes/tag.rb | 5 + config/routes/user.rb | 3 + config/routes/valuation.rb | 13 + config/routes/verification.rb | 9 + 25 files changed, 478 insertions(+), 466 deletions(-) create mode 100644 config/initializers/routing.rb create mode 100644 config/routes/account.rb create mode 100644 config/routes/admin.rb create mode 100644 config/routes/annotation.rb create mode 100644 config/routes/budget.rb create mode 100644 config/routes/comment.rb create mode 100644 config/routes/community.rb create mode 100644 config/routes/debate.rb create mode 100644 config/routes/devise.rb create mode 100644 config/routes/direct_upload.rb create mode 100644 config/routes/document.rb create mode 100644 config/routes/graphql.rb create mode 100644 config/routes/legislation.rb create mode 100644 config/routes/management.rb create mode 100644 config/routes/moderation.rb create mode 100644 config/routes/notification.rb create mode 100644 config/routes/officing.rb create mode 100644 config/routes/poll.rb create mode 100644 config/routes/proposal.rb create mode 100644 config/routes/related_content.rb create mode 100644 config/routes/tag.rb create mode 100644 config/routes/user.rb create mode 100644 config/routes/valuation.rb create mode 100644 config/routes/verification.rb diff --git a/config/initializers/routing.rb b/config/initializers/routing.rb new file mode 100644 index 000000000..32783d4a8 --- /dev/null +++ b/config/initializers/routing.rb @@ -0,0 +1,5 @@ +class ActionDispatch::Routing::Mapper + def draw(route_file) + instance_eval(File.read(Rails.root.join("config/routes/#{route_file}.rb"))) + end +end diff --git a/config/routes.rb b/config/routes.rb index fb1535b6c..c85deab68 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,484 +5,47 @@ Rails.application.routes.draw do get '/sandbox/*template' => 'sandbox#show' end - devise_for :users, controllers: { - registrations: 'users/registrations', - sessions: 'users/sessions', - confirmations: 'users/confirmations', - omniauth_callbacks: 'users/omniauth_callbacks' - } - devise_for :organizations, class_name: 'User', - controllers: { - registrations: 'organizations/registrations', - sessions: 'devise/sessions' - }, - skip: [:omniauth_callbacks] + mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? - devise_scope :organization do - get 'organizations/sign_up/success', to: 'organizations/registrations#success' - end - - devise_scope :user do - patch '/user/confirmation', to: 'users/confirmations#update', as: :update_user_confirmation - get '/user/registrations/check_username', to: 'users/registrations#check_username' - get 'users/sign_up/success', to: 'users/registrations#success' - get 'users/registrations/delete_form', to: 'users/registrations#delete_form' - delete 'users/registrations', to: 'users/registrations#delete' - get :finish_signup, to: 'users/registrations#finish_signup' - patch :do_finish_signup, to: 'users/registrations#do_finish_signup' - end + draw :account + draw :admin + draw :annotation + draw :budget + draw :comment + draw :community + draw :debate + draw :devise + draw :direct_upload + draw :document + draw :graphql + draw :legislation + draw :management + draw :moderation + draw :notification + draw :officing + draw :poll + draw :proposal + draw :related_content + draw :tag + draw :user + draw :valuation + draw :verification root 'welcome#index' get '/welcome', to: 'welcome#welcome' - get '/cuentasegura', to: 'welcome#verification', as: :cuentasegura - get '/consul.json', to: "installation#details" - resources :debates do - member do - post :vote - put :flag - put :unflag - put :mark_featured - put :unmark_featured - end - collection do - get :map - get :suggest - end - end - - resources :proposals do - member do - post :vote - post :vote_featured - put :flag - put :unflag - get :retire_form - get :share - patch :retire - end - collection do - get :map - get :suggest - get :summary - end - end - - resources :comments, only: [:create, :show], shallow: true do - member do - post :vote - put :flag - put :unflag - end - end - - 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 - member do - post :vote - end - collection { get :suggest } - end - resource :ballot, only: :show, controller: "budgets/ballots" do - resources :lines, controller: "budgets/ballot/lines", only: [:create, :destroy] - end - resource :results, only: :show, controller: "budgets/results" - end - - scope '/participatory_budget' do - resources :spending_proposals, only: [:index, :new, :create, :show, :destroy], path: 'investment_projects' do - post :vote, on: :member - end - end - + resources :stats, only: [:index] + resources :images, only: [:destroy] + resources :documents, only: [:destroy] resources :follows, only: [:create, :destroy] - resources :documents, only: [:destroy] - - resources :images, only: [:destroy] - - resources :direct_uploads, only: [:create] - delete "direct_uploads/destroy", to: "direct_uploads#destroy", as: :direct_upload_destroy - - resources :stats, only: [:index] - - resources :legacy_legislations, only: [:show], path: 'legislations' - - resources :annotations do - get :search, on: :collection - end - - resources :polls, only: [:show, :index] do - member do - get :stats - get :results - end - resources :questions, controller: 'polls/questions', shallow: true do - post :answer, on: :member - end - end - - namespace :legislation do - resources :processes, only: [:index, :show] do - member do - get :debate - get :draft_publication - get :allegations - get :result_publication - get :proposals - end - resources :questions, only: [:show] do - resources :answers, only: [:create] - end - resources :proposals do - member do - post :vote - put :flag - put :unflag - end - collection do - get :map - get :suggest - end - end - resources :draft_versions, only: [:show] do - get :go_to_version, on: :collection - get :changes - resources :annotations do - get :search, on: :collection - get :comments - post :new_comment - end - end - end - end - - resources :users, only: [:show] do - resources :direct_messages, only: [:new, :create, :show] - end - - resource :account, controller: "account", only: [:show, :update, :delete] do - get :erase, on: :collection - end - - resources :notifications, only: [:index, :show] do - put :mark_all_as_read, on: :collection - end - - resources :proposal_notifications, only: [:new, :create, :show] - - resource :verification, controller: "verification", only: [:show] - - resources :communities, only: [:show] do - resources :topics - end - - scope module: :verification do - resource :residence, controller: "residence", only: [:new, :create] - resource :sms, controller: "sms", only: [:new, :create, :edit, :update] - resource :verified_user, controller: "verified_user", only: [:show] - resource :email, controller: "email", only: [:new, :show, :create] - resource :letter, controller: "letter", only: [:new, :create, :show, :edit, :update] - end - - resources :tags do - collection do - get :suggest - end - end - - namespace :admin do - root to: "dashboard#index" - resources :organizations, only: :index do - get :search, on: :collection - member do - put :verify - put :reject - end - end - - resources :hidden_users, only: [:index, :show] do - member do - put :restore - put :confirm_hide - end - end - - resources :debates, only: :index do - member do - put :restore - put :confirm_hide - end - end - - resources :proposals, only: :index do - member do - put :restore - put :confirm_hide - end - end - - resources :spending_proposals, only: [:index, :show, :edit, :update] do - member do - patch :assign_admin - patch :assign_valuators - end - - get :summary, on: :collection - end - - resources :budgets do - member do - put :calculate_winners - end - - resources :budget_groups do - resources :budget_headings do - end - end - - resources :budget_investments, only: [:index, :show, :edit, :update] do - resources :budget_investment_milestones - member { patch :toggle_selection } - end - end - - resources :signature_sheets, only: [:index, :new, :create, :show] - - resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do - collection { get :search} - end - - resources :comments, only: :index do - member do - put :restore - put :confirm_hide - end - end - - resources :tags, only: [:index, :create, :update, :destroy] - resources :officials, only: [:index, :edit, :update, :destroy] do - get :search, on: :collection - end - - resources :settings, only: [:index, :update] - put :update_map, to: "settings#update_map" - - resources :moderators, only: [:index, :create, :destroy] do - get :search, on: :collection - end - - resources :valuators, only: [:index, :create, :destroy] do - get :search, on: :collection - get :summary, on: :collection - end - - resources :managers, only: [:index, :create, :destroy] do - get :search, on: :collection - end - - resources :administrators, only: [:index, :create, :destroy] do - get :search, on: :collection - end - - resources :users, only: [:index, :show] - - scope module: :poll do - resources :polls do - get :booth_assignments, on: :collection - patch :add_question, on: :member - - resources :booth_assignments, only: [:index, :show, :create, :destroy] do - get :search_booths, on: :collection - get :manage, on: :collection - end - - resources :officer_assignments, only: [:index, :create, :destroy] do - get :search_officers, on: :collection - get :by_officer, on: :collection - end - - resources :recounts, only: :index - resources :results, only: :index - end - - resources :officers do - get :search, on: :collection - end - - resources :booths do - get :available, on: :collection - - resources :shifts do - get :search_officers, on: :collection - end - end - - resources :questions, shallow: true do - resources :answers, except: [:index, :destroy], controller: 'questions/answers', shallow: true do - resources :images, controller: 'questions/answers/images' - resources :videos, controller: 'questions/answers/videos' - get :documents, to: 'questions/answers#documents' - end - post '/answers/order_answers', to: 'questions/answers#order_answers' - end - end - - resources :verifications, controller: :verifications, only: :index do - get :search, on: :collection - end - - resource :activity, controller: :activity, only: :show - resources :newsletters, only: :index do - get :users, on: :collection - end - resource :stats, only: :show do - get :proposal_notifications, on: :collection - get :direct_messages, on: :collection - get :polls, on: :collection - end - - namespace :legislation do - resources :processes do - resources :questions - resources :proposals - resources :draft_versions - end - end - - namespace :api do - resource :stats, only: :show - end - - resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy] - - namespace :site_customization do - resources :pages, except: [:show] - resources :images, only: [:index, :update, :destroy] - resources :content_blocks, except: [:show] - end - end - - namespace :moderation do - root to: "dashboard#index" - - resources :users, only: :index do - member do - put :hide - put :hide_in_moderation_screen - end - end - - resources :debates, only: :index do - put :hide, on: :member - put :moderate, on: :collection - end - - resources :proposals, only: :index do - put :hide, on: :member - put :moderate, on: :collection - end - - resources :comments, only: :index do - put :hide, on: :member - put :moderate, on: :collection - end - end - - 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 - end - end - end - - namespace :management do - root to: "dashboard#index" - - resources :document_verifications, only: [:index, :new, :create] do - post :check, on: :collection - end - - resources :email_verifications, only: [:new, :create] - - resources :user_invites, only: [:new, :create] - - resources :users, only: [:new, :create] do - collection do - delete :logout - delete :erase - end - end - - resource :account, controller: "account", only: [:show] - - get 'sign_in', to: 'sessions#create', as: :sign_in - - resource :session, only: [:create, :destroy] - resources :proposals, only: [:index, :new, :create, :show] do - post :vote, on: :member - get :print, on: :collection - end - - resources :spending_proposals, only: [:index, :new, :create, :show] do - post :vote, on: :member - get :print, on: :collection - end - - resources :budgets, only: :index do - collection do - get :create_investments - get :support_investments - get :print_investments - end - resources :investments, only: [:index, :new, :create, :show, :destroy], controller: 'budgets/investments' do - post :vote, on: :member - get :print, on: :collection - end - end - end - - namespace :officing do - resources :polls, only: [:index] do - get :final, on: :collection - - resources :results, only: [:new, :create, :index] - end - resource :residence, controller: "residence", only: [:new, :create] - resources :voters, only: [:new, :create] - root to: "dashboard#index" - end - - resources :related_contents, only: [:create] do - member do - put :score_positive - put :score_negative - end - end - - # GraphQL - get '/graphql', to: 'graphql#query' - post '/graphql', to: 'graphql#query' - - mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? - - mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/graphql' - - # more info pages + # More info pages get 'more-information', to: 'pages#show', id: 'more_info/index', as: 'more_info' get 'more-information/how-to-use', to: 'pages#show', id: 'more_info/how_to_use/index', as: 'how_to_use' get 'more-information/faq', to: 'pages#show', id: 'more_info/faq/index', as: 'faq' - # static pages + # Static pages get '/blog' => redirect("http://blog.consul/") resources :pages, path: '/', only: [:show] end diff --git a/config/routes/account.rb b/config/routes/account.rb new file mode 100644 index 000000000..2b377bc36 --- /dev/null +++ b/config/routes/account.rb @@ -0,0 +1,3 @@ +resource :account, controller: "account", only: [:show, :update, :delete] do + get :erase, on: :collection +end diff --git a/config/routes/admin.rb b/config/routes/admin.rb new file mode 100644 index 000000000..93a1a0cc8 --- /dev/null +++ b/config/routes/admin.rb @@ -0,0 +1,172 @@ +namespace :admin do + root to: "dashboard#index" + resources :organizations, only: :index do + get :search, on: :collection + member do + put :verify + put :reject + end + end + + resources :hidden_users, only: [:index, :show] do + member do + put :restore + put :confirm_hide + end + end + + resources :debates, only: :index do + member do + put :restore + put :confirm_hide + end + end + + resources :proposals, only: :index do + member do + put :restore + put :confirm_hide + end + end + + resources :spending_proposals, only: [:index, :show, :edit, :update] do + member do + patch :assign_admin + patch :assign_valuators + end + + get :summary, on: :collection + end + + resources :budgets do + member do + put :calculate_winners + end + + resources :budget_groups do + resources :budget_headings + end + + resources :budget_investments, only: [:index, :show, :edit, :update] do + resources :budget_investment_milestones + member { patch :toggle_selection } + end + end + + resources :signature_sheets, only: [:index, :new, :create, :show] + + resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do + collection { get :search } + end + + resources :comments, only: :index do + member do + put :restore + put :confirm_hide + end + end + + resources :tags, only: [:index, :create, :update, :destroy] + resources :officials, only: [:index, :edit, :update, :destroy] do + get :search, on: :collection + end + + resources :settings, only: [:index, :update] + put :update_map, to: "settings#update_map" + + resources :moderators, only: [:index, :create, :destroy] do + get :search, on: :collection + end + + resources :valuators, only: [:index, :create, :destroy] do + get :search, on: :collection + get :summary, on: :collection + end + + resources :managers, only: [:index, :create, :destroy] do + get :search, on: :collection + end + + resources :administrators, only: [:index, :create, :destroy] do + get :search, on: :collection + end + + resources :users, only: [:index, :show] + + scope module: :poll do + resources :polls do + get :booth_assignments, on: :collection + patch :add_question, on: :member + + resources :booth_assignments, only: [:index, :show, :create, :destroy] do + get :search_booths, on: :collection + get :manage, on: :collection + end + + resources :officer_assignments, only: [:index, :create, :destroy] do + get :search_officers, on: :collection + get :by_officer, on: :collection + end + + resources :recounts, only: :index + resources :results, only: :index + end + + resources :officers do + get :search, on: :collection + end + + resources :booths do + get :available, on: :collection + + resources :shifts do + get :search_officers, on: :collection + end + end + + resources :questions, shallow: true do + resources :answers, except: [:index, :destroy], controller: 'questions/answers' do + resources :images, controller: 'questions/answers/images' + resources :videos, controller: 'questions/answers/videos' + get :documents, to: 'questions/answers#documents' + end + post '/answers/order_answers', to: 'questions/answers#order_answers' + end + end + + resources :verifications, controller: :verifications, only: :index do + get :search, on: :collection + end + + resource :activity, controller: :activity, only: :show + + resources :newsletters, only: :index do + get :users, on: :collection + end + + resource :stats, only: :show do + get :proposal_notifications, on: :collection + get :direct_messages, on: :collection + get :polls, on: :collection + end + + namespace :legislation do + resources :processes do + resources :questions + resources :proposals + resources :draft_versions + end + end + + namespace :api do + resource :stats, only: :show + end + + resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy] + + namespace :site_customization do + resources :pages, except: [:show] + resources :images, only: [:index, :update, :destroy] + resources :content_blocks, except: [:show] + end +end diff --git a/config/routes/annotation.rb b/config/routes/annotation.rb new file mode 100644 index 000000000..7566f73d6 --- /dev/null +++ b/config/routes/annotation.rb @@ -0,0 +1,3 @@ +resources :annotations do + get :search, on: :collection +end diff --git a/config/routes/budget.rb b/config/routes/budget.rb new file mode 100644 index 000000000..3a06f3c7c --- /dev/null +++ b/config/routes/budget.rb @@ -0,0 +1,19 @@ +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 + member { post :vote } + collection { get :suggest } + end + + resource :ballot, only: :show, controller: "budgets/ballots" do + resources :lines, controller: "budgets/ballot/lines", only: [:create, :destroy] + end + + resource :results, only: :show, controller: "budgets/results" +end + +scope '/participatory_budget' do + resources :spending_proposals, only: [:index, :new, :create, :show, :destroy], path: 'investment_projects' do + post :vote, on: :member + end +end diff --git a/config/routes/comment.rb b/config/routes/comment.rb new file mode 100644 index 000000000..f3e525396 --- /dev/null +++ b/config/routes/comment.rb @@ -0,0 +1,7 @@ +resources :comments, only: [:create, :show], shallow: true do + member do + post :vote + put :flag + put :unflag + end +end diff --git a/config/routes/community.rb b/config/routes/community.rb new file mode 100644 index 000000000..9e010ffb7 --- /dev/null +++ b/config/routes/community.rb @@ -0,0 +1,3 @@ +resources :communities, only: [:show] do + resources :topics +end diff --git a/config/routes/debate.rb b/config/routes/debate.rb new file mode 100644 index 000000000..2345d150f --- /dev/null +++ b/config/routes/debate.rb @@ -0,0 +1,14 @@ +resources :debates do + member do + post :vote + put :flag + put :unflag + put :mark_featured + put :unmark_featured + end + + collection do + get :map + get :suggest + end +end diff --git a/config/routes/devise.rb b/config/routes/devise.rb new file mode 100644 index 000000000..e789aec52 --- /dev/null +++ b/config/routes/devise.rb @@ -0,0 +1,27 @@ +devise_for :users, controllers: { + registrations: 'users/registrations', + sessions: 'users/sessions', + confirmations: 'users/confirmations', + omniauth_callbacks: 'users/omniauth_callbacks' + } + +devise_scope :user do + patch '/user/confirmation', to: 'users/confirmations#update', as: :update_user_confirmation + get '/user/registrations/check_username', to: 'users/registrations#check_username' + get 'users/sign_up/success', to: 'users/registrations#success' + get 'users/registrations/delete_form', to: 'users/registrations#delete_form' + delete 'users/registrations', to: 'users/registrations#delete' + get :finish_signup, to: 'users/registrations#finish_signup' + patch :do_finish_signup, to: 'users/registrations#do_finish_signup' +end + +devise_for :organizations, class_name: 'User', + controllers: { + registrations: 'organizations/registrations', + sessions: 'devise/sessions', + }, + skip: [:omniauth_callbacks] + +devise_scope :organization do + get 'organizations/sign_up/success', to: 'organizations/registrations#success' +end diff --git a/config/routes/direct_upload.rb b/config/routes/direct_upload.rb new file mode 100644 index 000000000..dbcf9a9d0 --- /dev/null +++ b/config/routes/direct_upload.rb @@ -0,0 +1,2 @@ +resources :direct_uploads, only: [:create] +delete "direct_uploads/destroy", to: "direct_uploads#destroy", as: :direct_upload_destroy diff --git a/config/routes/document.rb b/config/routes/document.rb new file mode 100644 index 000000000..164153b50 --- /dev/null +++ b/config/routes/document.rb @@ -0,0 +1,7 @@ +resources :documents, only: [:new, :create, :destroy] do + collection do + get :new_nested + delete :destroy_upload + post :upload + end +end diff --git a/config/routes/graphql.rb b/config/routes/graphql.rb new file mode 100644 index 000000000..d41efc54a --- /dev/null +++ b/config/routes/graphql.rb @@ -0,0 +1,3 @@ +get '/graphql', to: 'graphql#query' +post '/graphql', to: 'graphql#query' +mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/graphql' diff --git a/config/routes/legislation.rb b/config/routes/legislation.rb new file mode 100644 index 000000000..a38dfcac5 --- /dev/null +++ b/config/routes/legislation.rb @@ -0,0 +1,37 @@ +namespace :legislation do + resources :processes, only: [:index, :show] do + member do + get :debate + get :draft_publication + get :allegations + get :result_publication + get :proposals + end + + resources :questions, only: [:show] do + resources :answers, only: [:create] + end + + resources :proposals do + member do + post :vote + put :flag + put :unflag + end + collection do + get :map + get :suggest + end + end + + resources :draft_versions, only: [:show] do + get :go_to_version, on: :collection + get :changes + resources :annotations do + get :search, on: :collection + get :comments + post :new_comment + end + end + end +end diff --git a/config/routes/management.rb b/config/routes/management.rb new file mode 100644 index 000000000..e7a746540 --- /dev/null +++ b/config/routes/management.rb @@ -0,0 +1,44 @@ +namespace :management do + root to: "dashboard#index" + + resources :document_verifications, only: [:index, :new, :create] do + post :check, on: :collection + end + + resources :email_verifications, only: [:new, :create] + resources :user_invites, only: [:new, :create] + + resources :users, only: [:new, :create] do + collection do + delete :logout + delete :erase + end + end + + resource :account, controller: "account", only: [:show] + resource :session, only: [:create, :destroy] + get 'sign_in', to: 'sessions#create', as: :sign_in + + resources :proposals, only: [:index, :new, :create, :show] do + post :vote, on: :member + get :print, on: :collection + end + + resources :spending_proposals, only: [:index, :new, :create, :show] do + post :vote, on: :member + get :print, on: :collection + end + + resources :budgets, only: :index do + collection do + get :create_investments + get :support_investments + get :print_investments + end + + resources :investments, only: [:index, :new, :create, :show, :destroy], controller: 'budgets/investments' do + post :vote, on: :member + get :print, on: :collection + end + end +end diff --git a/config/routes/moderation.rb b/config/routes/moderation.rb new file mode 100644 index 000000000..77eb0a216 --- /dev/null +++ b/config/routes/moderation.rb @@ -0,0 +1,25 @@ +namespace :moderation do + root to: "dashboard#index" + + resources :users, only: :index do + member do + put :hide + put :hide_in_moderation_screen + end + end + + resources :debates, only: :index do + put :hide, on: :member + put :moderate, on: :collection + end + + resources :proposals, only: :index do + put :hide, on: :member + put :moderate, on: :collection + end + + resources :comments, only: :index do + put :hide, on: :member + put :moderate, on: :collection + end +end diff --git a/config/routes/notification.rb b/config/routes/notification.rb new file mode 100644 index 000000000..18936ff59 --- /dev/null +++ b/config/routes/notification.rb @@ -0,0 +1,5 @@ +resources :notifications, only: [:index, :show] do + put :mark_all_as_read, on: :collection +end + +resources :proposal_notifications, only: [:new, :create, :show] diff --git a/config/routes/officing.rb b/config/routes/officing.rb new file mode 100644 index 000000000..7adfbbf60 --- /dev/null +++ b/config/routes/officing.rb @@ -0,0 +1,10 @@ +namespace :officing do + resources :polls, only: [:index] do + get :final, on: :collection + resources :results, only: [:new, :create, :index] + end + + resource :residence, controller: "residence", only: [:new, :create] + resources :voters, only: [:new, :create] + root to: "dashboard#index" +end diff --git a/config/routes/poll.rb b/config/routes/poll.rb new file mode 100644 index 000000000..2e9502745 --- /dev/null +++ b/config/routes/poll.rb @@ -0,0 +1,10 @@ +resources :polls, only: [:show, :index] do + member do + get :stats + get :results + end + + resources :questions, controller: 'polls/questions', shallow: true do + post :answer, on: :member + end +end diff --git a/config/routes/proposal.rb b/config/routes/proposal.rb new file mode 100644 index 000000000..d3408ed29 --- /dev/null +++ b/config/routes/proposal.rb @@ -0,0 +1,17 @@ +resources :proposals do + member do + post :vote + post :vote_featured + put :flag + put :unflag + get :retire_form + get :share + patch :retire + end + + collection do + get :map + get :suggest + get :summary + end +end diff --git a/config/routes/related_content.rb b/config/routes/related_content.rb new file mode 100644 index 000000000..e8730c344 --- /dev/null +++ b/config/routes/related_content.rb @@ -0,0 +1,6 @@ +resources :related_contents, only: [:create] do + member do + put :score_positive + put :score_negative + end +end diff --git a/config/routes/tag.rb b/config/routes/tag.rb new file mode 100644 index 000000000..f9c5ab66f --- /dev/null +++ b/config/routes/tag.rb @@ -0,0 +1,5 @@ +resources :tags do + collection do + get :suggest + end +end diff --git a/config/routes/user.rb b/config/routes/user.rb new file mode 100644 index 000000000..56647fd2e --- /dev/null +++ b/config/routes/user.rb @@ -0,0 +1,3 @@ +resources :users, only: [:show] do + resources :direct_messages, only: [:new, :create, :show] +end diff --git a/config/routes/valuation.rb b/config/routes/valuation.rb new file mode 100644 index 000000000..743bc1c72 --- /dev/null +++ b/config/routes/valuation.rb @@ -0,0 +1,13 @@ +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 + end + end +end diff --git a/config/routes/verification.rb b/config/routes/verification.rb new file mode 100644 index 000000000..6af42e005 --- /dev/null +++ b/config/routes/verification.rb @@ -0,0 +1,9 @@ +scope module: :verification do + resource :residence, controller: "residence", only: [:new, :create] + resource :sms, controller: "sms", only: [:new, :create, :edit, :update] + resource :verified_user, controller: "verified_user", only: [:show] + resource :email, controller: "email", only: [:new, :show, :create] + resource :letter, controller: "letter", only: [:new, :create, :show, :edit, :update] +end + +resource :verification, controller: "verification", only: [:show] From baa3c5280f8d67c2b943eb65e555e4d7582abc63 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 9 Jan 2018 23:53:09 +0100 Subject: [PATCH 03/26] Remove TODO's from code, write reminder action on related issue --- db/dev_seeds.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index d2c32cb02..8ed80d5cb 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -535,41 +535,29 @@ end section "Creating polls" do Poll.create(name: "Current Poll", - # TODO: Uncomment when Poll get slugs - # slug: "current-poll", starts_at: 7.days.ago, ends_at: 7.days.from_now, geozone_restricted: false) Poll.create(name: "Current Poll Geozone Restricted", - # TODO: Uncomment when Poll get slugs - # slug: "current-poll-geozone-restricted", starts_at: 5.days.ago, ends_at: 5.days.from_now, geozone_restricted: true, geozones: Geozone.reorder("RANDOM()").limit(3)) Poll.create(name: "Incoming Poll", - # TODO: Uncomment when Poll get slugs - # slug: "incoming-poll", starts_at: 1.month.from_now, ends_at: 2.months.from_now) Poll.create(name: "Recounting Poll", - # TODO: Uncomment when Poll get slugs - # slug: "recounting-poll", starts_at: 15.days.ago, ends_at: 2.days.ago) Poll.create(name: "Expired Poll without Stats & Results", - # TODO: Uncomment when Poll get slugs - # slug: "expired-poll-without-stats-and-results", starts_at: 2.months.ago, ends_at: 1.month.ago) Poll.create(name: "Expired Poll with Stats & Results", - # TODO: Uncomment when Poll get slugs - # slug: "expired-poll-with-stats-and-results", starts_at: 2.months.ago, ends_at: 1.month.ago, results_enabled: true, From 1d6c3034cbb812a4527f7f535a7cc84be55d7de8 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 00:58:30 +0100 Subject: [PATCH 04/26] Add test scenarios to check investment price showing rules --- spec/factories.rb | 6 +++ spec/features/budgets/investments_spec.rb | 58 +++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index 252e40f5c..b4da87586 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -326,6 +326,12 @@ FactoryBot.define do incompatible true end + trait :selected_with_price do + selected + price 1000 + price_explanation 'Because of reasons' + end + trait :unselected do selected false feasibility "feasible" diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index d4c9a0176..e868c140b 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -418,6 +418,64 @@ feature 'Budget Investments' do end end + context "Show Investment's price & cost explanation" do + + let(:investment) { create(:budget_investment, :selected_with_price, heading: heading) } + + context "When investment with price is selected" do + + scenario "Price & explanation is shown when Budget is on published prices phase" do + Budget::PUBLISHED_PRICES_PHASES.each do |phase| + budget.update(phase: phase) + visit budget_investment_path(budget_id: budget.id, id: investment.id) + + expect(page).to have_content(investment.formatted_price) + expect(page).to have_content(investment.price_explanation) + + visit budget_investments_path(budget) + + expect(page).to have_content(investment.formatted_price) + end + end + + scenario "Price & explanation isn't shown when Budget is not on published prices phase" do + (Budget::PHASES - Budget::PUBLISHED_PRICES_PHASES).each do |phase| + budget.update(phase: phase) + visit budget_investment_path(budget_id: budget.id, id: investment.id) + + expect(page).not_to have_content(investment.formatted_price) + expect(page).not_to have_content(investment.price_explanation) + + visit budget_investments_path(budget) + + expect(page).not_to have_content(investment.formatted_price) + end + end + end + + context "When investment with price is unselected" do + + background do + investment.update(selected: false) + end + + scenario "Price & explanation isn't shown for any Budget's phase" do + Budget::PHASES.each do |phase| + budget.update(phase: phase) + visit budget_investment_path(budget_id: budget.id, id: investment.id) + + expect(page).not_to have_content(investment.formatted_price) + expect(page).not_to have_content(investment.price_explanation) + + visit budget_investments_path(budget) + + expect(page).not_to have_content(investment.formatted_price) + end + end + end + + end + scenario 'Can access the community' do Setting['feature.community'] = true From f350b99123d6fc07a507f043b9e2beff6e978ce0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 00:59:19 +0100 Subject: [PATCH 05/26] Remove deprecated investment test scenario for price explanation --- spec/features/budgets/investments_spec.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index e868c140b..69ab52df1 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -535,13 +535,6 @@ feature 'Budget Investments' do expect(page).not_to have_content(investment.price_explanation) end - scenario "Budget in balloting phase" do - budget.update(phase: "balloting") - visit budget_investment_path(budget_id: budget.id, id: investment.id) - - expect(page).to have_content("Price explanation") - expect(page).to have_content(investment.price_explanation) - end end scenario "Show (unfeasible budget investment)" do From cb1151f1d619722f673fb4dfdda96bb78bc17342 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:02:07 +0100 Subject: [PATCH 06/26] Increase Budget model spec for new publishing_prices phase --- spec/models/budget_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb index b86db7e6e..af42b4bc0 100644 --- a/spec/models/budget_spec.rb +++ b/spec/models/budget_spec.rb @@ -55,6 +55,9 @@ describe Budget do budget.phase = "valuating" expect(budget).to be_valuating + budget.phase = "publishing_prices" + expect(budget).to be_publishing_prices + budget.phase = "balloting" expect(budget).to be_balloting @@ -81,6 +84,9 @@ describe Budget do budget.phase = "valuating" expect(budget).to be_on_hold + budget.phase = "publishing_prices" + expect(budget).to be_on_hold + budget.phase = "balloting" expect(budget).not_to be_on_hold @@ -107,6 +113,9 @@ describe Budget do budget.phase = "valuating" expect(budget).not_to be_balloting_or_later + budget.phase = "publishing_prices" + expect(budget).not_to be_balloting_or_later + budget.phase = "balloting" expect(budget).to be_balloting_or_later @@ -142,6 +151,8 @@ describe Budget do expect(budget.investments_orders).to eq(['random']) end it "is random and price when ballotting and reviewing ballots" do + budget.phase = 'publishing_prices' + expect(budget.investments_orders).to eq(['random', 'price']) budget.phase = 'balloting' expect(budget.investments_orders).to eq(['random', 'price']) budget.phase = 'reviewing_ballots' From d8ceff1a538937f45e0c87cf93702b741fd676a5 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:09:13 +0100 Subject: [PATCH 07/26] Refactor Budget's on hold phases to constant, plus alignments --- app/models/budget.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/budget.rb b/app/models/budget.rb index ce8bc4dfa..509352372 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -5,6 +5,8 @@ class Budget < ActiveRecord::Base PHASES = %w(drafting accepting reviewing selecting valuating balloting reviewing_ballots finished).freeze + ON_HOLD_PHASES = %w(reviewing valuating reviewing_ballots).freeze + CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze validates :name, presence: true, uniqueness: true @@ -19,17 +21,17 @@ class Budget < ActiveRecord::Base before_validation :sanitize_descriptions - scope :on_hold, -> { where(phase: %w(reviewing valuating reviewing_ballots")) } - scope :drafting, -> { where(phase: "drafting") } + scope :on_hold, -> { where(phase: ON_HOLD_PHASES) } + scope :drafting, -> { where(phase: "drafting") } scope :accepting, -> { where(phase: "accepting") } scope :reviewing, -> { where(phase: "reviewing") } scope :selecting, -> { where(phase: "selecting") } scope :valuating, -> { where(phase: "valuating") } scope :balloting, -> { where(phase: "balloting") } scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") } - scope :finished, -> { where(phase: "finished") } + scope :finished, -> { where(phase: "finished") } - scope :current, -> { where.not(phase: "finished") } + scope :current, -> { where.not(phase: "finished") } def description send("description_#{phase}").try(:html_safe) @@ -84,7 +86,7 @@ class Budget < ActiveRecord::Base end def on_hold? - reviewing? || valuating? || reviewing_ballots? + ON_HOLD_PHASES.include?(phase) end def current? From 922318b978b28ea4c7bfa9c814579f4b6d030ab4 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:10:57 +0100 Subject: [PATCH 08/26] Add publishing prices phase to budget model, plus translation texts --- app/models/budget.rb | 13 +++++++++---- config/locales/en/budgets.yml | 1 + config/locales/es/budgets.yml | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/budget.rb b/app/models/budget.rb index 509352372..7fa03db9a 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -3,9 +3,9 @@ class Budget < ActiveRecord::Base include Measurable include Sluggable - PHASES = %w(drafting accepting reviewing selecting valuating balloting - reviewing_ballots finished).freeze - ON_HOLD_PHASES = %w(reviewing valuating reviewing_ballots).freeze + PHASES = %w(drafting accepting reviewing selecting valuating publishing_prices + balloting reviewing_ballots finished).freeze + ON_HOLD_PHASES = %w(reviewing valuating publishing_prices reviewing_ballots).freeze CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze @@ -27,6 +27,7 @@ class Budget < ActiveRecord::Base scope :reviewing, -> { where(phase: "reviewing") } scope :selecting, -> { where(phase: "selecting") } scope :valuating, -> { where(phase: "valuating") } + scope :publishing_prices, -> { where(phase: "publishing_prices") } scope :balloting, -> { where(phase: "balloting") } scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") } scope :finished, -> { where(phase: "finished") } @@ -65,6 +66,10 @@ class Budget < ActiveRecord::Base phase == "valuating" end + def publishing_prices? + phase == "publishing_prices" + end + def balloting? phase == "balloting" end @@ -120,7 +125,7 @@ class Budget < ActiveRecord::Base case phase when 'accepting', 'reviewing' %w{random} - when 'balloting', 'reviewing_ballots' + when 'publishing_prices', 'balloting', 'reviewing_ballots' %w{random price} else %w{random confidence_score} diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 5aba444ab..1209d9206 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -34,6 +34,7 @@ en: reviewing: Reviewing projects selecting: Selecting projects valuating: Valuating projects + publishing_prices: Publishing projects prices balloting: Balloting projects reviewing_ballots: Reviewing Ballots finished: Finished budget diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index b85f0ec47..bbf668f21 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -34,6 +34,7 @@ es: reviewing: Revisión interna de proyectos selecting: Fase de apoyos valuating: Evaluación de proyectos + publishing_prices: Publicación de precios balloting: Votación final reviewing_ballots: Votación finalizada finished: Resultados From 6772f94c148a28cf41fe65b1deab812c6b11a2dd Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:11:13 +0100 Subject: [PATCH 09/26] Add description publishing prices column to budgets table --- .../20180109175851_add_publishing_prices_phase_to_budget.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180109175851_add_publishing_prices_phase_to_budget.rb diff --git a/db/migrate/20180109175851_add_publishing_prices_phase_to_budget.rb b/db/migrate/20180109175851_add_publishing_prices_phase_to_budget.rb new file mode 100644 index 000000000..e6181f6e1 --- /dev/null +++ b/db/migrate/20180109175851_add_publishing_prices_phase_to_budget.rb @@ -0,0 +1,5 @@ +class AddPublishingPricesPhaseToBudget < ActiveRecord::Migration + def change + add_column :budgets, :description_publishing_prices, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index d599658c1..d2c5d3450 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180108182839) do +ActiveRecord::Schema.define(version: 20180109175851) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -202,6 +202,7 @@ ActiveRecord::Schema.define(version: 20180108182839) do t.text "description_finished" t.string "slug" t.text "description_drafting" + t.text "description_publishing_prices" end create_table "campaigns", force: :cascade do |t| From 3bc683edce61eb00ad0a1a216be8132050f5f68e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:12:11 +0100 Subject: [PATCH 10/26] Increase budget factory with publishing_price trait & description value --- spec/factories.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index b4da87586..7372b5ba9 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -228,6 +228,7 @@ FactoryBot.define do description_reviewing "This budget is reviewing" description_selecting "This budget is selecting" description_valuating "This budget is valuating" + description_publishing_prices "This budget is publishing prices" description_balloting "This budget is balloting" description_reviewing_ballots "This budget is reviewing ballots" description_finished "This budget is finished" @@ -252,6 +253,10 @@ FactoryBot.define do phase 'valuating' end + trait :publishing_prices do + phase 'publishing_prices' + end + trait :balloting do phase 'balloting' end @@ -313,7 +318,6 @@ FactoryBot.define do selected true feasibility "feasible" valuation_finished true - end trait :winner do From f3a7de55ea62135ff060e4f3740c3be5211b3b66 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:13:34 +0100 Subject: [PATCH 11/26] Rename should_show_price_info? to should_show_price_explanation? at Budget::Investment & usage --- app/models/budget/investment.rb | 2 +- app/views/budgets/investments/_investment_show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4e2e5d0b0..b2cc8cba5 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -245,7 +245,7 @@ class Budget (budget.reviewing_ballots? || budget.finished?) end - def should_show_price_info? + def should_show_price_explanation? feasible? && price_explanation.present? && (budget.balloting? || budget.reviewing_ballots? || budget.finished?) diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 946952bd9..3b0078bf8 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -71,7 +71,7 @@

<%= investment.unfeasibility_explanation %>

<% end %> - <% if investment.should_show_price_info? %> + <% if investment.should_show_price_explanation? %>

<%= t('budgets.investments.show.price_explanation') %>

<%= investment.price_explanation %>

<% end %> From 3563b87399da0075c8a067d173bda3bd442ac7ed Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:14:23 +0100 Subject: [PATCH 12/26] Increase Budget Investment model spec for should_show_price & explantion methods --- spec/models/budget/investment_spec.rb | 72 ++++++++++++++++++++------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index a04134ce4..63065cfbe 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -193,37 +193,73 @@ describe Budget::Investment do end end - describe "#should_show_price_info?" do - it "returns true for feasibles if phase is balloting or later and price_explanation is present" do - ["balloting", "reviewing_ballots", "finished"].each do |phase| - budget = create(:budget, phase: phase) - investment = create(:budget_investment, :feasible, budget: budget, price_explanation: "price explanation") + describe "#should_show_price?" do + let(:budget) { create(:budget, :publishing_prices) } + let(:investment) do + create(:budget_investment, :selected, budget: budget) + end - expect(investment.should_show_price_info?).to eq(true) + it "returns true for selected investments which budget's phase is publishing_prices or later" do + Budget::PUBLISHED_PRICES_PHASES.each do |phase| + budget.update(phase: phase) + + expect(investment.should_show_price?).to eq(true) end end it "returns false in any other phase" do - (Budget::PHASES - ["balloting", "reviewing_ballots", "finished"]).each do |phase| - budget = create(:budget, phase: phase) - investment = create(:budget_investment, :feasible, budget: budget, price_explanation: "price explanation") + (Budget::PHASES - Budget::PUBLISHED_PRICES_PHASES).each do |phase| + budget.update(phase: phase) - expect(investment.should_show_price_info?).to eq(false) + expect(investment.should_show_price?).to eq(false) end end - it "returns false if investment is unfeasible" do - budget = create(:budget, phase: "balloting") - investment = create(:budget_investment, :unfeasible, budget: budget, price_explanation: "price explanation") + it "returns false if investment is not selected" do + investment.selected = false - expect(investment.should_show_price_info?).to eq(false) + expect(investment.should_show_price?).to eq(false) end - it "returns false if price_explanation is blank" do - budget = create(:budget, phase: "balloting") - investment = create(:budget_investment, :unfeasible, budget: budget, price_explanation: "") + it "returns false if price is not present" do + investment.price = nil - expect(investment.should_show_price_info?).to eq(false) + expect(investment.should_show_price?).to eq(false) + end + end + + describe "#should_show_price_explanation?" do + let(:budget) { create(:budget, :publishing_prices) } + let(:investment) do + create(:budget_investment, :selected, budget: budget, price_explanation: "because of reasons") + end + + it "returns true for selected with price_explanation & budget in publishing_prices or later" do + Budget::PUBLISHED_PRICES_PHASES.each do |phase| + budget.update(phase: phase) + + expect(investment.should_show_price_explanation?).to eq(true) + end + end + + it "returns false in any other phase" do + (Budget::PHASES - Budget::PUBLISHED_PRICES_PHASES).each do |phase| + budget.update(phase: phase) + + expect(investment.should_show_price_explanation?).to eq(false) + end + end + + it "returns false if investment is not selected" do + investment.selected = false + + expect(investment.should_show_price_explanation?).to eq(false) + end + + it "returns false if price_explanation is not present" do + investment.price_explanation = "" + + expect(investment.should_show_price_explanation?).to eq(false) end end From 21d6ce57c5cd0c3a8751b6abfdde93dfc43bd06e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:15:07 +0100 Subject: [PATCH 13/26] Add published_prices? helper method and phases constant at Budget model --- app/models/budget.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/budget.rb b/app/models/budget.rb index 7fa03db9a..6111df301 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -6,6 +6,7 @@ class Budget < ActiveRecord::Base PHASES = %w(drafting accepting reviewing selecting valuating publishing_prices balloting reviewing_ballots finished).freeze ON_HOLD_PHASES = %w(reviewing valuating publishing_prices reviewing_ballots).freeze + PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze @@ -82,6 +83,10 @@ class Budget < ActiveRecord::Base phase == "finished" end + def published_prices? + PUBLISHED_PRICES_PHASES.include?(phase) + end + def balloting_process? balloting? || reviewing_ballots? end From 334091710cf737d0c003d044e95e32040ae34246 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 01:16:04 +0100 Subject: [PATCH 14/26] Refactor price & explanation showing logic at Investment model --- app/models/budget/investment.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index b2cc8cba5..579a39525 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -240,15 +240,11 @@ class Budget end def should_show_price? - feasible? && - selected? && - (budget.reviewing_ballots? || budget.finished?) + selected? && price.present? && budget.published_prices? end def should_show_price_explanation? - feasible? && - price_explanation.present? && - (budget.balloting? || budget.reviewing_ballots? || budget.finished?) + should_show_price? && price_explanation.present? end def formatted_price From eda673a85d115c6834cbd475987aa33039af0529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 10 Jan 2018 11:57:13 +0100 Subject: [PATCH 15/26] Restored missing code --- .../budget_investments/_investments.html.erb | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 75bde7002..594ef5cf0 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -58,7 +58,25 @@ <%= investment.valuation_finished? ? t('shared.yes'): t('shared.no') %>
<% if params[:filter] == 'selected' %> "); -<% end %> +$("#<%= dom_id(@budget_group) %>").html('<%= j render("admin/budgets/group", group: @budget_group, headings: @budget_group.headings) %>'); diff --git a/app/views/admin/budgets/_heading.html.erb b/app/views/admin/budgets/_heading.html.erb index 7ffeca7a0..bc9d59c5f 100644 --- a/app/views/admin/budgets/_heading.html.erb +++ b/app/views/admin/budgets/_heading.html.erb @@ -12,16 +12,16 @@ <%= link_to t("admin.actions.edit"), edit_admin_budget_budget_group_budget_heading_path(budget_id: group.budget.id, budget_group_id: group.id, id: heading.id), class: "button hollow", - remote: true%> + remote: true %> <%= link_to t("admin.budget_investments.index.title"), admin_budget_budget_investments_path(budget_id: group.budget.id, heading_id: heading.id), - class: "button hollow"%> + class: "button hollow" %> <% if heading.can_be_deleted? %> <%= link_to t('admin.administrators.administrator.delete'), #admin_budget_budget_group_budget_headings_path(group.budget.id, group.id), [:admin, group.budget, group, heading], method: :delete, - class: "button hollow alert"%> + class: "button hollow alert" %> <% end %> - \ No newline at end of file + diff --git a/app/views/admin/budgets/_heading_form.html.erb b/app/views/admin/budgets/_heading_form.html.erb index 43a4797a8..8dd2d563a 100644 --- a/app/views/admin/budgets/_heading_form.html.erb +++ b/app/views/admin/budgets/_heading_form.html.erb @@ -1,4 +1,5 @@ <%= form_for [:admin, budget, group, heading], remote: true do |f| %> + <%= render 'shared/errors', resource: heading %> <%= f.text_field :name, label: false, @@ -25,6 +26,4 @@ <%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %> - -
-<% end %> \ No newline at end of file +<% end %> diff --git a/spec/models/budget/heading_spec.rb b/spec/models/budget/heading_spec.rb index 76ac82692..a556cf2ca 100644 --- a/spec/models/budget/heading_spec.rb +++ b/spec/models/budget/heading_spec.rb @@ -26,7 +26,7 @@ describe Budget::Heading do end describe "heading" do - it "can be deleted if not budget's investments associated" do + it "can be deleted if no budget's investments associated" do heading1 = create(:budget_heading, group: group, name: 'name') heading2 = create(:budget_heading, group: group, name: 'name 2') @@ -34,7 +34,6 @@ describe Budget::Heading do expect(heading1.can_be_deleted?).to eq false expect(heading2.can_be_deleted?).to eq true - end end From 760b7ca4c85cb3ff0c2df9ff8d65440fd482a7f7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 13:37:03 +0100 Subject: [PATCH 20/26] Fix indentations and lines lenght --- .../budget_investments/_investments.html.erb | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index c23f8a45c..0299b6149 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -30,14 +30,19 @@ <%= investment.id %> <% if params[:filter] == 'selected' %> From 88741b9179bca6c76f2fee7c6ba1423523a7f79e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 22:09:06 +0100 Subject: [PATCH 21/26] Improve investment links at budget list with target blank --- app/views/admin/budget_investments/_investments.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 0299b6149..741ccd9fd 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -33,7 +33,8 @@ <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, - params: Budget::Investment.filter_params(params)) %> + params: Budget::Investment.filter_params(params)), + target: "_blank" %>
+ <%= group.name %> <%= link_to t("admin.budgets.form.add_heading"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#group-#{group.id}-new-heading-form" } %>
+
<%= t("admin.budgets.form.no_heading") %>
@@ -22,6 +22,7 @@
<%= t("admin.budgets.form.table_heading") %> <%= t("admin.budgets.form.table_amount") %> <%= t("admin.budgets.form.table_population") %><%= t("admin.actions.actions") %>
- <%= heading.name %> - - <%= heading.price %> - - <%= heading.population %> -
+ <%= heading.name %> + + <%= heading.price %> + + <%= heading.population %> + + <%= link_to t("admin.actions.edit"), + edit_admin_budget_budget_group_budget_heading_path(budget_id: group.budget.id, budget_group_id: group.id, id: heading.id), + class: "button hollow", + remote: true%> + <%= link_to t("admin.budget_investments.index.title"), + admin_budget_budget_investments_path(budget_id: group.budget.id, heading_id: heading.id), + class: "button hollow"%> + <% if heading.can_be_deleted? %> + <%= link_to t('admin.administrators.administrator.delete'), + #admin_budget_budget_group_budget_headings_path(group.budget.id, group.id), + [:admin, group.budget, group, heading], + method: :delete, + class: "button hollow alert"%> + <% end %> +
- <%= investment_selected_link(investment) %> + <% 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], + page: params[:page]), + method: :patch, + remote: true, + class: "button small expanded" %> + <% elsif investment.feasible? && investment.valuation_finished? %> + <%= link_to_unless investment.budget.finished?, t("admin.budget_investments.index.select"), + toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small hollow expanded" %> + <% end %> From a06abf7650e88be59c2df0203fdd312555b10230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 10 Jan 2018 11:57:23 +0100 Subject: [PATCH 16/26] Removed unnecessary code --- app/helpers/budgets_helper.rb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index a14b86538..d2d6e1f5d 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -6,26 +6,6 @@ module BudgetsHelper csv_params end - def investment_selected_link(investment) - options = investment_selected_link_options(investment) - path = toggle_selection_admin_budget_budget_investment_path(@budget, - investment, filter: params[:filter], page: params[:page]) - link_options = {method: :patch, remote: true, class: options[:link_class]} - link_to options[:text], path, link_options - end - - def investment_selected_link_options(investment) - if investment.selected? - {link_class: "button small expanded", - text: t("admin.budget_investments.index.selected") } - elsif investment.feasible? && investment.valuation_finished? - {link_class: "button small hollow expanded", - text: t("admin.budget_investments.index.select")} - else - {} - end - end - def budget_phases_select_options Budget::PHASES.map { |ph| [ t("budgets.phase.#{ph}"), ph ] } end From bc363289ad84736f01bd4b48b10845cd6b87865c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 10 Jan 2018 12:19:48 +0100 Subject: [PATCH 17/26] Added translations to link text --- app/views/admin/budget_investments/_investments.html.erb | 5 ++++- config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 594ef5cf0..c23f8a45c 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -1,5 +1,8 @@
- <%= link_to 'download current selecction',admin_budget_budget_investments_path(csv_params), class: 'advanced-search small' %> + <%= link_to t("admin.budget_investments.index.download_current_selection"), + admin_budget_budget_investments_path(csv_params), + class: 'advanced-search small' %> +

<%= page_entries_info @investments %>

diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0d83e824b..0045f0991 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -138,6 +138,7 @@ en: undecided: "Undecided" selected: "Selected" select: "Select" + download_current_selection: "Download current selection" table_id: "ID" table_title: "Title" table_supports: "Supports" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 456b78ab3..ff886a02d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -139,6 +139,7 @@ es: undecided: "Sin decidir" selected: "Seleccionada" select: "Seleccionar" + download_current_selection: "Descargar selección actual" table_id: "ID" table_title: "Título" table_supports: "Apoyos" From 02f7e423fea3198f3f0bad7b95ea0622599f7720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 10 Jan 2018 13:03:52 +0100 Subject: [PATCH 18/26] Improved tests --- spec/features/admin/budget_investments_spec.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index c3fc69473..aab577f4a 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -639,7 +639,10 @@ feature 'Admin budget investments' do admin = create(:administrator, user: create(:user, username: 'Gema')) investment.update(administrator_id: admin.id) - visit admin_budget_budget_investments_path(@budget, format: :csv) + visit admin_budget_budget_investments_path(@budget) + within('#filter-subnav') { click_link 'All' } + + click_link "Download current selection" header = page.response_headers['Content-Disposition'] expect(header).to match(/^attachment/) @@ -666,8 +669,11 @@ feature 'Admin budget investments' do title: 'compatible') investment2 = create(:budget_investment, :finished, budget: @budget, title: 'finished') - visit admin_budget_budget_investments_path(@budget, format: :csv, - filter: :valuation_finished) + + visit admin_budget_budget_investments_path(@budget) + within('#filter-subnav') { click_link 'Valuation finished' } + + click_link "Download current selection" header = page.response_headers['Content-Disposition'] header.should match(/^attachment/) From f0724ce13a97d03c4114430eae1db2e691740dc7 Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 10 Jan 2018 13:13:05 +0100 Subject: [PATCH 19/26] Changes suggested in the PR made --- .../admin/budget_headings_controller.rb | 22 +++++++++---------- app/views/admin/budget_headings/update.js.erb | 6 +---- app/views/admin/budgets/_heading.html.erb | 8 +++---- .../admin/budgets/_heading_form.html.erb | 5 ++--- spec/models/budget/heading_spec.rb | 3 +-- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/app/controllers/admin/budget_headings_controller.rb b/app/controllers/admin/budget_headings_controller.rb index ee1878edf..902f256b5 100644 --- a/app/controllers/admin/budget_headings_controller.rb +++ b/app/controllers/admin/budget_headings_controller.rb @@ -3,30 +3,30 @@ class Admin::BudgetHeadingsController < Admin::BaseController feature_flag :budgets def create - @budget = Budget.find params[:budget_id] - @budget_group = @budget.groups.find params[:budget_group_id] + @budget = Budget.find(params[:budget_id]) + @budget_group = @budget.groups.find(params[:budget_group_id]) @budget_group.headings.create(budget_heading_params) @headings = @budget_group.headings end def edit - @budget = Budget.find params[:budget_id] - @budget_group = @budget.groups.find params[:budget_group_id] - @heading = Budget::Heading.find params[:id] + @budget = Budget.find(params[:budget_id]) + @budget_group = @budget.groups.find(params[:budget_group_id]) + @heading = Budget::Heading.find(params[:id]) end def update - @budget = Budget.find params[:budget_id] - @budget_group = @budget.groups.find params[:budget_group_id] - @heading = Budget::Heading.find params[:id] + @budget = Budget.find(params[:budget_id]) + @budget_group = @budget.groups.find(params[:budget_group_id]) + @heading = Budget::Heading.find(params[:id]) @heading.assign_attributes(budget_heading_params) - @errors = @heading.errors.full_messages unless @heading.save + render :edit unless @heading.save end def destroy - @heading = Budget::Heading.find params[:id] + @heading = Budget::Heading.find(params[:id]) @heading.destroy - @budget = Budget.find params[:budget_id] + @budget = Budget.find(params[:budget_id]) redirect_to admin_budget_path(@budget) end diff --git a/app/views/admin/budget_headings/update.js.erb b/app/views/admin/budget_headings/update.js.erb index d46e35386..6466959cd 100644 --- a/app/views/admin/budget_headings/update.js.erb +++ b/app/views/admin/budget_headings/update.js.erb @@ -1,5 +1 @@ -<% if @errors %> - $("#heading-<%=@heading.id%> div#error_explanation").replaceWith("<%= j render("admin/budget_headings/errors", errors: @errors) %>"); -<% else %> - $("#heading-<%=@heading.id%>").html("
<%= j render("admin/budgets/heading", group: @budget_group, budget: @budget, heading: @heading) %>
- <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %> + <%= link_to investment.title, + admin_budget_budget_investment_path(budget_id: @budget.id, + id: investment.id, + params: Budget::Investment.filter_params(params)) %> <%= investment.total_votes %> <% if investment.administrator.present? %> - <%= investment.administrator.name %> + + <%= investment.administrator.name %> + <% else %> <%= t("admin.budget_investments.index.no_admin_assigned") %> <% end %> @@ -62,23 +67,25 @@ <% 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], - page: params[:page]), - method: :patch, - remote: true, - class: "button small expanded" %> + <%= link_to_unless investment.budget.finished?, + t("admin.budget_investments.index.selected"), + toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small expanded" %> <% elsif investment.feasible? && investment.valuation_finished? %> - <%= link_to_unless investment.budget.finished?, t("admin.budget_investments.index.select"), - toggle_selection_admin_budget_budget_investment_path(@budget, - investment, - filter: params[:filter], - page: params[:page]), - method: :patch, - remote: true, - class: "button small hollow expanded" %> + <%= link_to_unless investment.budget.finished?, + t("admin.budget_investments.index.select"), + toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small hollow expanded" %> <% end %> <%= investment.total_votes %> From db051beabc2ecbbee39003303ea5d3efe88073c4 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 22:43:52 +0100 Subject: [PATCH 22/26] Fix to_not to not_to on spec --- spec/features/admin/budget_investments_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index aab577f4a..ae3cfed70 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -47,7 +47,7 @@ feature 'Admin budget investments' do expect(page).to have_content(budget_investment.heading.name) expect(page).to have_content(budget_investment.id) expect(page).to have_content(budget_investment.total_votes) - expect(page).to_not have_link("Selected") + expect(page).not_to have_link("Selected") end end @@ -339,9 +339,9 @@ feature 'Admin budget investments' do click_link budget_investment.title - expect(page).to_not have_link "Edit" - expect(page).to_not have_link "Edit classification" - expect(page).to_not have_link "Edit dossier" + expect(page).not_to have_link "Edit" + expect(page).not_to have_link "Edit classification" + expect(page).not_to have_link "Edit dossier" expect(page).to have_link "Create new milestone" end end @@ -680,7 +680,7 @@ feature 'Admin budget investments' do header.should match(/filename="budget_investments.csv"$/) expect(page).to have_content investment2.title - expect(page).to_not have_content investment1.title + expect(page).not_to have_content investment1.title end end From 30261153823ae43409d5027346dc778f81b24b3b Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 22:44:11 +0100 Subject: [PATCH 23/26] Remove redundant curly braces around a hash parameter --- app/controllers/admin/budget_investments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 0208fccd8..dbaa91f99 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -16,7 +16,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController respond_to do |format| format.html format.csv do - send_data Budget::Investment.to_csv(@investments, {headers: true}), + send_data Budget::Investment.to_csv(@investments, headers: true), filename: 'budget_investments.csv' end end From 1fee0eb2aa2d20a8c366f35641b8194827394e46 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 10 Jan 2018 23:48:13 +0100 Subject: [PATCH 24/26] Update unreleased section of changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8701852ce..5298cb47e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Added Drafting phase to Budgets https://github.com/consul/consul/pull/2285 +- Added 'Publish investments price' phase to Budgets https://github.com/consul/consul/pull/2296 - Allow admins to destroy budgets without investments https://github.com/consul/consul/pull/2283 - Added rubocop-rspec gem, enabled cops one by one fixing offenses. - Added CSV download link to budget_investments https://github.com/consul/consul/pull/2147 From 55aa5bfdfb651fe67dded1451851a3a87c5c0189 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 11 Jan 2018 12:24:07 +0100 Subject: [PATCH 25/26] Update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5298cb47e..f6a819e4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Redirect admin to budget lists after edit https://github.com/consul/consul/pull/2284 - Improve budget investment form https://github.com/consul/consul/pull/2280 - Prevent edition of investments if budget is in the final phase https://github.com/consul/consul/pull/2223 +- Split 'routes.rb' file into multiple small files https://github.com/consul/consul/pull/1908 ### Deprecated From c76b099971c52f0bcbcdca9ef78473002fa69b8c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 11 Jan 2018 14:03:17 +0100 Subject: [PATCH 26/26] Update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6a819e4f..c6fe7ef09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added rubocop-rspec gem, enabled cops one by one fixing offenses. - Added CSV download link to budget_investments https://github.com/consul/consul/pull/2147 - Added Capistrano task to automate maintenance mode https://github.com/consul/consul/pull/1932 +- Added actions to edit and delete a budget's headings https://github.com/consul/consul/pull/1917 ### Changed - Updated multiple minor & patch gem versions thanks to [Depfu](https://depfu.com)