From bc218531b051dd35e59655264d6cc25722343f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 13 Sep 2017 12:31:42 +0200 Subject: [PATCH 01/46] Proposals phase migration --- ...3101029_add_proposals_phase_to_legislation_processes.rb | 7 +++++++ db/schema.rb | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170913101029_add_proposals_phase_to_legislation_processes.rb diff --git a/db/migrate/20170913101029_add_proposals_phase_to_legislation_processes.rb b/db/migrate/20170913101029_add_proposals_phase_to_legislation_processes.rb new file mode 100644 index 000000000..b3ecfe3f1 --- /dev/null +++ b/db/migrate/20170913101029_add_proposals_phase_to_legislation_processes.rb @@ -0,0 +1,7 @@ +class AddProposalsPhaseToLegislationProcesses < ActiveRecord::Migration + def change + add_column :legislation_processes, :proposals_phase_start_date, :date + add_column :legislation_processes, :proposals_phase_end_date, :date + add_column :legislation_processes, :proposals_phase_enabled, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index ba856107c..578a0bc25 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: 20170908175149) do +ActiveRecord::Schema.define(version: 20170913101029) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -470,6 +470,9 @@ ActiveRecord::Schema.define(version: 20170908175149) do t.boolean "draft_publication_enabled", default: false t.boolean "result_publication_enabled", default: false t.boolean "published", default: true + t.date "proposals_phase_start_date" + t.date "proposals_phase_end_date" + t.boolean "proposals_phase_enabled" end add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree From dc9fe973f49f7c4a9c7d57b06190a3bea4a7c5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 13 Sep 2017 12:33:16 +0200 Subject: [PATCH 02/46] Added proposals phase attributes to legislation processes form Also added them to the list of accepted params and completed translations. --- .../admin/legislation/processes_controller.rb | 3 ++ app/models/legislation/process.rb | 6 +++- .../legislation/processes/_form.html.erb | 33 +++++++++++++++++++ config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 5d8d828cd..da27f9955 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -47,9 +47,12 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :draft_publication_date, :allegations_start_date, :allegations_end_date, + :proposals_phase_start_date, + :proposals_phase_end_date, :result_publication_date, :debate_phase_enabled, :allegations_phase_enabled, + :proposals_phase_enabled, :draft_publication_enabled, :result_publication_enabled, :published diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index b6043df57..0f596b8f8 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -2,7 +2,7 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase draft_publication result_publication).freeze + PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase proposals_phase draft_publication result_publication).freeze has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id', dependent: :destroy @@ -33,6 +33,10 @@ class Legislation::Process < ActiveRecord::Base Legislation::Process::Phase.new(allegations_start_date, allegations_end_date, allegations_phase_enabled) end + def proposals_phase + Legislation::Process::Phase.new(proposals_phase_start_date, proposals_phase_end_date, proposals_phase_enabled) + end + def draft_publication Legislation::Process::Publication.new(draft_publication_date, draft_publication_enabled) end diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 205d97361..ed034544b 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -114,6 +114,39 @@ +
+
+ +
+
+ <%= t('admin.legislation.processes.form.start') %> +
+
+ <%= f.text_field :proposals_phase_start_date, + label: false, + value: format_date_for_calendar_form(@process.proposals_phase_start_date), + class: "js-calendar-full", + id: "proposals_phase_start_date" %> +
+
+ <%= t('admin.legislation.processes.form.end') %> +
+
+ <%= f.text_field :proposals_phase_end_date, + label: false, + value: format_date_for_calendar_form(@process.proposals_phase_end_date), + class: "js-calendar-full", + id: "proposals_phase_end_date" %> +
+
+ <%= f.check_box :proposals_phase_enabled, checked: @process.proposals_phase.enabled?, label: t('admin.legislation.processes.form.enabled') %> +
+ +
+
+
+
+
<%= f.label :draft_publication_date %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 3f1b12189..3793b75a8 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -258,6 +258,7 @@ en: process: Process debate_phase: Debate phase allegations_phase: Allegations phase + proposals_phase: Proposals phase start: Start end: End use_markdown: Use Markdown to format the text diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 9872baa0d..27262845d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -258,6 +258,7 @@ es: process: Proceso debate_phase: Fase previa allegations_phase: Fase de alegaciones + proposals_phase: Fase de propuestas start: Inicio end: Fin use_markdown: Usa Markdown para formatear el texto From f521a9023b39ec08fa2c5cdffd997be10a98fb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 13 Sep 2017 15:43:36 +0200 Subject: [PATCH 03/46] Added Proposal model to Legislation This new Legislation::Proposal model inherits from the original Proposal, as it will behave in a very similar way. --- app/controllers/admin/legislation/proposals_controller.rb | 7 +++++++ app/models/legislation/process.rb | 1 + app/models/legislation/proposal.rb | 8 ++++++++ config/routes.rb | 5 +++-- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/legislation/proposals_controller.rb create mode 100644 app/models/legislation/proposal.rb diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb new file mode 100644 index 000000000..7f4441bce --- /dev/null +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -0,0 +1,7 @@ +class Admin::Legislation::ProposalsController < Admin::Legislation::BaseController + load_and_authorize_resource :process, class: "Legislation::Process" + load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process + + def index + end +end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 0f596b8f8..6a37aeef2 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -9,6 +9,7 @@ class Legislation::Process < ActiveRecord::Base has_one :final_draft_version, -> { where final_version: true, status: 'published' }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id', dependent: :destroy + has_many :proposals, -> { order(:id) }, class_name: 'Legislation::Proposal', foreign_key: 'legislation_process_id', dependent: :destroy validates :title, presence: true validates :start_date, presence: true diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb new file mode 100644 index 000000000..2c187d302 --- /dev/null +++ b/app/models/legislation/proposal.rb @@ -0,0 +1,8 @@ +class Legislation::Proposal < Proposal + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + + belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' + + scope :sorted, -> { order('id ASC') } +end diff --git a/config/routes.rb b/config/routes.rb index a41e8d429..f0276f290 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -287,11 +287,11 @@ Rails.application.routes.draw do end resources :booths do - get :available, on: :collection + get :available, on: :collection resources :shifts do get :search_officers, on: :collection - end + end end resources :questions @@ -313,6 +313,7 @@ Rails.application.routes.draw do namespace :legislation do resources :processes do resources :questions + resources :proposals resources :draft_versions end end From c811fd46f07c678a8077e031f291d1bd89b24abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 13 Sep 2017 15:48:07 +0200 Subject: [PATCH 04/46] Proposals description migration and form - Added to legislation processes a new attribute called `proposals_description`. - Then created new views to show a form for the `@process` to edit this attribute **from in the proposals section**. - Completed translations for new views. --- .../admin/legislation/processes_controller.rb | 5 +-- .../legislation/processes/_subnav.html.erb | 5 ++- .../legislation/proposals/_form.html.erb | 36 +++++++++++++++++++ .../legislation/proposals/index.html.erb | 16 +++++++++ config/locales/en/admin.yml | 9 +++++ config/locales/es/admin.yml | 9 +++++ ...ls_description_to_legislation_processes.rb | 5 +++ db/schema.rb | 3 +- 8 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 app/views/admin/legislation/proposals/_form.html.erb create mode 100644 app/views/admin/legislation/proposals/index.html.erb create mode 100644 db/migrate/20170913130803_add_proposals_description_to_legislation_processes.rb diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index da27f9955..f316d9b65 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -20,7 +20,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def update if @process.update(process_params) link = legislation_process_path(@process).html_safe - redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.update.notice', link: link) + redirect_to :back, notice: t('admin.legislation.processes.update.notice', link: link) else flash.now[:error] = t('admin.legislation.processes.update.error') render :edit @@ -55,7 +55,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :proposals_phase_enabled, :draft_publication_enabled, :result_publication_enabled, - :published + :published, + :proposals_description ) end end diff --git a/app/views/admin/legislation/processes/_subnav.html.erb b/app/views/admin/legislation/processes/_subnav.html.erb index 97640c4f4..56b668641 100644 --- a/app/views/admin/legislation/processes/_subnav.html.erb +++ b/app/views/admin/legislation/processes/_subnav.html.erb @@ -2,9 +2,12 @@
  • > <%= link_to t("admin.legislation.processes.subnav.info"), edit_admin_legislation_process_path(process) %>
  • -
  • > +
  • > <%= link_to t("admin.legislation.processes.subnav.questions"), admin_legislation_process_questions_path(process) %>
  • +
  • > + <%= link_to t("admin.legislation.processes.subnav.proposals"), admin_legislation_process_proposals_path(process) %> +
  • > <%= link_to t("admin.legislation.processes.subnav.draft_texts"), admin_legislation_process_draft_versions_path(process) %>
  • diff --git a/app/views/admin/legislation/proposals/_form.html.erb b/app/views/admin/legislation/proposals/_form.html.erb new file mode 100644 index 000000000..30f7f4950 --- /dev/null +++ b/app/views/admin/legislation/proposals/_form.html.erb @@ -0,0 +1,36 @@ +<%= form_for [:admin, @process], html: {data: {watch_changes: true}} do |f| %> + + <% if @process.errors.any? %> + +
    + + + + <%= @process.errors.count %> + <%= t("admin.legislation.processes.errors.form.error", count: @process.errors.count) %> + +
    + + <% end %> + +
    +
    + <%= label_tag t('admin.legislation.proposals.form.header_information') %> + <%= t('admin.legislation.proposals.form.header_information_description') %> +
    +
    + <%= f.text_area :proposals_description, + label: false, + rows: 5, + placeholder: t('admin.legislation.proposals.form.header_information_placeholder') %> +
    +
    + +
    +
    + <%= f.submit(class: "button expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %> +
    +
    +<% end %> diff --git a/app/views/admin/legislation/proposals/index.html.erb b/app/views/admin/legislation/proposals/index.html.erb new file mode 100644 index 000000000..162f3c8dd --- /dev/null +++ b/app/views/admin/legislation/proposals/index.html.erb @@ -0,0 +1,16 @@ +<% provide :title do %> + Admin - <%= t("admin.menu.legislation") %> - <%= @process.title %> - <%= t("admin.legislation.proposals.index.title") %> +<% end %> + +
    +
    + <%= back_link_to admin_legislation_processes_path, t("admin.legislation.proposals.index.back") %> + +

    <%= @process.title %>

    + + <%= render 'admin/legislation/processes/subnav', process: @process, active: 'proposals' %> + + <%= render "form" %> + +
    +
    diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 3793b75a8..275d628e5 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -291,6 +291,15 @@ en: info: Information draft_texts: Text questions: Debate + proposals: Proposals + proposals: + index: + title: Proposals + back: Back + form: + header_information: Information header + header_information_description: Provide information about the proposals. This text will be displayed as an alert in the Proposals section inside this Process. Use Markdown to format the text. + header_information_placeholder: Add information for the proposals' header draft_versions: create: notice: 'Draft created successfully. Click to visit' diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 27262845d..54ab2ce8f 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -291,6 +291,15 @@ es: info: Información draft_texts: Texto questions: Debate + proposals: Propuestas + proposals: + index: + title: Propuestas + back: Volver + form: + header_information: Encabezado de información + header_information_description: Proporciona información sobre el recorrido de las propuestas. Este texto se mostrará como una alerta en el encabezado de la sección de Propuestas dentro de este proceso. Usa Markdown para formatear el texto. + header_information_placeholder: Añade información para el encabezado de las las propuestas draft_versions: create: notice: 'Borrador creado correctamente. Haz click para verlo' diff --git a/db/migrate/20170913130803_add_proposals_description_to_legislation_processes.rb b/db/migrate/20170913130803_add_proposals_description_to_legislation_processes.rb new file mode 100644 index 000000000..d5e4f9c5d --- /dev/null +++ b/db/migrate/20170913130803_add_proposals_description_to_legislation_processes.rb @@ -0,0 +1,5 @@ +class AddProposalsDescriptionToLegislationProcesses < ActiveRecord::Migration + def change + add_column :legislation_processes, :proposals_description, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 578a0bc25..5b84833a7 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: 20170913101029) do +ActiveRecord::Schema.define(version: 20170913130803) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -473,6 +473,7 @@ ActiveRecord::Schema.define(version: 20170913101029) do t.date "proposals_phase_start_date" t.date "proposals_phase_end_date" t.boolean "proposals_phase_enabled" + t.text "proposals_description" end add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree From fb44a931df25c90b964b94b3c51b2e8ad8dbbf59 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 13 Sep 2017 17:45:56 +0200 Subject: [PATCH 05/46] fixes legislation key dates with new proposal dates --- app/assets/stylesheets/legislation_process.scss | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 2ec9f8ee9..f31d02ef6 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -109,16 +109,13 @@ $border-dark: darken($border, 10%); li { cursor: pointer; display: inline-block; - margin: 0 1rem 1rem 0; + margin-bottom: $line-height; + margin-right: $line-height; transition: all 0.4s; border-bottom: 2px solid transparent; @include breakpoint(medium) { - margin-left: $line-height * 2; - } - - &:first-of-type { - margin-left: 0; + margin-bottom: 0; } &:hover, From 929e81a878246ea55144ef365b1976e8117ff0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 14 Sep 2017 12:49:13 +0200 Subject: [PATCH 06/46] Added proposals phase to key dates --- .../legislation/processes/_key_dates.html.erb | 17 +++++++++++++---- .../legislation/processes/_process.html.erb | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index f1198c2e3..0bc95bef5 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -6,7 +6,7 @@
      <% if process.debate_phase.enabled? %> -
    • > +
    • > <%= link_to debate_legislation_process_path(process) do %>

      <%= t('legislation.processes.shared.debate_dates') %>

      <%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>

      @@ -14,8 +14,17 @@
    • <% end %> + <% if process.proposals_phase.enabled? %> +
    • > + <%= link_to proposals_legislation_process_path(process) do %> +

      <%= t('legislation.processes.shared.proposals_dates') %>

      +

      <%= format_date(process.proposals_phase_start_date) %> - <%= format_date(process.proposals_phase_end_date) %>

      + <% end %> +
    • + <% end %> + <% if process.draft_publication.enabled? %> -
    • > +
    • > <%= link_to draft_publication_legislation_process_path(process) do %>

      <%= t('legislation.processes.shared.draft_publication_date') %>

      <%= format_date(process.draft_publication_date) %>

      @@ -24,7 +33,7 @@ <% end %> <% if process.allegations_phase.enabled? %> -
    • > +
    • > <%= link_to allegations_legislation_process_path(process) do %>

      <%= t('legislation.processes.shared.allegations_dates') %>

      <%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>

      @@ -33,7 +42,7 @@ <% end %> <% if process.result_publication.enabled? %> -
    • > +
    • > <%= link_to result_publication_legislation_process_path(process) do %>

      <%= t('legislation.processes.shared.result_publication_date') %>

      <%= format_date(process.result_publication_date) %>

      diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb index d5e44076a..a41fdbe4a 100644 --- a/app/views/legislation/processes/_process.html.erb +++ b/app/views/legislation/processes/_process.html.erb @@ -40,6 +40,13 @@
    <% end %> + <% if process.proposals_phase.enabled? %> +
    +
    <%= t('legislation.processes.shared.proposals_dates') %>
    +

    <%= format_date(process.proposals_phase_start_date) %> - <%= format_date(process.proposals_phase_end_date) %>

    +
    + <% end %> + <% if process.allegations_phase.enabled? %>
    <%= t('legislation.processes.shared.allegations_dates') %>
    From 335399e571b8a0ae451737c8d4f8526e3db88ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 14 Sep 2017 12:50:48 +0200 Subject: [PATCH 07/46] Created Legislation Proposals model --- app/models/legislation/process.rb | 1 + app/models/legislation/proposal.rb | 191 +++++++++++++++++- ...0914102634_create_legislation_proposals.rb | 32 +++ db/schema.rb | 33 ++- 4 files changed, 253 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20170914102634_create_legislation_proposals.rb diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 6a37aeef2..7e1e884cb 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -18,6 +18,7 @@ class Legislation::Process < ActiveRecord::Base validates :debate_end_date, presence: true, if: :debate_start_date? validates :allegations_start_date, presence: true, if: :allegations_end_date? validates :allegations_end_date, presence: true, if: :allegations_start_date? + validates :proposals_phase_end_date, presence: true, if: :proposals_phase_start_date? validate :valid_date_ranges scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current).order('id DESC') } diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 2c187d302..1eb82e70a 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -1,8 +1,193 @@ -class Legislation::Proposal < Proposal - acts_as_paranoid column: :hidden_at +class Legislation::Proposal < ActiveRecord::Base include ActsAsParanoidAliases + include Flaggable + include Taggable + include Conflictable + include Measurable + include Sanitizable + include Searchable + include Filterable + include HasPublicAuthor + include Graphqlable + include Followable + include Communitable + include Documentable + + documentable max_documents_allowed: 3, + max_file_size: 3.megabytes, + accepted_content_types: [ "application/pdf" ] + accepts_nested_attributes_for :documents, allow_destroy: true + + acts_as_votable + acts_as_paranoid column: :hidden_at + + RETIRE_OPTIONS = %w(duplicated started unfeasible done other) belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' + belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :geozone + has_many :comments, as: :commentable + has_many :proposal_notifications - scope :sorted, -> { order('id ASC') } + validates :title, presence: true + validates :question, presence: true + validates :summary, presence: true + validates :author, presence: true + validates :responsible_name, presence: true + + validates :title, length: { in: 4..Legislation::Proposal.title_max_length } + validates :description, length: { maximum: Legislation::Proposal.description_max_length } + validates :question, length: { in: 10..Legislation::Proposal.question_max_length } + validates :responsible_name, length: { in: 6..Legislation::Proposal.responsible_name_max_length } + validates :retired_reason, inclusion: {in: RETIRE_OPTIONS, allow_nil: true} + + validates :terms_of_service, acceptance: { allow_nil: false }, on: :create + + before_validation :set_responsible_name + + before_save :calculate_hot_score, :calculate_confidence_score + + scope :for_render, -> { includes(:tags) } + scope :sort_by_hot_score, -> { reorder(hot_score: :desc) } + scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) } + scope :sort_by_created_at, -> { reorder(created_at: :desc) } + scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } + scope :sort_by_random, -> { reorder("RANDOM()") } + scope :sort_by_relevance, -> { all } + scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } + scope :sort_by_archival_date, -> { archived.sort_by_confidence_score } + scope :archived, -> { where("proposals.created_at <= ?", Setting["months_to_archive_proposals"].to_i.months.ago) } + scope :not_archived, -> { where("proposals.created_at > ?", Setting["months_to_archive_proposals"].to_i.months.ago) } + scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} + scope :retired, -> { where.not(retired_at: nil) } + scope :not_retired, -> { where(retired_at: nil) } + scope :successful, -> { where("cached_votes_up >= ?", Legislation::Proposal.votes_needed_for_success) } + scope :public_for_api, -> { all } + + def to_param + "#{id}-#{title}".parameterize + end + + def searchable_values + { title => 'A', + question => 'B', + author.username => 'B', + tag_list.join(' ') => 'B', + geozone.try(:name) => 'B', + summary => 'C', + description => 'D' + } + end + + def self.search(terms) + by_code = search_by_code(terms.strip) + by_code.present? ? by_code : pg_search(terms) + end + + def self.search_by_code(terms) + matched_code = match_code(terms) + results = where(id: matched_code[1]) if matched_code + return results if (results.present? && results.first.code == terms) + end + + def self.match_code(terms) + /\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms) + end + + def self.for_summary + summary = {} + categories = ActsAsTaggableOn::Tag.category_names.sort + geozones = Geozone.names.sort + + groups = categories + geozones + groups.each do |group| + summary[group] = search(group).last_week.sort_by_confidence_score.limit(3) + end + summary + end + + def total_votes + cached_votes_up + end + + def voters + User.active.where(id: votes_for.voters) + end + + def editable? + total_votes <= Setting["max_votes_for_proposal_edit"].to_i + end + + def editable_by?(user) + author_id == user.id && editable? + end + + def votable_by?(user) + user && user.level_two_or_three_verified? + end + + def retired? + retired_at.present? + end + + def register_vote(user, vote_value) + if votable_by?(user) && !archived? + vote_by(voter: user, vote: vote_value) + end + end + + def code + "#{Setting['proposal_code_prefix']}-#{created_at.strftime('%Y-%m')}-#{id}" + end + + def after_commented + save # updates the hot_score because there is a before_save + end + + def calculate_hot_score + self.hot_score = ScoreCalculator.hot_score(created_at, + total_votes, + total_votes, + comments_count) + end + + def calculate_confidence_score + self.confidence_score = ScoreCalculator.confidence_score(total_votes, total_votes) + end + + def after_hide + tags.each{ |t| t.decrement_custom_counter_for('Proposal') } + end + + def after_restore + tags.each{ |t| t.increment_custom_counter_for('Proposal') } + end + + def self.votes_needed_for_success + Setting['votes_for_proposal_success'].to_i + end + + def successful? + total_votes >= Legislation::Proposal.votes_needed_for_success + end + + def archived? + created_at <= Setting["months_to_archive_proposals"].to_i.months.ago + end + + def notifications + proposal_notifications + end + + def users_to_notify + (voters + followers).uniq + end + + protected + + def set_responsible_name + if author && author.document_number? + self.responsible_name = author.document_number + end + end end diff --git a/db/migrate/20170914102634_create_legislation_proposals.rb b/db/migrate/20170914102634_create_legislation_proposals.rb new file mode 100644 index 000000000..defe9f1dd --- /dev/null +++ b/db/migrate/20170914102634_create_legislation_proposals.rb @@ -0,0 +1,32 @@ +class CreateLegislationProposals < ActiveRecord::Migration + def change + create_table :legislation_proposals do |t| + t.references :legislation_process, index: true, foreign_key: true + t.string :title, limit: 80 + t.text :description + t.string :question + t.string :external_url + t.integer :author_id + t.datetime :hidden_at + t.integer :flags_count, default: 0 + t.datetime :ignored_flag_at + t.integer :cached_votes_up, default: 0 + t.integer :comments_count, default: 0 + t.datetime :confirmed_hide_at + t.integer :hot_score, limit: 8, default: 0 + t.integer :confidence_score, default: 0 + t.string :responsible_name, limit: 60 + t.text :summary + t.string :video_url + t.tsvector :tsv + t.integer :geozone_id + t.datetime :retired_at + t.string :retired_reason + t.text :retired_explanation + t.integer :community_id + + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5b84833a7..8a33adfc8 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: 20170913130803) do +ActiveRecord::Schema.define(version: 20170914102634) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -486,6 +486,36 @@ ActiveRecord::Schema.define(version: 20170913130803) do add_index "legislation_processes", ["result_publication_date"], name: "index_legislation_processes_on_result_publication_date", using: :btree add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree + create_table "legislation_proposals", force: :cascade do |t| + t.integer "legislation_process_id" + t.string "title", limit: 80 + t.text "description" + t.string "question" + t.string "external_url" + t.integer "author_id" + t.datetime "hidden_at" + t.integer "flags_count", default: 0 + t.datetime "ignored_flag_at" + t.integer "cached_votes_up", default: 0 + t.integer "comments_count", default: 0 + t.datetime "confirmed_hide_at" + t.integer "hot_score", limit: 8, default: 0 + t.integer "confidence_score", default: 0 + t.string "responsible_name", limit: 60 + t.text "summary" + t.string "video_url" + t.tsvector "tsv" + t.integer "geozone_id" + t.datetime "retired_at" + t.string "retired_reason" + t.text "retired_explanation" + t.integer "community_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree + create_table "legislation_question_options", force: :cascade do |t| t.integer "legislation_question_id" t.string "value" @@ -1083,6 +1113,7 @@ ActiveRecord::Schema.define(version: 20170913130803) do add_foreign_key "geozones_polls", "polls" add_foreign_key "identities", "users" add_foreign_key "legislation_draft_versions", "legislation_processes" + add_foreign_key "legislation_proposals", "legislation_processes" add_foreign_key "locks", "users" add_foreign_key "managers", "users" add_foreign_key "moderators", "users" From 0245605f19be78bc42faae19bef0c4f548499d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 14 Sep 2017 12:51:36 +0200 Subject: [PATCH 08/46] Added Legislation Proposals controller --- .../legislation/processes_controller.rb | 13 ++ .../legislation/proposals_controller.rb | 131 ++++++++++++++++++ config/routes.rb | 17 +++ 3 files changed, 161 insertions(+) create mode 100644 app/controllers/legislation/proposals_controller.rb diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 588ffdf9e..6c12cea5b 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -14,6 +14,8 @@ class Legislation::ProcessesController < Legislation::BaseController redirect_to legislation_process_draft_version_path(@process, draft_version) elsif @process.debate_phase.enabled? redirect_to debate_legislation_process_path(@process) + elsif @process.proposals_phase.enabled? + redirect_to proposals_legislation_process_path(@process) else redirect_to allegations_legislation_process_path(@process) end @@ -81,6 +83,17 @@ class Legislation::ProcessesController < Legislation::BaseController end end + def proposals + set_process + @phase = :proposals_phase + + if @process.proposals_phase.started? + render :proposals + else + render :phase_not_open + end + end + private def member_method? diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb new file mode 100644 index 000000000..a275a061d --- /dev/null +++ b/app/controllers/legislation/proposals_controller.rb @@ -0,0 +1,131 @@ +class Legislation::ProposalsController < ApplicationController + include CommentableActions + include FlagActions + + load_and_authorize_resource :process + load_and_authorize_resource :proposal, through: :process + + before_action :parse_tag_filter, only: :index + before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] + before_action :load_geozones, only: [:edit, :map, :summary] + before_action :authenticate_user!, except: [:index, :show, :map, :summary] + + invisible_captcha only: [:create, :update], honeypot: :subtitle + + has_orders %w{hot_score confidence_score created_at relevance archival_date}, only: :index + has_orders %w{most_voted newest oldest}, only: :show + + load_and_authorize_resource + helper_method :resource_model, :resource_name + respond_to :html, :js + + def show + super + @notifications = @proposal.notifications + @document = Document.new(documentable: @proposal) + redirect_to proposal_path(@proposal), status: :moved_permanently if request.path != proposal_path(@proposal) + end + + def create + @proposal = Legislation::Proposal.new(proposal_params.merge(author: current_user)) + recover_documents_from_cache(@proposal) + + if @proposal.save + redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal') + else + render :new + end + end + + def index_customization + discard_archived + load_retired + load_successful_proposals + load_featured unless @proposal_successful_exists + end + + def vote + @proposal.register_vote(current_user, 'yes') + set_proposal_votes(@proposal) + end + + def retire + if valid_retired_params? && @proposal.update(retired_params.merge(retired_at: Time.current)) + redirect_to proposal_path(@proposal), notice: t('proposals.notice.retired') + else + render action: :retire_form + end + end + + def retire_form + end + + def share + if Setting['proposal_improvement_path'].present? + @proposal_improvement_path = Setting['proposal_improvement_path'] + end + end + + def vote_featured + @proposal.register_vote(current_user, 'yes') + set_featured_proposal_votes(@proposal) + end + + def summary + @proposals = Legislation::Proposal.for_summary + @tag_cloud = tag_cloud + end + + private + + def proposal_params + params.require(:proposal).permit(:legislation_process_id, :title, :question, :summary, :description, :external_url, :video_url, + :responsible_name, :tag_list, :terms_of_service, :geozone_id, + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) + end + + def retired_params + params.require(:proposal).permit(:retired_reason, :retired_explanation) + end + + def valid_retired_params? + @proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:proposal][:retired_reason].blank? + @proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:proposal][:retired_explanation].blank? + @proposal.errors.empty? + end + + def resource_model + Legislation::Proposal + end + + def set_featured_proposal_votes(proposals) + @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} + end + + def discard_archived + @resources = @resources.not_archived unless @current_order == "archival_date" + end + + def load_retired + if params[:retired].present? + @resources = @resources.retired + @resources = @resources.where(retired_reason: params[:retired]) if Legislation::Proposal::RETIRE_OPTIONS.include?(params[:retired]) + else + @resources = @resources.not_retired + end + end + + def load_featured + return unless !@advanced_search_terms && @search_terms.blank? && @tag_filter.blank? && params[:retired].blank? + @featured_proposals = Legislation::Proposal.not_archived.sort_by_confidence_score.limit(3) + if @featured_proposals.present? + set_featured_proposal_votes(@featured_proposals) + @resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id)) + end + end + + def load_successful_proposals + @proposal_successful_exists = Legislation::Proposal.successful.exists? + end + +end diff --git a/config/routes.rb b/config/routes.rb index f0276f290..e2ccb51ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -124,10 +124,27 @@ Rails.application.routes.draw do 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 + 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 :draft_versions, only: [:show] do get :go_to_version, on: :collection get :changes From 0ed6b0da6b1b714c64fa1c9bcbd526b8e5b98f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 14 Sep 2017 12:52:03 +0200 Subject: [PATCH 09/46] Added Legislation Proposals views --- .../legislation/processes/proposals.html.erb | 29 +++ .../legislation/proposals/_actions.html.erb | 10 + .../proposals/_categories.html.erb | 12 ++ .../legislation/proposals/_comments.html.erb | 24 +++ .../proposals/_featured_proposal.html.erb | 27 +++ .../proposals/_featured_votes.html.erb | 44 +++++ .../proposals/_filter_subnav.html.erb | 30 +++ .../proposals/_flag_actions.html.erb | 21 ++ .../legislation/proposals/_form.html.erb | 103 ++++++++++ .../legislation/proposals/_geozones.html.erb | 6 + .../proposals/_notifications.html.erb | 17 ++ .../legislation/proposals/_popular.html.erb | 6 + .../legislation/proposals/_proposal.html.erb | 81 ++++++++ .../proposals/_refresh_flag_actions.js.erb | 1 + .../legislation/proposals/_retired.html.erb | 13 ++ .../legislation/proposals/_votes.html.erb | 66 +++++++ app/views/legislation/proposals/edit.html.erb | 14 ++ .../legislation/proposals/index.html.erb | 102 ++++++++++ app/views/legislation/proposals/map.html.erb | 1 + app/views/legislation/proposals/new.html.erb | 24 +++ .../proposals/retire_form.html.erb | 38 ++++ .../legislation/proposals/share.html.erb | 51 +++++ app/views/legislation/proposals/show.html.erb | 183 ++++++++++++++++++ .../legislation/proposals/suggest.js.erb | 1 + .../legislation/proposals/summary.html.erb | 53 +++++ app/views/legislation/proposals/vote.js.erb | 1 + .../proposals/vote_featured.js.erb | 1 + config/locales/es/legislation.yml | 1 + 28 files changed, 960 insertions(+) create mode 100644 app/views/legislation/processes/proposals.html.erb create mode 100644 app/views/legislation/proposals/_actions.html.erb create mode 100644 app/views/legislation/proposals/_categories.html.erb create mode 100644 app/views/legislation/proposals/_comments.html.erb create mode 100644 app/views/legislation/proposals/_featured_proposal.html.erb create mode 100644 app/views/legislation/proposals/_featured_votes.html.erb create mode 100644 app/views/legislation/proposals/_filter_subnav.html.erb create mode 100644 app/views/legislation/proposals/_flag_actions.html.erb create mode 100644 app/views/legislation/proposals/_form.html.erb create mode 100644 app/views/legislation/proposals/_geozones.html.erb create mode 100644 app/views/legislation/proposals/_notifications.html.erb create mode 100644 app/views/legislation/proposals/_popular.html.erb create mode 100644 app/views/legislation/proposals/_proposal.html.erb create mode 100644 app/views/legislation/proposals/_refresh_flag_actions.js.erb create mode 100644 app/views/legislation/proposals/_retired.html.erb create mode 100644 app/views/legislation/proposals/_votes.html.erb create mode 100644 app/views/legislation/proposals/edit.html.erb create mode 100644 app/views/legislation/proposals/index.html.erb create mode 100644 app/views/legislation/proposals/map.html.erb create mode 100644 app/views/legislation/proposals/new.html.erb create mode 100644 app/views/legislation/proposals/retire_form.html.erb create mode 100644 app/views/legislation/proposals/share.html.erb create mode 100644 app/views/legislation/proposals/show.html.erb create mode 100644 app/views/legislation/proposals/suggest.js.erb create mode 100644 app/views/legislation/proposals/summary.html.erb create mode 100644 app/views/legislation/proposals/vote.js.erb create mode 100644 app/views/legislation/proposals/vote_featured.js.erb diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb new file mode 100644 index 000000000..9e54ba46e --- /dev/null +++ b/app/views/legislation/processes/proposals.html.erb @@ -0,0 +1,29 @@ +<% provide :title do %><%= @process.title %><% end %> + +<%= render 'legislation/processes/header', process: @process, header: :full %> + +<%= render 'key_dates', process: @process, phase: :proposals %> + +
    +
    +
    +
    +
    + <% if @process.proposals.empty? %> +
    +

    <%= t('.empty_questions') %>

    +
    + <% else %> + <%= render @process.proposals %> + <% end %> +
    +
    + +
    +
    +

    <%= t('.participate') %>

    +
    +
    +
    +
    +
    diff --git a/app/views/legislation/proposals/_actions.html.erb b/app/views/legislation/proposals/_actions.html.erb new file mode 100644 index 000000000..b2bc9f111 --- /dev/null +++ b/app/views/legislation/proposals/_actions.html.erb @@ -0,0 +1,10 @@ +<% if can? :hide, proposal %> + <%= link_to t("admin.actions.hide").capitalize, hide_moderation_proposal_path(proposal), + method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> +<% end %> + +<% if can? :hide, proposal.author %> +  |  + <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(proposal.author_id), + method: :put, data: { confirm: t('admin.actions.confirm') } %> +<% end %> diff --git a/app/views/legislation/proposals/_categories.html.erb b/app/views/legislation/proposals/_categories.html.erb new file mode 100644 index 000000000..a694eb555 --- /dev/null +++ b/app/views/legislation/proposals/_categories.html.erb @@ -0,0 +1,12 @@ + + +
    + +
      + <% @categories.each do |category| %> +
    • + <% css_class = { class: 'active' } if params[:search] == category.name %> + <%= link_to category.name, proposals_path(search: category.name), css_class || {} %> +
    • + <% end %> +
    diff --git a/app/views/legislation/proposals/_comments.html.erb b/app/views/legislation/proposals/_comments.html.erb new file mode 100644 index 000000000..c304bc4dd --- /dev/null +++ b/app/views/legislation/proposals/_comments.html.erb @@ -0,0 +1,24 @@ +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count, @comment_flags] do %> +
    +
    + <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> + + <% if user_signed_in? %> + <%= render 'comments/form', {commentable: @proposal, parent_id: nil, toggeable: false} %> + <% else %> +
    + +
    + <%= t("proposals.show.login_to_comment", + signin: link_to(t("votes.signin"), new_user_session_path), + signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> +
    + <% end %> + + <% @comment_tree.root_comments.each do |comment| %> + <%= render 'comments/comment', comment: comment %> + <% end %> + <%= paginate @comment_tree.root_comments %> +
    +
    +<% end %> diff --git a/app/views/legislation/proposals/_featured_proposal.html.erb b/app/views/legislation/proposals/_featured_proposal.html.erb new file mode 100644 index 000000000..5500b2418 --- /dev/null +++ b/app/views/legislation/proposals/_featured_proposal.html.erb @@ -0,0 +1,27 @@ + diff --git a/app/views/legislation/proposals/_featured_votes.html.erb b/app/views/legislation/proposals/_featured_votes.html.erb new file mode 100644 index 000000000..3177812a4 --- /dev/null +++ b/app/views/legislation/proposals/_featured_votes.html.erb @@ -0,0 +1,44 @@ +
    +
    + <% if voted_for?(@featured_proposals_votes, proposal) %> +
    + <%= t("proposals.proposal.already_supported") %> +
    + <% else %> + <%= link_to vote_featured_proposal_path(proposal, value: 'yes'), + class: "button button-support small expanded", + title: t('proposals.proposal.support_title'), method: "post", remote: true do %> + <%= t("proposals.proposal.support") %> + <% end %> + <% end %> +
    + + <% if user_signed_in? && current_user.organization? %> + + <% elsif user_signed_in? && !proposal.votable_by?(current_user)%> + + <% elsif !user_signed_in? %> + + <% end %> + + <% if voted_for?(@featured_proposals_votes, proposal) %> + <% if setting['twitter_handle'] %> + + <% end %> + <% end %> +
    diff --git a/app/views/legislation/proposals/_filter_subnav.html.erb b/app/views/legislation/proposals/_filter_subnav.html.erb new file mode 100644 index 000000000..fece62a17 --- /dev/null +++ b/app/views/legislation/proposals/_filter_subnav.html.erb @@ -0,0 +1,30 @@ +
    +
    +
      +
    • + <%= link_to "#tab-comments" do %> +

      + <%= t("proposals.show.comments_tab") %> + (<%= @proposal.comments_count %>) +

      + <% end %> +
    • +
    • + <%= link_to "#tab-notifications" do %> +

      + <%= t("proposals.show.notifications_tab") %> + (<%= @notifications.count %>) +

      + <% end %> +
    • +
    • + <%= link_to "#tab-documents" do %> +

      + <%= t("documents.tab") %> + (<%= @proposal.documents.count %>) +

      + <% end %> +
    • +
    +
    +
    diff --git a/app/views/legislation/proposals/_flag_actions.html.erb b/app/views/legislation/proposals/_flag_actions.html.erb new file mode 100644 index 000000000..3e776de66 --- /dev/null +++ b/app/views/legislation/proposals/_flag_actions.html.erb @@ -0,0 +1,21 @@ + + + <% if show_flag_action? proposal %> + + + + + <%= link_to t('shared.flag'), flag_proposal_path(proposal), method: :put, remote: true, id: "flag-proposal-#{ proposal.id }" %> + + <% end %> + + <% if show_unflag_action? proposal %> + + + + + <%= link_to t('shared.unflag'), unflag_proposal_path(proposal), method: :put, remote: true, id: "unflag-proposal-#{ proposal.id }" %> + + <% end %> + + diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb new file mode 100644 index 000000000..73b39dfdb --- /dev/null +++ b/app/views/legislation/proposals/_form.html.erb @@ -0,0 +1,103 @@ +<%= form_for(@proposal, url: form_url) do |f| %> + <%= render 'shared/errors', resource: @proposal %> + +
    +
    + <%= f.label :title, t("proposals.form.proposal_title") %> + <%= f.text_field :title, maxlength: Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_proposals_path}%> +
    +
    + + <%= f.invisible_captcha :subtitle %> + +
    + <%= f.label :question, t("proposals.form.proposal_question") %> +

    + <%= t("proposals.form.proposal_question_example_html") %> +

    + <%= f.text_field :question, maxlength: Proposal.question_max_length, + placeholder: t("proposals.form.proposal_question"), + label: false, + aria: {describedby: "question-help-text"} %> +
    + +
    + <%= f.label :summary, t("proposals.form.proposal_summary") %> +

    <%= t("proposals.form.proposal_summary_note") %>

    + <%= f.text_area :summary, rows: 4, maxlength: 200, label: false, + placeholder: t('proposals.form.proposal_summary'), + aria: {describedby: "summary-help-text"} %> +
    + +
    + <%= f.label :description, t("proposals.form.proposal_text") %> + <%= f.cktext_area :description, maxlength: Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> +
    + +
    + <%= f.label :video_url, t("proposals.form.proposal_video_url") %> +

    <%= t("proposals.form.proposal_video_url_note") %>

    + <%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false, + aria: {describedby: "video-url-help-text"} %> +
    + +
    + <%= f.label :external_url, t("proposals.form.proposal_external_url") %> + <%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %> +
    + +
    + <%= render 'documents/nested_documents', documentable: @proposal %> +
    + +
    + <%= f.label :geozone_id, t("proposals.form.geozone") %> + <%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %> +
    + +
    + <%= f.label :tag_list, t("proposals.form.tags_label") %> +

    <%= t("proposals.form.tags_instructions") %>

    + +
    + <%= f.label :category_tag_list, t("proposals.form.tag_category_label") %> + <% @categories.each do |tag| %> + <%= tag.name %> + <% end %> +
    + +
    + <%= f.text_field :tag_list, value: @proposal.tag_list.to_s, + label: false, + placeholder: t("proposals.form.tags_placeholder"), + class: 'js-tag-list', + aria: {describedby: "tag-list-help-text"} %> +
    + + <% if current_user.unverified? %> +
    + <%= f.label :responsible_name, t("proposals.form.proposal_responsible_name") %> +

    <%= t("proposals.form.proposal_responsible_name_note") %>

    + <%= f.text_field :responsible_name, placeholder: t("proposals.form.proposal_responsible_name"), label: false, + aria: {describedby: "responsible-name-help-text"} %> +
    + <% end %> + +
    + <% if @proposal.new_record? %> + <%= f.label :terms_of_service do %> + <%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %> + + <%= t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> + + <% end %> + <% end %> +
    + +
    + <%= f.submit(class: "button", value: t("proposals.#{action_name}.form.submit_button")) %> +
    +
    +<% end %> diff --git a/app/views/legislation/proposals/_geozones.html.erb b/app/views/legislation/proposals/_geozones.html.erb new file mode 100644 index 000000000..7e4dbcaa4 --- /dev/null +++ b/app/views/legislation/proposals/_geozones.html.erb @@ -0,0 +1,6 @@ + + +
    +<%= link_to map_proposals_path, id: 'map', title: t("shared.tags_cloud.districts_list") do %> + <%= image_tag("map.jpg", alt: t("shared.tags_cloud.districts_list")) %> +<% end %> diff --git a/app/views/legislation/proposals/_notifications.html.erb b/app/views/legislation/proposals/_notifications.html.erb new file mode 100644 index 000000000..69389b2c5 --- /dev/null +++ b/app/views/legislation/proposals/_notifications.html.erb @@ -0,0 +1,17 @@ +
    +
    +
    + <% if @notifications.blank? %> +
    + <%= t('proposals.show.no_notifications') %> +
    + <% end %> + + <% @notifications.each do |notification| %> +

    <%= notification.title %>

    +

    <%= notification.created_at.to_date %>

    +

    <%= notification.body %>

    + <% end %> +
    +
    +
    diff --git a/app/views/legislation/proposals/_popular.html.erb b/app/views/legislation/proposals/_popular.html.erb new file mode 100644 index 000000000..7f46ea802 --- /dev/null +++ b/app/views/legislation/proposals/_popular.html.erb @@ -0,0 +1,6 @@ + + + +

    + <%= link_to t("proposals.index.top_link_proposals"), summary_proposals_path, class: "small" %>
    +

    diff --git a/app/views/legislation/proposals/_proposal.html.erb b/app/views/legislation/proposals/_proposal.html.erb new file mode 100644 index 000000000..c269146ab --- /dev/null +++ b/app/views/legislation/proposals/_proposal.html.erb @@ -0,0 +1,81 @@ +
    Proposal.votes_needed_for_success) %>" + data-type="proposal"> +
    +
    +
    + +
    +
    + <% cache [locale_and_user_status(proposal), 'index', proposal, proposal.author] do %> +

    <%= link_to proposal.title, namespaced_proposal_path(proposal) %>

    +

    +   + <%= link_to t("proposals.proposal.comments", count: proposal.comments_count), namespaced_proposal_path(proposal, anchor: "comments") %> + +  •  + <%= l proposal.created_at.to_date %> + + <% if proposal.author.hidden? || proposal.author.erased? %> +  •  + + <%= t("proposals.show.author_deleted") %> + + <% else %> +  •  + + <%= proposal.author.name %> + + <% if proposal.author.display_official_position_badge? %> +  •  + + <%= proposal.author.official_position %> + + <% end %> + <% end %> + + <% if proposal.author.verified_organization? %> +  •  + + <%= t("shared.collective") %> + + <% end %> +

    +
    +

    <%= proposal.summary %>

    +
    +
    + <%= render "shared/tags", taggable: proposal, limit: 5 %> + <% end %> +
    +
    + +
    + <% if proposal.successful? %> +
    + +

    + <%= t("proposals.proposal.successful", + voting: link_to(t("proposals.proposal.voting"), polls_path)).html_safe %> +

    +
    + <% if can? :create, Poll::Question %> +

    + <%= link_to t('poll_questions.create_question'), + new_admin_question_path(proposal_id: proposal.id), + class: "button hollow" %> +

    + <% end %> + <% elsif proposal.archived? %> +
    + <%= t("proposals.proposal.supports", count: proposal.total_votes) %> +

    <%= t("proposals.proposal.archived") %>

    +
    + <% else %> + <%= render 'votes', + { proposal: proposal, vote_url: vote_proposal_path(proposal, value: 'yes') } %> + <% end %> +
    +
    +
    +
    diff --git a/app/views/legislation/proposals/_refresh_flag_actions.js.erb b/app/views/legislation/proposals/_refresh_flag_actions.js.erb new file mode 100644 index 000000000..0e20636ae --- /dev/null +++ b/app/views/legislation/proposals/_refresh_flag_actions.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@proposal) %> .js-flag-actions").html('<%= j render("proposals/flag_actions", proposal: @proposal) %>'); diff --git a/app/views/legislation/proposals/_retired.html.erb b/app/views/legislation/proposals/_retired.html.erb new file mode 100644 index 000000000..2167b14af --- /dev/null +++ b/app/views/legislation/proposals/_retired.html.erb @@ -0,0 +1,13 @@ + + + +<% if params[:retired].blank? %> +

    <%= link_to t("proposals.index.retired_proposals_link"), proposals_path(retired: 'all'), class: "small" %>

    +<% else %> + +<% end %> diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb new file mode 100644 index 000000000..fb41357af --- /dev/null +++ b/app/views/legislation/proposals/_votes.html.erb @@ -0,0 +1,66 @@ +
    +
    + + + <%= supports_percentage(proposal) %> / <%= t("proposals.proposal.total_percent") %> + +
    + + + <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  + + "> + <%= t("proposals.proposal.supports_necessary", number: number_with_delimiter(Proposal.votes_needed_for_success)) %> + + + + +
    + <% if voted_for?(@proposal_votes, proposal) %> +
    + <%= t("proposals.proposal.already_supported") %> +
    + <% elsif user_signed_in? && proposal.votable_by?(current_user) %> + <%= link_to vote_url, + class: "button button-support small expanded", + title: t('proposals.proposal.support_title'), method: "post", remote: true do %> + <%= t("proposals.proposal.support") %> + <% end %> + <% else %> +
    + <%= t("proposals.proposal.support") %> +
    + <% end %> +
    + + <% if user_signed_in? && current_user.organization? %> + + <% elsif user_signed_in? && !proposal.votable_by?(current_user) %> +
    + +
    + <% elsif !user_signed_in? %> +
    + +
    + <% end %> + + <% if voted_for?(@proposal_votes, proposal) && setting['twitter_handle'] %> + + <% end %> +
    diff --git a/app/views/legislation/proposals/edit.html.erb b/app/views/legislation/proposals/edit.html.erb new file mode 100644 index 000000000..6e5b14a08 --- /dev/null +++ b/app/views/legislation/proposals/edit.html.erb @@ -0,0 +1,14 @@ +
    + +
    + <%= back_link_to %> + +
    + <%= link_to t("proposals.edit.show_link"), @proposal %> +
    + +

    <%= t("proposals.edit.editing") %>

    + + <%= render "form", form_url: proposal_url(@proposal) %> +
    +
    diff --git a/app/views/legislation/proposals/index.html.erb b/app/views/legislation/proposals/index.html.erb new file mode 100644 index 000000000..69a8df4a3 --- /dev/null +++ b/app/views/legislation/proposals/index.html.erb @@ -0,0 +1,102 @@ +<% provide :title do %><%= t('proposals.index.title') %><% end %> +<% content_for :header_addon do %> + <%= render "shared/search_form", + search_path: proposals_path(page: 1), + i18n_namespace: "proposals.index.search_form" %> +<% end %> +<% content_for :canonical do %> + <%= render "shared/canonical", href: proposals_url %> +<% end %> + +
    + <% if @search_terms || @advanced_search_terms || @tag_filter || params[:retired].present? %> +
    +
    +
    + <% if @search_terms || @advanced_search_terms %> +

    <%= t("shared.search_results") %>

    +

    + <%= page_entries_info @proposals %> + <% if !@advanced_search_terms %> + <%= t("proposals.index.search_results_html", count: @proposals.size, search_term: @search_terms) %> + <% end %> +

    + <% elsif @tag_filter %> +

    <%= t("shared.search_results") %>

    +

    + <%= page_entries_info @proposals %> + <%= t("proposals.index.filter_topic", count: @proposals.size, topic: @tag_filter) %> +

    + <% elsif params[:retired].present? %> +

    <%= t("proposals.index.retired_proposals") %>

    + <% end %> +
    +
    +
    + <% else %> + <%= render "shared/section_header", i18n_namespace: "proposals.index.section_header", image: "proposals" %> + <% end %> + +
    +
    + + <% if has_banners? %> + <%= render "shared/banner" %> + <% end %> + + <% if @featured_proposals.present? %> + + <% end %> + + <%= render("shared/advanced_search", search_path: proposals_path(page: 1)) unless params[:retired].present? %> + + <%= render 'shared/order_links', i18n_namespace: "proposals.index" %> + + <% if @proposals.any? %> +
    + <%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button expanded' %> +
    + <% end %> + +
    + <%= render partial: 'proposals/proposal', collection: @proposals %> + <%= paginate @proposals %> + + <% unless @search_terms || @advanced_search_terms || @tag_filter %> +
    +

    + <%= t("proposals.index.section_footer.title") %> +

    +

    <%= t("proposals.index.section_footer.help_text_1") %>

    +

    <%= t("proposals.index.section_footer.help_text_2", + org: link_to(setting['org_name'], new_user_registration_path)).html_safe %>

    +

    <%= t("proposals.index.section_footer.help_text_3") %>

    +
    + <% end %> +
    +
    + +
    + +
    + +
    +
    diff --git a/app/views/legislation/proposals/map.html.erb b/app/views/legislation/proposals/map.html.erb new file mode 100644 index 000000000..84c7721f2 --- /dev/null +++ b/app/views/legislation/proposals/map.html.erb @@ -0,0 +1 @@ +<%= render 'shared/map', new_url_path: new_proposal_path %> diff --git a/app/views/legislation/proposals/new.html.erb b/app/views/legislation/proposals/new.html.erb new file mode 100644 index 000000000..95249e36e --- /dev/null +++ b/app/views/legislation/proposals/new.html.erb @@ -0,0 +1,24 @@ +
    + +
    + <%= back_link_to %> + +

    <%= t("proposals.new.start_new") %>

    +
    + <%= link_to more_info_path(anchor: "proposals") ,title: t('shared.target_blank_html'), target: "_blank" do %> + <%= t("proposals.new.more_info")%> + <% end %> +
    + <%= render "proposals/form", form_url: proposals_url %> +
    + +
    + +

    <%= t("proposals.new.recommendations_title") %>

    +
      +
    • <%= t("proposals.new.recommendation_one") %>
    • +
    • <%= t("proposals.new.recommendation_two") %>
    • +
    • <%= t("proposals.new.recommendation_three") %>
    • +
    +
    +
    diff --git a/app/views/legislation/proposals/retire_form.html.erb b/app/views/legislation/proposals/retire_form.html.erb new file mode 100644 index 000000000..d56277cb3 --- /dev/null +++ b/app/views/legislation/proposals/retire_form.html.erb @@ -0,0 +1,38 @@ +
    + +
    + +

    <%= t("proposals.retire_form.title") %>

    + +

    <%= link_to @proposal.title, @proposal %>

    + +
    + <%= t("proposals.retire_form.warning") %> +
    + + <%= form_for(@proposal, url: retire_proposal_path(@proposal)) do |f| %> + <%= render 'shared/errors', resource: @proposal %> +
    +
    + <%= f.label :retired_reason, t("proposals.retire_form.retired_reason_label") %> + <%= f.select :retired_reason, retire_proposals_options, {include_blank: t("proposals.retire_form.retired_reason_blank"), label: false} %> +
    +
    + +
    +
    + <%= f.label :retired_explanation, t("proposals.retire_form.retired_explanation_label") %> + <%= f.text_area :retired_explanation, rows: 4, maxlength: 500, label: false, + placeholder: t('proposals.retire_form.retired_explanation_placeholder') %> +
    +
    + +
    +
    + <%= f.submit(class: "button expanded", value: t("proposals.retire_form.submit_button")) %> +
    +
    + <% end %> + +
    +
    \ No newline at end of file diff --git a/app/views/legislation/proposals/share.html.erb b/app/views/legislation/proposals/share.html.erb new file mode 100644 index 000000000..f86882401 --- /dev/null +++ b/app/views/legislation/proposals/share.html.erb @@ -0,0 +1,51 @@ +<% provide :title do %><%= @proposal.title %><% end %> +<% provide :social_media_meta_tags do %> +<%= render "shared/social_media_meta_tags", + social_url: proposal_url(@proposal), + social_title: @proposal.title, + social_description: @proposal.summary %> +<% end %> +<% content_for :canonical do %> + <%= render "shared/canonical", href: proposal_url(@proposal) %> +<% end %> + +<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> +
    +
    +
    + +

    <%= t("proposals.proposal.created") %>

    + +

    + <%= t("proposals.proposal.share.guide") %>
    + <%= t("proposals.proposal.share.edit") %> +

    + + <%= render partial: 'shared/social_share', locals: { + title: @proposal.title, + url: proposal_url(@proposal) + } %> + + <% if @proposal_improvement_path.present? %> +
    +

    <%= t("proposals.proposal.improve_info") %>

    + <%= link_to t("proposals.proposal.improve_info_link"), @proposal_improvement_path, class: "button" %> +
    + <% end %> + +
    + <%= link_to t("proposals.proposal.share.view_proposal"), proposal_path(@proposal) %> +
    +
    + +
    +
    +

    + <%= @proposal.title %>
    + <%= t("proposals.show.code") %> <%= @proposal.code %> +

    +
    +
    +
    +
    +<% end %> diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb new file mode 100644 index 000000000..1dc918e8e --- /dev/null +++ b/app/views/legislation/proposals/show.html.erb @@ -0,0 +1,183 @@ +<% provide :title do %><%= @proposal.title %><% end %> +<% content_for :meta_description do %><%= @proposal.summary %><% end %> +<% provide :social_media_meta_tags do %> +<%= render "shared/social_media_meta_tags", + social_url: proposal_url(@proposal), + social_title: @proposal.title, + social_description: @proposal.summary %> +<% end %> +<% content_for :canonical do %> + <%= render "shared/canonical", href: proposal_url(@proposal) %> +<% end %> + +<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> +
    +
    +
    + <%= back_link_to %> + + <% if can?(:create, @document) && @proposal.documents.size < Proposal.max_documents_allowed %> + <%= link_to t("documents.upload_document"), + new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url), + class: 'button hollow float-right' %> + <% end %> + + <% if author_of?(@proposal, current_user) %> + <%= link_to t("proposals.show.send_notification"), + new_proposal_notification_path(proposal_id: @proposal.id), + class: 'button hollow float-right' %> + <% end %> + + <% if current_user && @proposal.editable_by?(current_user) %> + <%= link_to edit_proposal_path(@proposal), class: 'edit-proposal button hollow float-right' do %> + <%= t("proposals.show.edit_proposal_link") %> + <% end %> + <% end %> + +

    <%= @proposal.title %>

    + <% if @proposal.retired? %> +
    + + <%= t("proposals.show.retired_warning") %>
    + <%= link_to t("proposals.show.retired_warning_link_to_explanation"), "#retired_explanation" %> +
    +
    + <% elsif @proposal.conflictive? %> +
    + <%= t("proposals.show.flag") %> +
    + <% end %> + +
    + <%= render '/shared/author_info', resource: @proposal %> + +  •  + <%= l @proposal.created_at.to_date %> +  •  +   + <%= link_to t("proposals.show.comments", count: @proposal.comments_count), "#comments" %> + + <% if current_user %> +  •  + <%= render 'proposals/flag_actions', proposal: @proposal %> + <% end %> + +
    + +
    +

    + <%= t("proposals.show.code") %> + <%= @proposal.code %> +

    + +
    <%= @proposal.summary %>
    + + <% if @proposal.video_url.present? %> +
    +
    +
    +
    +
    + <% end %> + + <%= safe_html_with_links @proposal.description %> + + <% if @proposal.external_url.present? %> + + <% end %> + + <% if @proposal.video_url.present? %> + + + <% end %> + +

    <%= @proposal.question %>

    + + <% if @proposal.retired? %> +
    +

    <%= t('proposals.show.retired') %>: <%= t("proposals.retire_options.#{@proposal.retired_reason}") unless @proposal.retired_reason == 'other' %>

    + <%= simple_format text_with_links(@proposal.retired_explanation), {}, sanitize: false %> +
    + <% end %> + + <%= render 'shared/tags', taggable: @proposal %> + + <%= render 'shared/geozone', geozonable: @proposal %> + +
    + <%= render 'proposals/actions', proposal: @proposal %> +
    +
    + + +
    +
    +<% end %> + +
    + <%= render "proposals/filter_subnav" %> + <%= render "proposals/notifications" %> + +
    + <%= render "proposals/comments" %> +
    + +
    + <%= render 'documents/documents', + documents: @proposal.documents, + max_documents_allowed: Proposal.max_documents_allowed %> +
    +
    diff --git a/app/views/legislation/proposals/suggest.js.erb b/app/views/legislation/proposals/suggest.js.erb new file mode 100644 index 000000000..819af2b16 --- /dev/null +++ b/app/views/legislation/proposals/suggest.js.erb @@ -0,0 +1 @@ +<%= render "shared/suggest" %> \ No newline at end of file diff --git a/app/views/legislation/proposals/summary.html.erb b/app/views/legislation/proposals/summary.html.erb new file mode 100644 index 000000000..a28cf8750 --- /dev/null +++ b/app/views/legislation/proposals/summary.html.erb @@ -0,0 +1,53 @@ +
    +
    +
    + <%= back_link_to %> + + <% @proposals.each do |group_name, proposals| %> +
    +

    <%= group_name %>

    + + <% proposals[0..2].each do |proposal| %> +
    +
    +
    +
    +
    +

    <%= link_to proposal.title, namespaced_proposal_path(proposal) %>

    + +

    + <% if proposal.author.hidden? || proposal.author.erased? %> + <%= t("proposals.show.author_deleted") %> + <% else %> + <%= proposal.author.name %> + <% if proposal.author.display_official_position_badge? %> + + <%= proposal.author.official_position %> + + <% end %> + <% end %> +

    + +
    +

    <%= proposal.summary %>

    +
    +
    +
    +
    +
    +
    + <% end %> +
    + <% end %> +
    + +
    + +
    +
    +
    \ No newline at end of file diff --git a/app/views/legislation/proposals/vote.js.erb b/app/views/legislation/proposals/vote.js.erb new file mode 100644 index 000000000..4a5ca6b6b --- /dev/null +++ b/app/views/legislation/proposals/vote.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("proposals/votes", proposal: @proposal) %>'); \ No newline at end of file diff --git a/app/views/legislation/proposals/vote_featured.js.erb b/app/views/legislation/proposals/vote_featured.js.erb new file mode 100644 index 000000000..52619282b --- /dev/null +++ b/app/views/legislation/proposals/vote_featured.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("proposals/featured_votes", proposal: @proposal) %>'); \ No newline at end of file diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index 454422046..2e8b6e201 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -86,6 +86,7 @@ es: draft_publication_date: Publicación borrador allegations_dates: Alegaciones result_publication_date: Publicación resultados + proposals_dates: Propuestas questions: comments: comment_button: Publicar respuesta From 393e9f2b6a7dcaca236eabdfd6a4761011a42485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 14 Sep 2017 17:38:42 +0200 Subject: [PATCH 10/46] Added permissions for Legislation:Proposal --- app/models/abilities/administrator.rb | 11 +++++++++-- app/models/abilities/common.rb | 14 ++++++++++++++ app/models/abilities/everyone.rb | 1 + app/models/abilities/moderation.rb | 9 +++++++++ app/models/abilities/moderator.rb | 2 +- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 773dabf34..9d2335f9d 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -14,6 +14,9 @@ module Abilities can :restore, Proposal cannot :restore, Proposal, hidden_at: nil + can :restore, Legislation::Proposal + cannot :restore, Legislation::Proposal, hidden_at: nil + can :restore, User cannot :restore, User, hidden_at: nil @@ -26,6 +29,9 @@ module Abilities can :confirm_hide, Proposal cannot :confirm_hide, Proposal, hidden_at: nil + can :confirm_hide, Legislation::Proposal + cannot :confirm_hide, Legislation::Proposal, hidden_at: nil + can :confirm_hide, User cannot :confirm_hide, User, hidden_at: nil @@ -33,7 +39,7 @@ module Abilities can :unmark_featured, Debate can :comment_as_administrator, [Debate, Comment, Proposal, Poll::Question, Budget::Investment, - Legislation::Question, Legislation::Annotation, Topic] + Legislation::Question, Legislation::Proposal, Legislation::Annotation, Topic] can [:search, :create, :index, :destroy], ::Administrator can [:search, :create, :index, :destroy], ::Moderator @@ -71,7 +77,8 @@ module Abilities can [:manage], ::Legislation::Process can [:manage], ::Legislation::DraftVersion can [:manage], ::Legislation::Question - cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation] + can [:manage], ::Legislation::Proposal + cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal] can [:create, :destroy], Document end diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 620cfb212..459b779c7 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -18,12 +18,20 @@ module Abilities end can [:retire_form, :retire], Proposal, author_id: user.id + can :read, Legislation::Proposal + can :update, Legislation::Proposal do |proposal| + proposal.editable_by?(user) + end + can [:retire_form, :retire], Legislation::Proposal, author_id: user.id + can :create, Comment can :create, Debate can :create, Proposal + can :create, Legislation::Proposal can :suggest, Debate can :suggest, Proposal + can :suggest, Legislation::Proposal can [:flag, :unflag], Comment cannot [:flag, :unflag], Comment, user_id: user.id @@ -34,6 +42,9 @@ module Abilities can [:flag, :unflag], Proposal cannot [:flag, :unflag], Proposal, author_id: user.id + can [:flag, :unflag], Legislation::Proposal + cannot [:flag, :unflag], Legislation::Proposal, author_id: user.id + can [:create, :destroy], Follow can [:create, :destroy, :new], Document, documentable: { author_id: user.id } @@ -50,6 +61,9 @@ module Abilities can :vote, SpendingProposal can :create, SpendingProposal + can :vote, Legislation::Proposal + can :vote_featured, Legislation::Proposal + can :create, Budget::Investment, budget: { phase: "accepting" } can :suggest, Budget::Investment, budget: { phase: "accepting" } can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 3004ca8ad..d0cef4846 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -22,6 +22,7 @@ module Abilities can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer + can [:read, :map, :summary, :share], Legislation::Proposal can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation end end diff --git a/app/models/abilities/moderation.rb b/app/models/abilities/moderation.rb index e9a1da2ac..f0f823de1 100644 --- a/app/models/abilities/moderation.rb +++ b/app/models/abilities/moderation.rb @@ -38,6 +38,15 @@ module Abilities can :moderate, Proposal cannot :moderate, Proposal, author_id: user.id + can :hide, Legislation::Proposal, hidden_at: nil + cannot :hide, Legislation::Proposal, author_id: user.id + + can :ignore_flag, Legislation::Proposal, ignored_flag_at: nil, hidden_at: nil + cannot :ignore_flag, Legislation::Proposal, author_id: user.id + + can :moderate, Legislation::Proposal + cannot :moderate, Legislation::Proposal, author_id: user.id + can :hide, User cannot :hide, User, id: user.id diff --git a/app/models/abilities/moderator.rb b/app/models/abilities/moderator.rb index 4e1427c12..eac434f22 100644 --- a/app/models/abilities/moderator.rb +++ b/app/models/abilities/moderator.rb @@ -6,7 +6,7 @@ module Abilities merge Abilities::Moderation.new(user) can :comment_as_moderator, [Debate, Comment, Proposal, Budget::Investment, Poll::Question, - Legislation::Question, Legislation::Annotation, Topic] + Legislation::Question, Legislation::Annotation, Legislation::Proposal, Topic] end end end From 8805037e2fad1671fbb3139341ea5b3f5ae82d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 19 Sep 2017 10:08:01 +0200 Subject: [PATCH 11/46] Legislation proposal views changes --- app/views/legislation/proposals/_form.html.erb | 10 ++++++---- app/views/legislation/proposals/_proposal.html.erb | 4 ++-- app/views/legislation/proposals/new.html.erb | 2 +- app/views/legislation/proposals/share.html.erb | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 73b39dfdb..dec8e56d2 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -1,10 +1,12 @@ <%= form_for(@proposal, url: form_url) do |f| %> <%= render 'shared/errors', resource: @proposal %> + <%= f.hidden_field(:legislation_process_id, :value => params[:process_id]) %> +
    <%= f.label :title, t("proposals.form.proposal_title") %> - <%= f.text_field :title, maxlength: Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_proposals_path}%> + <%= f.text_field :title, maxlength: Legislation::Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_proposals_path}%>
    @@ -15,7 +17,7 @@

    <%= t("proposals.form.proposal_question_example_html") %>

    - <%= f.text_field :question, maxlength: Proposal.question_max_length, + <%= f.text_field :question, maxlength: Legislation::Proposal.question_max_length, placeholder: t("proposals.form.proposal_question"), label: false, aria: {describedby: "question-help-text"} %> @@ -31,7 +33,7 @@
    <%= f.label :description, t("proposals.form.proposal_text") %> - <%= f.cktext_area :description, maxlength: Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> + <%= f.cktext_area :description, maxlength: Legislation::Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
    @@ -46,7 +48,7 @@ <%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %>
    -
    +
    <%= render 'documents/nested_documents', documentable: @proposal %>
    diff --git a/app/views/legislation/proposals/_proposal.html.erb b/app/views/legislation/proposals/_proposal.html.erb index c269146ab..996be8f95 100644 --- a/app/views/legislation/proposals/_proposal.html.erb +++ b/app/views/legislation/proposals/_proposal.html.erb @@ -72,8 +72,8 @@

    <%= t("proposals.proposal.archived") %>

    <% else %> - <%= render 'votes', - { proposal: proposal, vote_url: vote_proposal_path(proposal, value: 'yes') } %> + <%= render 'legislation/proposals/votes', + { proposal: proposal, vote_url: vote_legislation_process_proposal_path(proposal.legislation_process_id, proposal, value: 'yes') } %> <% end %>
    diff --git a/app/views/legislation/proposals/new.html.erb b/app/views/legislation/proposals/new.html.erb index 95249e36e..f6f31bff5 100644 --- a/app/views/legislation/proposals/new.html.erb +++ b/app/views/legislation/proposals/new.html.erb @@ -9,7 +9,7 @@ <%= t("proposals.new.more_info")%> <% end %>
    - <%= render "proposals/form", form_url: proposals_url %> + <%= render "legislation/proposals/form", form_url: legislation_process_proposals_url, id: @proposal.id %>
    diff --git a/app/views/legislation/proposals/share.html.erb b/app/views/legislation/proposals/share.html.erb index f86882401..5faa9d985 100644 --- a/app/views/legislation/proposals/share.html.erb +++ b/app/views/legislation/proposals/share.html.erb @@ -34,7 +34,7 @@ <% end %>
    - <%= link_to t("proposals.proposal.share.view_proposal"), proposal_path(@proposal) %> + <%= link_to t("proposals.proposal.share.view_proposal"), legislation_process_proposal_path(@proposal.legislation_process_id, @proposal) %>
    From d83bb9e31fcb5ee9e5a58ce154b9b4563e4bb5f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 19 Sep 2017 10:08:36 +0200 Subject: [PATCH 12/46] Legislation proposal controller adaptation --- app/controllers/application_controller.rb | 4 ++++ .../legislation/proposals_controller.rb | 20 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 495a25314..318777314 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -76,6 +76,10 @@ class ApplicationController < ActionController::Base @proposal_votes = current_user ? current_user.proposal_votes(proposals) : {} end + def set_legislation_proposal_votes(proposals) + @proposal_votes = current_user ? current_user.legislation_proposal_votes(proposals) : {} + end + def set_spending_proposal_votes(spending_proposals) @spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {} end diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index a275a061d..1eab07047 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -1,9 +1,9 @@ -class Legislation::ProposalsController < ApplicationController +class Legislation::ProposalsController < Legislation::BaseController include CommentableActions include FlagActions - load_and_authorize_resource :process - load_and_authorize_resource :proposal, through: :process + load_and_authorize_resource :process, class: "Legislation::Process" + load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process before_action :parse_tag_filter, only: :index before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] @@ -15,7 +15,6 @@ class Legislation::ProposalsController < ApplicationController has_orders %w{hot_score confidence_score created_at relevance archival_date}, only: :index has_orders %w{most_voted newest oldest}, only: :show - load_and_authorize_resource helper_method :resource_model, :resource_name respond_to :html, :js @@ -23,7 +22,8 @@ class Legislation::ProposalsController < ApplicationController super @notifications = @proposal.notifications @document = Document.new(documentable: @proposal) - redirect_to proposal_path(@proposal), status: :moved_permanently if request.path != proposal_path(@proposal) + redirect_to legislation_process_proposal_path(params[:process_id], @proposal), + status: :moved_permanently if request.path != legislation_process_proposal_path(params[:process_id], @proposal) end def create @@ -31,7 +31,7 @@ class Legislation::ProposalsController < ApplicationController recover_documents_from_cache(@proposal) if @proposal.save - redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal') + redirect_to share_legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t('flash.actions.create.proposal') else render :new end @@ -46,7 +46,7 @@ class Legislation::ProposalsController < ApplicationController def vote @proposal.register_vote(current_user, 'yes') - set_proposal_votes(@proposal) + set_legislation_proposal_votes(@proposal) end def retire @@ -98,7 +98,11 @@ class Legislation::ProposalsController < ApplicationController Legislation::Proposal end - def set_featured_proposal_votes(proposals) + def resource_name + 'proposal' + end + + def set_legislation_proposal_votes(proposals) @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} end From 08d1e96575467159f6e13185f8b39185d46682f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 19 Sep 2017 10:09:43 +0200 Subject: [PATCH 13/46] Added migration to include `legislation/proposals_count` in tags table --- ...19_add_legislation_proposals_count_to_tags.rb | 6 ++++++ db/schema.rb | 16 +++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb diff --git a/db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb b/db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb new file mode 100644 index 000000000..9ce6ace89 --- /dev/null +++ b/db/migrate/20170915101519_add_legislation_proposals_count_to_tags.rb @@ -0,0 +1,6 @@ +class AddLegislationProposalsCountToTags < ActiveRecord::Migration + def change + add_column :tags, "legislation/proposals_count", :integer, default: 0 + add_index :tags, "legislation/proposals_count" + end +end diff --git a/db/schema.rb b/db/schema.rb index 8a33adfc8..41952607e 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: 20170914102634) do +ActiveRecord::Schema.define(version: 20170915101519) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -927,16 +927,18 @@ ActiveRecord::Schema.define(version: 20170914102634) do add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree create_table "tags", force: :cascade do |t| - t.string "name", limit: 40 - t.integer "taggings_count", default: 0 - t.integer "debates_count", default: 0 - t.integer "proposals_count", default: 0 - t.integer "spending_proposals_count", default: 0 + t.string "name", limit: 40 + t.integer "taggings_count", default: 0 + t.integer "debates_count", default: 0 + t.integer "proposals_count", default: 0 + t.integer "spending_proposals_count", default: 0 t.string "kind" - t.integer "budget/investments_count", default: 0 + t.integer "budget/investments_count", default: 0 + t.integer "legislation/proposals_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree + add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree From c1672bdbf415c9ec4e94793b9eb6ee46dc945c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 19 Sep 2017 10:10:10 +0200 Subject: [PATCH 14/46] Legislation proposals adaptation in some models and initializers --- app/models/legislation/proposal.rb | 4 ++-- app/models/user.rb | 6 ++++++ app/models/vote.rb | 6 ++++-- config/initializers/acts_as_taggable_on.rb | 5 +++-- config/initializers/vote_extensions.rb | 4 ++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 1eb82e70a..5f6706339 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -156,11 +156,11 @@ class Legislation::Proposal < ActiveRecord::Base end def after_hide - tags.each{ |t| t.decrement_custom_counter_for('Proposal') } + tags.each{ |t| t.decrement_custom_counter_for('LegislationProposal') } end def after_restore - tags.each{ |t| t.increment_custom_counter_for('Proposal') } + tags.each{ |t| t.increment_custom_counter_for('LegislationProposal') } end def self.votes_needed_for_success diff --git a/app/models/user.rb b/app/models/user.rb index ef6ab7832..b34897688 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -97,6 +97,12 @@ class User < ActiveRecord::Base voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } end + def legislation_proposal_votes(proposals) + voted = votes.for_proposals(proposals) + voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } + end + + def spending_proposal_votes(spending_proposals) voted = votes.for_spending_proposals(spending_proposals) voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } diff --git a/app/models/vote.rb b/app/models/vote.rb index 14b11a68d..4d4d07be0 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -5,10 +5,12 @@ class Vote < ActsAsVotable::Vote scope :public_for_api, -> do where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or (votes.votable_type = 'Proposal' and votes.votable_id in (?)) or - (votes.votable_type = 'Comment' and votes.votable_id in (?))}, + (votes.votable_type = 'Comment' and votes.votable_id in (?)) or + (votes.votable_type = 'LegislationProposal' and votes.votable_id in (?))}, Debate.public_for_api.pluck(:id), Proposal.public_for_api.pluck(:id), - Comment.public_for_api.pluck(:id)) + Comment.public_for_api.pluck(:id), + Legislation::Proposal.public_for_api.pluck(:id)) end end diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 57766c8c9..9db832bef 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -8,10 +8,11 @@ module ActsAsTaggableOn scope :public_for_api, -> do where(%{taggings.tag_id in (?) and (taggings.taggable_type = 'Debate' and taggings.taggable_id in (?)) or - (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?))}, + (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?)) or taggings.taggable_type = 'LegislationProposal' and taggings.taggable_id in (?))}, Tag.where('kind IS NULL or kind = ?', 'category').pluck(:id), Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id)) + Proposal.public_for_api.pluck(:id), + Legislation::Proposal.public_for_api.pluck(:id)) end def touch_taggable diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 06d3dde5b..1b6ae7252 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -13,6 +13,10 @@ ActsAsVotable::Vote.class_eval do where(votable_type: 'SpendingProposal', votable_id: spending_proposals) end + def self.for_spending_proposals(spending_proposals) + where(votable_type: 'LegislationProposal', votable_id: legislation_proposals) + end + def self.for_budget_investments(budget_investments) where(votable_type: 'Budget::Investment', votable_id: budget_investments) end From 38ba5e159bbce7e8bf4a0823daa96e32c724ab1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 20 Sep 2017 17:45:17 +0200 Subject: [PATCH 15/46] Legislation proposals show and edit views available --- app/controllers/application_controller.rb | 4 ---- app/controllers/legislation/base_controller.rb | 4 ++++ app/controllers/legislation/processes_controller.rb | 1 + app/controllers/legislation/proposals_controller.rb | 11 ++++++----- app/views/legislation/proposals/_proposal.html.erb | 4 ++-- app/views/legislation/proposals/_votes.html.erb | 4 ++-- app/views/legislation/proposals/edit.html.erb | 4 ++-- app/views/legislation/proposals/share.html.erb | 2 +- app/views/legislation/proposals/show.html.erb | 6 +++--- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 318777314..495a25314 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -76,10 +76,6 @@ class ApplicationController < ActionController::Base @proposal_votes = current_user ? current_user.proposal_votes(proposals) : {} end - def set_legislation_proposal_votes(proposals) - @proposal_votes = current_user ? current_user.legislation_proposal_votes(proposals) : {} - end - def set_spending_proposal_votes(spending_proposals) @spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {} end diff --git a/app/controllers/legislation/base_controller.rb b/app/controllers/legislation/base_controller.rb index ca609ecba..c08ffc444 100644 --- a/app/controllers/legislation/base_controller.rb +++ b/app/controllers/legislation/base_controller.rb @@ -2,4 +2,8 @@ class Legislation::BaseController < ApplicationController include FeatureFlags feature_flag :legislation + + def set_legislation_proposal_votes(proposals) + @legislation_proposal_votes = current_user ? current_user.legislation_proposal_votes(proposals) : {} + end end diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 6c12cea5b..d788d3bf3 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -88,6 +88,7 @@ class Legislation::ProcessesController < Legislation::BaseController @phase = :proposals_phase if @process.proposals_phase.started? + set_legislation_proposal_votes(@process.proposals) render :proposals else render :phase_not_open diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index 1eab07047..c65315ddf 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -20,6 +20,7 @@ class Legislation::ProposalsController < Legislation::BaseController def show super + set_legislation_proposal_votes(@process.proposals) @notifications = @proposal.notifications @document = Document.new(documentable: @proposal) redirect_to legislation_process_proposal_path(params[:process_id], @proposal), @@ -79,18 +80,18 @@ class Legislation::ProposalsController < Legislation::BaseController private def proposal_params - params.require(:proposal).permit(:legislation_process_id, :title, :question, :summary, :description, :external_url, :video_url, + params.require(:legislation_proposal).permit(:legislation_process_id, :title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :geozone_id, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) end def retired_params - params.require(:proposal).permit(:retired_reason, :retired_explanation) + params.require(:legislation_proposal).permit(:retired_reason, :retired_explanation) end def valid_retired_params? - @proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:proposal][:retired_reason].blank? - @proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:proposal][:retired_explanation].blank? + @proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:legislation_proposal][:retired_reason].blank? + @proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:legislation_proposal][:retired_explanation].blank? @proposal.errors.empty? end @@ -102,7 +103,7 @@ class Legislation::ProposalsController < Legislation::BaseController 'proposal' end - def set_legislation_proposal_votes(proposals) + def set_featured_proposal_votes(proposals) @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} end diff --git a/app/views/legislation/proposals/_proposal.html.erb b/app/views/legislation/proposals/_proposal.html.erb index 996be8f95..f3b603aa5 100644 --- a/app/views/legislation/proposals/_proposal.html.erb +++ b/app/views/legislation/proposals/_proposal.html.erb @@ -8,10 +8,10 @@
    <% cache [locale_and_user_status(proposal), 'index', proposal, proposal.author] do %> -

    <%= link_to proposal.title, namespaced_proposal_path(proposal) %>

    +

    <%= link_to proposal.title, legislation_process_proposal_path(proposal.legislation_process_id, proposal) %>

      - <%= link_to t("proposals.proposal.comments", count: proposal.comments_count), namespaced_proposal_path(proposal, anchor: "comments") %> + <%= link_to t("proposals.proposal.comments", count: proposal.comments_count), legislation_process_proposal_path(proposal.legislation_process_id, proposal, anchor: "comments") %>  •  <%= l proposal.created_at.to_date %> diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index fb41357af..b44c4d6cb 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -16,7 +16,7 @@

    - <% if voted_for?(@proposal_votes, proposal) %> + <% if voted_for?(@legislation_proposal_votes, proposal) %>
    <%= t("proposals.proposal.already_supported") %>
    @@ -58,7 +58,7 @@
    <% end %> - <% if voted_for?(@proposal_votes, proposal) && setting['twitter_handle'] %> + <% if voted_for?(@legislation_proposal_votes, proposal) && setting['twitter_handle'] %> diff --git a/app/views/legislation/proposals/edit.html.erb b/app/views/legislation/proposals/edit.html.erb index 6e5b14a08..6d4761524 100644 --- a/app/views/legislation/proposals/edit.html.erb +++ b/app/views/legislation/proposals/edit.html.erb @@ -4,11 +4,11 @@ <%= back_link_to %>
    - <%= link_to t("proposals.edit.show_link"), @proposal %> + <%= link_to t("proposals.edit.show_link"), legislation_process_proposal_path(@proposal.legislation_process_id, @proposal) %>

    <%= t("proposals.edit.editing") %>

    - <%= render "form", form_url: proposal_url(@proposal) %> + <%= render "form", form_url: legislation_process_proposal_url(@proposal.legislation_process_id, @proposal) %>
    diff --git a/app/views/legislation/proposals/share.html.erb b/app/views/legislation/proposals/share.html.erb index 5faa9d985..8ea0f7e98 100644 --- a/app/views/legislation/proposals/share.html.erb +++ b/app/views/legislation/proposals/share.html.erb @@ -9,7 +9,7 @@ <%= render "shared/canonical", href: proposal_url(@proposal) %> <% end %> -<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> +<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @legislation_proposal_votes] do %>
    diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index 1dc918e8e..b17464a04 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -10,7 +10,7 @@ <%= render "shared/canonical", href: proposal_url(@proposal) %> <% end %> -<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> +<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @legislation_proposal_votes] do %>
    @@ -29,7 +29,7 @@ <% end %> <% if current_user && @proposal.editable_by?(current_user) %> - <%= link_to edit_proposal_path(@proposal), class: 'edit-proposal button hollow float-right' do %> + <%= link_to edit_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal), class: 'edit-proposal button hollow float-right' do %> <%= t("proposals.show.edit_proposal_link") %> <% end %> <% end %> @@ -147,7 +147,7 @@
    <% else %> <%= render 'votes', - { proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: 'yes') } %> + { proposal: @proposal, vote_url: vote_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal, value: 'yes') } %> <% end %>
    <%= render partial: 'shared/social_share', locals: { From ba041f90c857daf5dfa55c520c96dfabd5c2e8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 16:17:11 +0200 Subject: [PATCH 16/46] Removed unnecessary parts in Legislation Proposals --- .../legislation/proposals_controller.rb | 57 +------------------ app/models/abilities/everyone.rb | 2 +- app/models/legislation/proposal.rb | 50 ---------------- app/models/user.rb | 2 +- app/models/vote.rb | 6 +- .../proposals/_filter_subnav.html.erb | 8 --- .../legislation/proposals/_proposal.html.erb | 26 +-------- .../legislation/proposals/_votes.html.erb | 12 ---- app/views/legislation/proposals/show.html.erb | 53 ++--------------- config/initializers/acts_as_taggable_on.rb | 5 +- config/initializers/vote_extensions.rb | 6 +- config/routes.rb | 4 -- 12 files changed, 17 insertions(+), 214 deletions(-) diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index c65315ddf..f924cb25f 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -12,7 +12,7 @@ class Legislation::ProposalsController < Legislation::BaseController invisible_captcha only: [:create, :update], honeypot: :subtitle - has_orders %w{hot_score confidence_score created_at relevance archival_date}, only: :index + has_orders %w{confidence_score created_at}, only: :index has_orders %w{most_voted newest oldest}, only: :show helper_method :resource_model, :resource_name @@ -21,7 +21,6 @@ class Legislation::ProposalsController < Legislation::BaseController def show super set_legislation_proposal_votes(@process.proposals) - @notifications = @proposal.notifications @document = Document.new(documentable: @proposal) redirect_to legislation_process_proposal_path(params[:process_id], @proposal), status: :moved_permanently if request.path != legislation_process_proposal_path(params[:process_id], @proposal) @@ -39,8 +38,6 @@ class Legislation::ProposalsController < Legislation::BaseController end def index_customization - discard_archived - load_retired load_successful_proposals load_featured unless @proposal_successful_exists end @@ -50,28 +47,12 @@ class Legislation::ProposalsController < Legislation::BaseController set_legislation_proposal_votes(@proposal) end - def retire - if valid_retired_params? && @proposal.update(retired_params.merge(retired_at: Time.current)) - redirect_to proposal_path(@proposal), notice: t('proposals.notice.retired') - else - render action: :retire_form - end - end - - def retire_form - end - def share if Setting['proposal_improvement_path'].present? @proposal_improvement_path = Setting['proposal_improvement_path'] end end - def vote_featured - @proposal.register_vote(current_user, 'yes') - set_featured_proposal_votes(@proposal) - end - def summary @proposals = Legislation::Proposal.for_summary @tag_cloud = tag_cloud @@ -85,16 +66,6 @@ class Legislation::ProposalsController < Legislation::BaseController documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) end - def retired_params - params.require(:legislation_proposal).permit(:retired_reason, :retired_explanation) - end - - def valid_retired_params? - @proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:legislation_proposal][:retired_reason].blank? - @proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:legislation_proposal][:retired_explanation].blank? - @proposal.errors.empty? - end - def resource_model Legislation::Proposal end @@ -103,32 +74,6 @@ class Legislation::ProposalsController < Legislation::BaseController 'proposal' end - def set_featured_proposal_votes(proposals) - @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} - end - - def discard_archived - @resources = @resources.not_archived unless @current_order == "archival_date" - end - - def load_retired - if params[:retired].present? - @resources = @resources.retired - @resources = @resources.where(retired_reason: params[:retired]) if Legislation::Proposal::RETIRE_OPTIONS.include?(params[:retired]) - else - @resources = @resources.not_retired - end - end - - def load_featured - return unless !@advanced_search_terms && @search_terms.blank? && @tag_filter.blank? && params[:retired].blank? - @featured_proposals = Legislation::Proposal.not_archived.sort_by_confidence_score.limit(3) - if @featured_proposals.present? - set_featured_proposal_votes(@featured_proposals) - @resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id)) - end - end - def load_successful_proposals @proposal_successful_exists = Legislation::Proposal.successful.exists? end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index d0cef4846..e16a53cec 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -22,7 +22,7 @@ module Abilities can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer - can [:read, :map, :summary, :share], Legislation::Proposal + can [:read, :map, :share], Legislation::Proposal can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation end end diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 5f6706339..d1339cabc 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -7,8 +7,6 @@ class Legislation::Proposal < ActiveRecord::Base include Sanitizable include Searchable include Filterable - include HasPublicAuthor - include Graphqlable include Followable include Communitable include Documentable @@ -21,13 +19,10 @@ class Legislation::Proposal < ActiveRecord::Base acts_as_votable acts_as_paranoid column: :hidden_at - RETIRE_OPTIONS = %w(duplicated started unfeasible done other) - belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone has_many :comments, as: :commentable - has_many :proposal_notifications validates :title, presence: true validates :question, presence: true @@ -39,7 +34,6 @@ class Legislation::Proposal < ActiveRecord::Base validates :description, length: { maximum: Legislation::Proposal.description_max_length } validates :question, length: { in: 10..Legislation::Proposal.question_max_length } validates :responsible_name, length: { in: 6..Legislation::Proposal.responsible_name_max_length } - validates :retired_reason, inclusion: {in: RETIRE_OPTIONS, allow_nil: true} validates :terms_of_service, acceptance: { allow_nil: false }, on: :create @@ -53,16 +47,8 @@ class Legislation::Proposal < ActiveRecord::Base scope :sort_by_created_at, -> { reorder(created_at: :desc) } scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } scope :sort_by_random, -> { reorder("RANDOM()") } - scope :sort_by_relevance, -> { all } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } - scope :sort_by_archival_date, -> { archived.sort_by_confidence_score } - scope :archived, -> { where("proposals.created_at <= ?", Setting["months_to_archive_proposals"].to_i.months.ago) } - scope :not_archived, -> { where("proposals.created_at > ?", Setting["months_to_archive_proposals"].to_i.months.ago) } scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} - scope :retired, -> { where.not(retired_at: nil) } - scope :not_retired, -> { where(retired_at: nil) } - scope :successful, -> { where("cached_votes_up >= ?", Legislation::Proposal.votes_needed_for_success) } - scope :public_for_api, -> { all } def to_param "#{id}-#{title}".parameterize @@ -94,18 +80,6 @@ class Legislation::Proposal < ActiveRecord::Base /\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms) end - def self.for_summary - summary = {} - categories = ActsAsTaggableOn::Tag.category_names.sort - geozones = Geozone.names.sort - - groups = categories + geozones - groups.each do |group| - summary[group] = search(group).last_week.sort_by_confidence_score.limit(3) - end - summary - end - def total_votes cached_votes_up end @@ -126,10 +100,6 @@ class Legislation::Proposal < ActiveRecord::Base user && user.level_two_or_three_verified? end - def retired? - retired_at.present? - end - def register_vote(user, vote_value) if votable_by?(user) && !archived? vote_by(voter: user, vote: vote_value) @@ -163,26 +133,6 @@ class Legislation::Proposal < ActiveRecord::Base tags.each{ |t| t.increment_custom_counter_for('LegislationProposal') } end - def self.votes_needed_for_success - Setting['votes_for_proposal_success'].to_i - end - - def successful? - total_votes >= Legislation::Proposal.votes_needed_for_success - end - - def archived? - created_at <= Setting["months_to_archive_proposals"].to_i.months.ago - end - - def notifications - proposal_notifications - end - - def users_to_notify - (voters + followers).uniq - end - protected def set_responsible_name diff --git a/app/models/user.rb b/app/models/user.rb index b34897688..36ac7d153 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -98,7 +98,7 @@ class User < ActiveRecord::Base end def legislation_proposal_votes(proposals) - voted = votes.for_proposals(proposals) + voted = votes.for_legislation_proposals(proposals) voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } end diff --git a/app/models/vote.rb b/app/models/vote.rb index 4d4d07be0..14b11a68d 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -5,12 +5,10 @@ class Vote < ActsAsVotable::Vote scope :public_for_api, -> do where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or (votes.votable_type = 'Proposal' and votes.votable_id in (?)) or - (votes.votable_type = 'Comment' and votes.votable_id in (?)) or - (votes.votable_type = 'LegislationProposal' and votes.votable_id in (?))}, + (votes.votable_type = 'Comment' and votes.votable_id in (?))}, Debate.public_for_api.pluck(:id), Proposal.public_for_api.pluck(:id), - Comment.public_for_api.pluck(:id), - Legislation::Proposal.public_for_api.pluck(:id)) + Comment.public_for_api.pluck(:id)) end end diff --git a/app/views/legislation/proposals/_filter_subnav.html.erb b/app/views/legislation/proposals/_filter_subnav.html.erb index fece62a17..986af6463 100644 --- a/app/views/legislation/proposals/_filter_subnav.html.erb +++ b/app/views/legislation/proposals/_filter_subnav.html.erb @@ -9,14 +9,6 @@ <% end %> -
  • - <%= link_to "#tab-notifications" do %> -

    - <%= t("proposals.show.notifications_tab") %> - (<%= @notifications.count %>) -

    - <% end %> -
  • <%= link_to "#tab-documents" do %>

    diff --git a/app/views/legislation/proposals/_proposal.html.erb b/app/views/legislation/proposals/_proposal.html.erb index f3b603aa5..92becc805 100644 --- a/app/views/legislation/proposals/_proposal.html.erb +++ b/app/views/legislation/proposals/_proposal.html.erb @@ -51,30 +51,8 @@

  • - <% if proposal.successful? %> -
    - -

    - <%= t("proposals.proposal.successful", - voting: link_to(t("proposals.proposal.voting"), polls_path)).html_safe %> -

    -
    - <% if can? :create, Poll::Question %> -

    - <%= link_to t('poll_questions.create_question'), - new_admin_question_path(proposal_id: proposal.id), - class: "button hollow" %> -

    - <% end %> - <% elsif proposal.archived? %> -
    - <%= t("proposals.proposal.supports", count: proposal.total_votes) %> -

    <%= t("proposals.proposal.archived") %>

    -
    - <% else %> - <%= render 'legislation/proposals/votes', - { proposal: proposal, vote_url: vote_legislation_process_proposal_path(proposal.legislation_process_id, proposal, value: 'yes') } %> - <% end %> + <%= render 'legislation/proposals/votes', + { proposal: proposal, vote_url: vote_legislation_process_proposal_path(proposal.legislation_process_id, proposal, value: 'yes') } %>
    diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index b44c4d6cb..b294acf45 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -1,18 +1,6 @@
    -
    - - - <%= supports_percentage(proposal) %> / <%= t("proposals.proposal.total_percent") %> - -
    - <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  - - "> - <%= t("proposals.proposal.supports_necessary", number: number_with_delimiter(Proposal.votes_needed_for_success)) %> - -
    diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index b17464a04..f3692e3c7 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -22,12 +22,6 @@ class: 'button hollow float-right' %> <% end %> - <% if author_of?(@proposal, current_user) %> - <%= link_to t("proposals.show.send_notification"), - new_proposal_notification_path(proposal_id: @proposal.id), - class: 'button hollow float-right' %> - <% end %> - <% if current_user && @proposal.editable_by?(current_user) %> <%= link_to edit_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal), class: 'edit-proposal button hollow float-right' do %> <%= t("proposals.show.edit_proposal_link") %> @@ -35,14 +29,7 @@ <% end %>

    <%= @proposal.title %>

    - <% if @proposal.retired? %> -
    - - <%= t("proposals.show.retired_warning") %>
    - <%= link_to t("proposals.show.retired_warning_link_to_explanation"), "#retired_explanation" %> -
    -
    - <% elsif @proposal.conflictive? %> + <% if @proposal.conflictive? %>
    <%= t("proposals.show.flag") %>
    @@ -105,13 +92,6 @@

    <%= @proposal.question %>

    - <% if @proposal.retired? %> -
    -

    <%= t('proposals.show.retired') %>: <%= t("proposals.retire_options.#{@proposal.retired_reason}") unless @proposal.retired_reason == 'other' %>

    - <%= simple_format text_with_links(@proposal.retired_explanation), {}, sanitize: false %> -
    - <% end %> - <%= render 'shared/tags', taggable: @proposal %> <%= render 'shared/geozone', geozonable: @proposal %> @@ -125,30 +105,8 @@

    <%= t("votes.supports") %>

    - - <% if @proposal.successful? %> -

    - <%= t("proposals.proposal.successful", - voting: link_to(t("proposals.proposal.voting"), polls_path)).html_safe %> -

    - <% if can? :create, Poll::Question %> -

    - <%= link_to t('poll_questions.create_question'), - new_admin_question_path(proposal_id: @proposal.id), - class: "button hollow expanded" %> -

    - <% end %> - <% elsif @proposal.archived? %> -
    -

    - <%= t("proposals.proposal.supports", count: @proposal.total_votes) %> -

    -

    <%= t("proposals.proposal.archived") %>

    -
    - <% else %> - <%= render 'votes', - { proposal: @proposal, vote_url: vote_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal, value: 'yes') } %> - <% end %> + <%= render 'votes', + { proposal: @proposal, vote_url: vote_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal, value: 'yes') } %>
    <%= render partial: 'shared/social_share', locals: { share_title: t("proposals.show.share"), @@ -168,11 +126,10 @@ <% end %>
    - <%= render "proposals/filter_subnav" %> - <%= render "proposals/notifications" %> + <%= render "legislation/proposals/filter_subnav" %>
    - <%= render "proposals/comments" %> + <%= render "legislation/proposals/comments" %>
    diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 9db832bef..57766c8c9 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -8,11 +8,10 @@ module ActsAsTaggableOn scope :public_for_api, -> do where(%{taggings.tag_id in (?) and (taggings.taggable_type = 'Debate' and taggings.taggable_id in (?)) or - (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?)) or taggings.taggable_type = 'LegislationProposal' and taggings.taggable_id in (?))}, + (taggings.taggable_type = 'Proposal' and taggings.taggable_id in (?))}, Tag.where('kind IS NULL or kind = ?', 'category').pluck(:id), Debate.public_for_api.pluck(:id), - Proposal.public_for_api.pluck(:id), - Legislation::Proposal.public_for_api.pluck(:id)) + Proposal.public_for_api.pluck(:id)) end def touch_taggable diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 1b6ae7252..effec12ea 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -9,12 +9,12 @@ ActsAsVotable::Vote.class_eval do where(votable_type: 'Proposal', votable_id: proposals) end - def self.for_spending_proposals(spending_proposals) - where(votable_type: 'SpendingProposal', votable_id: spending_proposals) + def self.for_legislation_proposals(proposals) + where(votable_type: 'Legislation::Proposal', votable_id: proposals) end def self.for_spending_proposals(spending_proposals) - where(votable_type: 'LegislationProposal', votable_id: legislation_proposals) + where(votable_type: 'SpendingProposal', votable_id: spending_proposals) end def self.for_budget_investments(budget_investments) diff --git a/config/routes.rb b/config/routes.rb index e2ccb51ed..851ff0cdf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -132,17 +132,13 @@ Rails.application.routes.draw do 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 :draft_versions, only: [:show] do From 6c1c71fcc9623ce7902e024060a123d697edaa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 16:18:08 +0200 Subject: [PATCH 17/46] Minor fixes Fixed subnavigation active links and button to create new proposal. --- app/helpers/tags_helper.rb | 2 ++ app/views/legislation/processes/proposals.html.erb | 4 +--- app/views/shared/_subnavigation.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 4cabae278..eb34a64f2 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -8,6 +8,8 @@ module TagsHelper proposals_path(search: tag_name) when 'budget/investment' budget_investments_path(@budget, search: tag_name) + when 'legislation/proposal' + legislation_process_proposals_path(@process, search: tag_name) else '#' end diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index 9e54ba46e..5883658b7 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -20,9 +20,7 @@
    -
    -

    <%= t('.participate') %>

    -
    +

    <%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %>

    diff --git a/app/views/shared/_subnavigation.html.erb b/app/views/shared/_subnavigation.html.erb index dd9809dd3..fbcdfebf3 100644 --- a/app/views/shared/_subnavigation.html.erb +++ b/app/views/shared/_subnavigation.html.erb @@ -12,7 +12,7 @@
  • <%= layout_menu_link_to t("layouts.header.proposals"), proposals_path, - controller_name == 'proposals', + controller_name == 'proposals' && !controller.class.parent == Legislation, accesskey: "2", title: t("shared.go_to_page") + t("layouts.header.proposals") %>
  • From 5ae8cda0d5079ba559cf545005e9c7d009498ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 16:23:34 +0200 Subject: [PATCH 18/46] Fixed legislation proposal vote action --- app/models/legislation/proposal.rb | 2 +- app/views/legislation/proposals/vote.js.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index d1339cabc..5ced1529d 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -101,7 +101,7 @@ class Legislation::Proposal < ActiveRecord::Base end def register_vote(user, vote_value) - if votable_by?(user) && !archived? + if votable_by?(user) vote_by(voter: user, vote: vote_value) end end diff --git a/app/views/legislation/proposals/vote.js.erb b/app/views/legislation/proposals/vote.js.erb index 4a5ca6b6b..1a0d6d4ed 100644 --- a/app/views/legislation/proposals/vote.js.erb +++ b/app/views/legislation/proposals/vote.js.erb @@ -1 +1 @@ -$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("proposals/votes", proposal: @proposal) %>'); \ No newline at end of file +$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("legislation/proposals/votes", proposal: @proposal) %>'); From 57c48fe596e041a412a0c81c1eb663b470df95a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 17:13:12 +0200 Subject: [PATCH 19/46] Legislation proposals comments working --- app/models/comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 8b68e11ad..a0cb343d7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base include HasPublicAuthor include Graphqlable - COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic).freeze + COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic Legislation::Proposal).freeze acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases From 536ee520e89d9338d4deec30cabe18768c29ebf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 17:13:22 +0200 Subject: [PATCH 20/46] Removed unnecessary views --- .../legislation/proposals/_retired.html.erb | 13 ----- .../proposals/retire_form.html.erb | 38 ------------- .../legislation/proposals/summary.html.erb | 53 ------------------- .../proposals/vote_featured.js.erb | 1 - 4 files changed, 105 deletions(-) delete mode 100644 app/views/legislation/proposals/_retired.html.erb delete mode 100644 app/views/legislation/proposals/retire_form.html.erb delete mode 100644 app/views/legislation/proposals/summary.html.erb delete mode 100644 app/views/legislation/proposals/vote_featured.js.erb diff --git a/app/views/legislation/proposals/_retired.html.erb b/app/views/legislation/proposals/_retired.html.erb deleted file mode 100644 index 2167b14af..000000000 --- a/app/views/legislation/proposals/_retired.html.erb +++ /dev/null @@ -1,13 +0,0 @@ - - - -<% if params[:retired].blank? %> -

    <%= link_to t("proposals.index.retired_proposals_link"), proposals_path(retired: 'all'), class: "small" %>

    -<% else %> - -<% end %> diff --git a/app/views/legislation/proposals/retire_form.html.erb b/app/views/legislation/proposals/retire_form.html.erb deleted file mode 100644 index d56277cb3..000000000 --- a/app/views/legislation/proposals/retire_form.html.erb +++ /dev/null @@ -1,38 +0,0 @@ -
    - -
    - -

    <%= t("proposals.retire_form.title") %>

    - -

    <%= link_to @proposal.title, @proposal %>

    - -
    - <%= t("proposals.retire_form.warning") %> -
    - - <%= form_for(@proposal, url: retire_proposal_path(@proposal)) do |f| %> - <%= render 'shared/errors', resource: @proposal %> -
    -
    - <%= f.label :retired_reason, t("proposals.retire_form.retired_reason_label") %> - <%= f.select :retired_reason, retire_proposals_options, {include_blank: t("proposals.retire_form.retired_reason_blank"), label: false} %> -
    -
    - -
    -
    - <%= f.label :retired_explanation, t("proposals.retire_form.retired_explanation_label") %> - <%= f.text_area :retired_explanation, rows: 4, maxlength: 500, label: false, - placeholder: t('proposals.retire_form.retired_explanation_placeholder') %> -
    -
    - -
    -
    - <%= f.submit(class: "button expanded", value: t("proposals.retire_form.submit_button")) %> -
    -
    - <% end %> - -
    -
    \ No newline at end of file diff --git a/app/views/legislation/proposals/summary.html.erb b/app/views/legislation/proposals/summary.html.erb deleted file mode 100644 index a28cf8750..000000000 --- a/app/views/legislation/proposals/summary.html.erb +++ /dev/null @@ -1,53 +0,0 @@ -
    -
    -
    - <%= back_link_to %> - - <% @proposals.each do |group_name, proposals| %> -
    -

    <%= group_name %>

    - - <% proposals[0..2].each do |proposal| %> -
    -
    -
    -
    -
    -

    <%= link_to proposal.title, namespaced_proposal_path(proposal) %>

    - -

    - <% if proposal.author.hidden? || proposal.author.erased? %> - <%= t("proposals.show.author_deleted") %> - <% else %> - <%= proposal.author.name %> - <% if proposal.author.display_official_position_badge? %> - - <%= proposal.author.official_position %> - - <% end %> - <% end %> -

    - -
    -

    <%= proposal.summary %>

    -
    -
    -
    -
    -
    -
    - <% end %> -
    - <% end %> -
    - -
    - -
    -
    -
    \ No newline at end of file diff --git a/app/views/legislation/proposals/vote_featured.js.erb b/app/views/legislation/proposals/vote_featured.js.erb deleted file mode 100644 index 52619282b..000000000 --- a/app/views/legislation/proposals/vote_featured.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("proposals/featured_votes", proposal: @proposal) %>'); \ No newline at end of file From f3229007e8ba0c0853ea4b03b2bc8df22fe301e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 21 Sep 2017 21:28:54 +0200 Subject: [PATCH 21/46] Run pending migrations --- db/schema.rb | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 41952607e..acacbf347 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: 20170915101519) do +ActiveRecord::Schema.define(version: 20170918231410) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -620,20 +620,6 @@ ActiveRecord::Schema.define(version: 20170915101519) do t.string "location" end - create_table "poll_final_recounts", force: :cascade do |t| - t.integer "booth_assignment_id" - t.integer "officer_assignment_id" - t.integer "count" - t.text "count_log", default: "" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "officer_assignment_id_log", default: "" - t.date "date", null: false - end - - add_index "poll_final_recounts", ["booth_assignment_id"], name: "index_poll_final_recounts_on_booth_assignment_id", using: :btree - add_index "poll_final_recounts", ["officer_assignment_id"], name: "index_poll_final_recounts_on_officer_assignment_id", using: :btree - create_table "poll_null_results", force: :cascade do |t| t.integer "author_id" t.integer "amount" @@ -725,6 +711,21 @@ ActiveRecord::Schema.define(version: 20170915101519) do add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree + create_table "poll_total_results", force: :cascade do |t| + t.integer "author_id" + t.integer "amount" + t.string "origin" + t.date "date" + t.integer "booth_assignment_id" + t.integer "officer_assignment_id" + t.text "amount_log", default: "" + t.text "officer_assignment_id_log", default: "" + t.text "author_id_log", default: "" + end + + add_index "poll_total_results", ["booth_assignment_id"], name: "index_poll_total_results_on_booth_assignment_id", using: :btree + add_index "poll_total_results", ["officer_assignment_id"], name: "index_poll_total_results_on_officer_assignment_id", using: :btree + create_table "poll_voters", force: :cascade do |t| t.string "document_number" t.string "document_type" @@ -1010,7 +1011,7 @@ ActiveRecord::Schema.define(version: 20170915101519) do t.boolean "email_digest", default: true t.boolean "email_on_direct_message", default: true t.boolean "official_position_badge", default: false - t.datetime "password_changed_at", default: '2017-09-06 18:19:39', null: false + t.datetime "password_changed_at", default: '2015-01-01 00:01:01', null: false t.boolean "created_from_signature", default: false t.integer "failed_email_digests_count", default: 0 t.text "former_users_data_log", default: "" @@ -1123,8 +1124,6 @@ ActiveRecord::Schema.define(version: 20170915101519) do add_foreign_key "organizations", "users" add_foreign_key "poll_answers", "poll_questions", column: "question_id" add_foreign_key "poll_booth_assignments", "polls" - add_foreign_key "poll_final_recounts", "poll_booth_assignments", column: "booth_assignment_id" - add_foreign_key "poll_final_recounts", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_null_results", "poll_booth_assignments", column: "booth_assignment_id" add_foreign_key "poll_null_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_officer_assignments", "poll_booth_assignments", column: "booth_assignment_id" From ebfa3fb011b200b89a902160f70bbfbc8c4e7a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 11:39:17 +0200 Subject: [PATCH 22/46] Disallow users to edit their legislation proposals --- app/models/abilities/common.rb | 2 +- app/models/abilities/everyone.rb | 2 +- app/views/legislation/proposals/show.html.erb | 12 ------------ 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 459b779c7..2de8e4c79 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -19,7 +19,7 @@ module Abilities can [:retire_form, :retire], Proposal, author_id: user.id can :read, Legislation::Proposal - can :update, Legislation::Proposal do |proposal| + cannot [:edit, :update], Legislation::Proposal do |proposal| proposal.editable_by?(user) end can [:retire_form, :retire], Legislation::Proposal, author_id: user.id diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index e16a53cec..c97bf0d94 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -18,7 +18,7 @@ module Abilities can [:read, :print], Budget::Investment can :read_results, Budget, phase: "finished" can :new, DirectMessage - can [:read, :debate, :draft_publication, :allegations, :result_publication], Legislation::Process, published: true + can [:read, :debate, :draft_publication, :allegations, :result_publication, :proposals], Legislation::Process, published: true can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index f3692e3c7..48dae91b6 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -16,18 +16,6 @@
    <%= back_link_to %> - <% if can?(:create, @document) && @proposal.documents.size < Proposal.max_documents_allowed %> - <%= link_to t("documents.upload_document"), - new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url), - class: 'button hollow float-right' %> - <% end %> - - <% if current_user && @proposal.editable_by?(current_user) %> - <%= link_to edit_legislation_process_proposal_path(@proposal.legislation_process_id, @proposal), class: 'edit-proposal button hollow float-right' do %> - <%= t("proposals.show.edit_proposal_link") %> - <% end %> - <% end %> -

    <%= @proposal.title %>

    <% if @proposal.conflictive? %>
    From 3c4f2426db7d11d5f4cb0c72b9459dcf1f93ce6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 11:39:30 +0200 Subject: [PATCH 23/46] Removed unnecessary content --- app/controllers/legislation/proposals_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index f924cb25f..85072a419 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -53,11 +53,6 @@ class Legislation::ProposalsController < Legislation::BaseController end end - def summary - @proposals = Legislation::Proposal.for_summary - @tag_cloud = tag_cloud - end - private def proposal_params From 02fa3a83b5329a9aa82d4571b1016b38c51f95e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 17:16:04 +0200 Subject: [PATCH 24/46] Custom tags for Legislation Process available Custom tags for Legislation Processes, editable in the admin section. --- .../admin/legislation/processes_controller.rb | 10 +++++++++- app/helpers/tags_helper.rb | 2 ++ app/models/legislation/process.rb | 5 ++++- .../admin/legislation/proposals/_form.html.erb | 14 ++++++++++++++ app/views/legislation/proposals/_form.html.erb | 4 ++-- ...1247_add_legislation_processes_count_to_tags.rb | 6 ++++++ db/schema.rb | 4 +++- 7 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index f316d9b65..0e7555211 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -19,6 +19,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def update if @process.update(process_params) + set_tag_list + link = legislation_process_path(@process).html_safe redirect_to :back, notice: t('admin.legislation.processes.update.notice', link: link) else @@ -56,7 +58,13 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :draft_publication_enabled, :result_publication_enabled, :published, - :proposals_description + :proposals_description, + :custom_list ) end + + def set_tag_list + @process.set_tag_list_on(:customs, process_params[:custom_list]) + @process.save + end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index eb34a64f2..b31f3167f 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -24,6 +24,8 @@ module TagsHelper proposal_path(taggable) when 'budget/investment' budget_investment_path(taggable.budget_id, taggable) + when 'legislation/proposal' + legislation_process_proposal_path(@process, taggable) else '#' end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 7e1e884cb..d6eed62db 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -1,6 +1,9 @@ class Legislation::Process < ActiveRecord::Base - acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + include Taggable + + acts_as_paranoid column: :hidden_at + acts_as_taggable_on :customs PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase proposals_phase draft_publication result_publication).freeze diff --git a/app/views/admin/legislation/proposals/_form.html.erb b/app/views/admin/legislation/proposals/_form.html.erb index 30f7f4950..343164587 100644 --- a/app/views/admin/legislation/proposals/_form.html.erb +++ b/app/views/admin/legislation/proposals/_form.html.erb @@ -28,6 +28,20 @@
    +
    +
    + <%= label_tag t('admin.legislation.proposals.form.header_information') %> + <%= t('admin.legislation.proposals.form.header_information_description') %> +
    +
    + <%= f.text_field :custom_list, value: @process.tag_list_on(:customs).to_s, + label: false, + placeholder: t("proposals.form.tags_placeholder"), + class: 'js-tag-list', + aria: {describedby: "tag-list-help-text"} %> +
    +
    +
    <%= f.submit(class: "button expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %> diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index dec8e56d2..798266ba1 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -63,8 +63,8 @@
    <%= f.label :category_tag_list, t("proposals.form.tag_category_label") %> - <% @categories.each do |tag| %> - <%= tag.name %> + <% @process.tag_list_on(:customs).each do |tag| %> + <%= tag %> <% end %>
    diff --git a/db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb b/db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb new file mode 100644 index 000000000..698a66af6 --- /dev/null +++ b/db/migrate/20170922101247_add_legislation_processes_count_to_tags.rb @@ -0,0 +1,6 @@ +class AddLegislationProcessesCountToTags < ActiveRecord::Migration + def change + add_column :tags, "legislation/processes_count", :integer, default: 0 + add_index :tags, "legislation/processes_count" + end +end diff --git a/db/schema.rb b/db/schema.rb index acacbf347..df544e28a 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: 20170918231410) do +ActiveRecord::Schema.define(version: 20170922101247) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -936,9 +936,11 @@ ActiveRecord::Schema.define(version: 20170918231410) do t.string "kind" t.integer "budget/investments_count", default: 0 t.integer "legislation/proposals_count", default: 0 + t.integer "legislation/processes_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree + add_index "tags", ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count", using: :btree add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree From a870f35de8d9f2c98e55e2599896639c9bd35a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 17:21:55 +0200 Subject: [PATCH 25/46] Added translations --- app/views/admin/legislation/proposals/_form.html.erb | 4 ++-- config/locales/en/admin.yml | 2 ++ config/locales/es/admin.yml | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/admin/legislation/proposals/_form.html.erb b/app/views/admin/legislation/proposals/_form.html.erb index 343164587..dd12f9492 100644 --- a/app/views/admin/legislation/proposals/_form.html.erb +++ b/app/views/admin/legislation/proposals/_form.html.erb @@ -30,8 +30,8 @@
    - <%= label_tag t('admin.legislation.proposals.form.header_information') %> - <%= t('admin.legislation.proposals.form.header_information_description') %> + <%= label_tag t('admin.legislation.proposals.form.custom_categories') %> + <%= t('admin.legislation.proposals.form.custom_categories_description') %>
    <%= f.text_field :custom_list, value: @process.tag_list_on(:customs).to_s, diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0953be816..42d18219d 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -300,6 +300,8 @@ en: header_information: Information header header_information_description: Provide information about the proposals. This text will be displayed as an alert in the Proposals section inside this Process. Use Markdown to format the text. header_information_placeholder: Add information for the proposals' header + custom_categories: Categories + custom_categories_description: Categories that users can select creating the proposal. draft_versions: create: notice: 'Draft created successfully. Click to visit' diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 679e41b6c..548cbc98b 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -300,6 +300,8 @@ es: header_information: Encabezado de información header_information_description: Proporciona información sobre el recorrido de las propuestas. Este texto se mostrará como una alerta en el encabezado de la sección de Propuestas dentro de este proceso. Usa Markdown para formatear el texto. header_information_placeholder: Añade información para el encabezado de las las propuestas + custom_categories: Categorías + custom_categories_description: Categorías que el usuario puede seleccionar al crear la propuesta. draft_versions: create: notice: 'Borrador creado correctamente. Haz click para verlo' From 2629837306fdfb97a6244e55a5cdad373fe8ff62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 22 Sep 2017 17:25:33 +0200 Subject: [PATCH 26/46] Fixed admin menu active states --- app/helpers/admin_helper.rb | 4 ++-- app/views/admin/_menu.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index f9c2e8c69..06fb158a4 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -17,7 +17,7 @@ module AdminHelper end def menu_moderated_content? - ["proposals", "debates", "comments", "hidden_users"].include? controller_name + ["proposals", "debates", "comments", "hidden_users"].include? controller_name && controller.class.parent != Admin::Legislation end def menu_budget? @@ -39,7 +39,7 @@ module AdminHelper def menu_customization? ["pages", "images", "content_blocks"].include? controller_name end - + def official_level_options options = [["", 0]] (1..5).each do |i| diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 11d58adc8..168f8c31b 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -19,7 +19,7 @@ <%= t("admin.menu.title_moderated_content") %>
      > -
    • > +
    • > <%= link_to t("admin.menu.hidden_proposals"), admin_proposals_path %>
    • From 231a14c428bbf8983f157e8593f3238b91238978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 25 Oct 2017 12:52:59 +0200 Subject: [PATCH 27/46] Fixed broken tests --- app/controllers/legislation/proposals_controller.rb | 1 - app/views/legislation/processes/_key_dates.html.erb | 10 +++++----- app/views/legislation/proposals/_form.html.erb | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index 85072a419..d762bb99c 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -28,7 +28,6 @@ class Legislation::ProposalsController < Legislation::BaseController def create @proposal = Legislation::Proposal.new(proposal_params.merge(author: current_user)) - recover_documents_from_cache(@proposal) if @proposal.save redirect_to share_legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t('flash.actions.create.proposal') diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index 0bc95bef5..bf8961d86 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -6,7 +6,7 @@
        <% if process.debate_phase.enabled? %> -
      • > +
      • > <%= link_to debate_legislation_process_path(process) do %>

        <%= t('legislation.processes.shared.debate_dates') %>

        <%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>

        @@ -15,7 +15,7 @@ <% end %> <% if process.proposals_phase.enabled? %> -
      • > +
      • > <%= link_to proposals_legislation_process_path(process) do %>

        <%= t('legislation.processes.shared.proposals_dates') %>

        <%= format_date(process.proposals_phase_start_date) %> - <%= format_date(process.proposals_phase_end_date) %>

        @@ -24,7 +24,7 @@ <% end %> <% if process.draft_publication.enabled? %> -
      • > +
      • > <%= link_to draft_publication_legislation_process_path(process) do %>

        <%= t('legislation.processes.shared.draft_publication_date') %>

        <%= format_date(process.draft_publication_date) %>

        @@ -33,7 +33,7 @@ <% end %> <% if process.allegations_phase.enabled? %> -
      • > +
      • > <%= link_to allegations_legislation_process_path(process) do %>

        <%= t('legislation.processes.shared.allegations_dates') %>

        <%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>

        @@ -42,7 +42,7 @@ <% end %> <% if process.result_publication.enabled? %> -
      • > +
      • > <%= link_to result_publication_legislation_process_path(process) do %>

        <%= t('legislation.processes.shared.result_publication_date') %>

        <%= format_date(process.result_publication_date) %>

        diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 798266ba1..4efbeb4e2 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -49,7 +49,7 @@
    - <%= render 'documents/nested_documents', documentable: @proposal %> + <%= render 'documents/nested_documents', documentable: @proposal, f: f %>
    From b5f2f9aa214256bb1ef0f64fb38bd9b65395fd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 25 Oct 2017 16:42:24 +0200 Subject: [PATCH 28/46] Added `cached_votes_total` and `cached_votes_down` to Legislation Proposals --- app/models/legislation/proposal.rb | 10 +++++++++- ...142440_add_cached_votes_to_legislation_proposals.rb | 6 ++++++ db/schema.rb | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20171025142440_add_cached_votes_to_legislation_proposals.rb diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 5ced1529d..32badbb46 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -80,10 +80,18 @@ class Legislation::Proposal < ActiveRecord::Base /\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms) end - def total_votes + def likes cached_votes_up end + def dislikes + cached_votes_down + end + + def total_votes + cached_votes_total + end + def voters User.active.where(id: votes_for.voters) end diff --git a/db/migrate/20171025142440_add_cached_votes_to_legislation_proposals.rb b/db/migrate/20171025142440_add_cached_votes_to_legislation_proposals.rb new file mode 100644 index 000000000..92544ddb6 --- /dev/null +++ b/db/migrate/20171025142440_add_cached_votes_to_legislation_proposals.rb @@ -0,0 +1,6 @@ +class AddCachedVotesToLegislationProposals < ActiveRecord::Migration + def change + add_column :legislation_proposals, :cached_votes_total, :integer, default: 0 + add_column :legislation_proposals, :cached_votes_down, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index f8dd19c13..05faf6f36 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: 20171020163240) do +ActiveRecord::Schema.define(version: 20171025142440) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -528,6 +528,8 @@ ActiveRecord::Schema.define(version: 20171020163240) do t.integer "community_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "cached_votes_total", default: 0 + t.integer "cached_votes_down", default: 0 end add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree From 276baedcfaf2ae7c6627562b3584ca2ad09e08b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 25 Oct 2017 16:42:55 +0200 Subject: [PATCH 29/46] Added votes to Legislation Proposals --- .../legislation/proposals_controller.rb | 2 +- .../legislation/proposals/_votes.html.erb | 70 ++++++++++++------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index d762bb99c..fa35ea171 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -42,7 +42,7 @@ class Legislation::ProposalsController < Legislation::BaseController end def vote - @proposal.register_vote(current_user, 'yes') + @proposal.register_vote(current_user, params[:value]) set_legislation_proposal_votes(@proposal) end diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index b294acf45..cfc80aa1b 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -1,40 +1,60 @@ -
    - - <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  - - -
    - <% if voted_for?(@legislation_proposal_votes, proposal) %> -
    - <%= t("proposals.proposal.already_supported") %> -
    - <% elsif user_signed_in? && proposal.votable_by?(current_user) %> - <%= link_to vote_url, - class: "button button-support small expanded", - title: t('proposals.proposal.support_title'), method: "post", remote: true do %> - <%= t("proposals.proposal.support") %> +<% voted_classes = css_classes_for_vote(@legislation_proposal_votes, proposal) %> +
    +
    + <% if user_signed_in? %> + <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: 'yes'), + class: "like #{voted_classes[:in_favor]}", title: t('votes.agree'), method: "post", remote: true do %> + + <%= t('votes.agree') %> + + <%= votes_percentage('likes', proposal) %> <% end %> <% else %> -
    - <%= t("proposals.proposal.support") %> + <% end %>
    + + +
    + <% if user_signed_in? %> + <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: 'no'), class: "unlike #{voted_classes[:against]}", title: t('votes.disagree'), method: "post", remote: true do %> + + <%= t('votes.disagree') %> + + <%= votes_percentage('dislikes', proposal) %> + <% end %> + <% else %> +
    + + <%= t('votes.disagree') %> + + <%= votes_percentage('dislikes', proposal) %> +
    + <% end %> +
    + + + <%= t("proposals.proposal.votes", count: proposal.total_votes) %> + + <% if user_signed_in? && current_user.organization? %> - <% elsif user_signed_in? && !proposal.votable_by?(current_user) %> -
    - + <% elsif user_signed_in? && !proposal.votable_by?(current_user)%> + <% elsif !user_signed_in? %>
    From 1b4756e073271862de30269c001a239b27ff4adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 25 Oct 2017 16:43:16 +0200 Subject: [PATCH 30/46] Front improvements and new translations --- app/assets/stylesheets/participation.scss | 5 ++++- app/views/legislation/processes/proposals.html.erb | 2 +- app/views/legislation/proposals/_featured_proposal.html.erb | 2 +- app/views/legislation/proposals/_proposal.html.erb | 2 +- config/locales/en/general.yml | 4 ++++ config/locales/es/general.yml | 4 ++++ 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 81757d78c..40d546999 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -855,7 +855,9 @@ } .debate, -.debate-show { +.debate-show, +.proposal-show, +.legislation-proposals { .votes { @include votes; @@ -870,6 +872,7 @@ } } +.proposal-show .votes, .debate-show .votes { border: 0; padding: $line-height / 2 0; diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index 5883658b7..c1b0abfaf 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -8,7 +8,7 @@
    -
    +
    <% if @process.proposals.empty? %>

    <%= t('.empty_questions') %>

    diff --git a/app/views/legislation/proposals/_featured_proposal.html.erb b/app/views/legislation/proposals/_featured_proposal.html.erb index 5500b2418..63a0e6c2c 100644 --- a/app/views/legislation/proposals/_featured_proposal.html.erb +++ b/app/views/legislation/proposals/_featured_proposal.html.erb @@ -17,7 +17,7 @@  •  <% end %> - <%= t("proposals.proposal.supports", count: proposal.total_votes) %> + <%= t("proposals.proposal.votes", count: proposal.total_votes) %>
    diff --git a/app/views/legislation/proposals/_proposal.html.erb b/app/views/legislation/proposals/_proposal.html.erb index 92becc805..0916f0de5 100644 --- a/app/views/legislation/proposals/_proposal.html.erb +++ b/app/views/legislation/proposals/_proposal.html.erb @@ -50,7 +50,7 @@
    -
    +
    <%= render 'legislation/proposals/votes', { proposal: proposal, vote_url: vote_legislation_process_proposal_path(proposal.legislation_process_id, proposal, value: 'yes') } %>
    diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 926410b51..107aaecaa 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -421,6 +421,10 @@ en: one: 1 support other: "%{count} supports" zero: No supports + votes: + one: 1 vote + other: "%{count} votes" + zero: No votes supports_necessary: "%{number} supports needed" total_percent: 100% archived: "This proposal has been archived and can't collect supports." diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index f82ba9ed7..ca88d8c1d 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -421,6 +421,10 @@ es: one: 1 apoyo other: "%{count} apoyos" zero: Sin apoyos + votes: + one: 1 voto + other: "%{count} votos" + zero: Sin votos supports_necessary: "%{number} apoyos necesarios" total_percent: 100% archived: "Esta propuesta ha sido archivada y ya no puede recoger apoyos." From b556617a80108c1aa119a1703158261b74df55a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 25 Oct 2017 16:43:25 +0200 Subject: [PATCH 31/46] Changed permissions to vote Legislation Proposals and Answers --- app/models/abilities/common.rb | 1 + app/models/abilities/everyone.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 310cc743e..8f289f986 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -67,6 +67,7 @@ module Abilities can :vote, Legislation::Proposal can :vote_featured, Legislation::Proposal + can :create, Legislation::Answer can :create, Budget::Investment, budget: { phase: "accepting" } can :suggest, Budget::Investment, budget: { phase: "accepting" } diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 258e030bd..a3720803e 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -27,7 +27,6 @@ module Abilities can [:read, :debate, :draft_publication, :allegations, :result_publication, :proposals], Legislation::Process, published: true can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question - can [:create], Legislation::Answer can [:read, :map, :share], Legislation::Proposal can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation end From 2d95069a7b4b211e96d621541a8330b625c6c05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 25 Oct 2017 17:55:55 +0200 Subject: [PATCH 32/46] Missing translations --- app/views/legislation/processes/proposals.html.erb | 2 +- config/locales/en/legislation.yml | 3 +++ config/locales/es/legislation.yml | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index c1b0abfaf..102766755 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -11,7 +11,7 @@
    <% if @process.proposals.empty? %>
    -

    <%= t('.empty_questions') %>

    +

    <%= t('.empty_proposals') %>

    <% else %> <%= render @process.proposals %> diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index 37f9c02aa..8afaf4de3 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -49,6 +49,8 @@ en: processes: header: view_process_information: View process information + proposals: + empty_proposals: There are no proposals debate: empty_questions: There aren't any questions participate: Participate in the debate @@ -86,6 +88,7 @@ en: draft_publication_date: Draft publication allegations_dates: Allegations result_publication_date: Final result publication + proposals_dates: Proposals questions: comments: comment_button: Publish answer diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index 32617e808..5c04d2fa5 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -49,6 +49,8 @@ es: processes: header: view_process_information: Ver información del proceso + proposals: + empty_proposals: No hay propuestas debate: empty_questions: No hay preguntas participate: Realiza tus aportaciones al debate previo participando en los siguientes temas. From f15ef5b66b686fd2493d33467225b50c92000564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 26 Oct 2017 16:56:30 +0200 Subject: [PATCH 33/46] Removed Legislation Proposals suggestions in form --- app/views/legislation/proposals/_form.html.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 4efbeb4e2..2cf43c3b9 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -6,9 +6,8 @@
    <%= f.label :title, t("proposals.form.proposal_title") %> - <%= f.text_field :title, maxlength: Legislation::Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_proposals_path}%> + <%= f.text_field :title, maxlength: Legislation::Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false %>
    -
    <%= f.invisible_captcha :subtitle %> From 73d6a0924278cf739ee0acd8d0c158dc25ecd00a Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 17:09:57 +0200 Subject: [PATCH 34/46] removes duplicated label on legislation proposal form --- app/views/legislation/proposals/_form.html.erb | 3 +-- config/locales/en/legislation.yml | 3 +++ config/locales/es/legislation.yml | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 4efbeb4e2..c9fac3a9b 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -58,11 +58,10 @@
    - <%= f.label :tag_list, t("proposals.form.tags_label") %> + <%= f.label :tag_list, t("legislation.proposals.form.tags_label") %>

    <%= t("proposals.form.tags_instructions") %>

    - <%= f.label :category_tag_list, t("proposals.form.tag_category_label") %> <% @process.tag_list_on(:customs).each do |tag| %> <%= tag %> <% end %> diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index 8afaf4de3..6d130e1c2 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -120,3 +120,6 @@ en: shared: share: Share share_comment: Comment on %{version_name} from process draft %{process_name} + proposals: + form: + tags_label: "Categories" \ No newline at end of file diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index 5c04d2fa5..fe5804e91 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -120,3 +120,6 @@ es: shared: share: Compartir share_comment: Comentario sobre la %{version_name} del borrador del proceso %{process_name} + proposals: + form: + tags_label: "Categorías" \ No newline at end of file From 658d115c91e592537bf5e7746e3cca04e0677cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 26 Oct 2017 17:13:04 +0200 Subject: [PATCH 35/46] Removed share view for Legislation Proposals --- .../legislation/proposals_controller.rb | 8 +-- .../legislation/proposals/share.html.erb | 51 ------------------- config/routes.rb | 1 - 3 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 app/views/legislation/proposals/share.html.erb diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index fa35ea171..ee4d10c06 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -30,7 +30,7 @@ class Legislation::ProposalsController < Legislation::BaseController @proposal = Legislation::Proposal.new(proposal_params.merge(author: current_user)) if @proposal.save - redirect_to share_legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t('flash.actions.create.proposal') + redirect_to legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t('flash.actions.create.proposal') else render :new end @@ -46,12 +46,6 @@ class Legislation::ProposalsController < Legislation::BaseController set_legislation_proposal_votes(@proposal) end - def share - if Setting['proposal_improvement_path'].present? - @proposal_improvement_path = Setting['proposal_improvement_path'] - end - end - private def proposal_params diff --git a/app/views/legislation/proposals/share.html.erb b/app/views/legislation/proposals/share.html.erb deleted file mode 100644 index 8ea0f7e98..000000000 --- a/app/views/legislation/proposals/share.html.erb +++ /dev/null @@ -1,51 +0,0 @@ -<% provide :title do %><%= @proposal.title %><% end %> -<% provide :social_media_meta_tags do %> -<%= render "shared/social_media_meta_tags", - social_url: proposal_url(@proposal), - social_title: @proposal.title, - social_description: @proposal.summary %> -<% end %> -<% content_for :canonical do %> - <%= render "shared/canonical", href: proposal_url(@proposal) %> -<% end %> - -<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @legislation_proposal_votes] do %> -
    -
    -
    - -

    <%= t("proposals.proposal.created") %>

    - -

    - <%= t("proposals.proposal.share.guide") %>
    - <%= t("proposals.proposal.share.edit") %> -

    - - <%= render partial: 'shared/social_share', locals: { - title: @proposal.title, - url: proposal_url(@proposal) - } %> - - <% if @proposal_improvement_path.present? %> -
    -

    <%= t("proposals.proposal.improve_info") %>

    - <%= link_to t("proposals.proposal.improve_info_link"), @proposal_improvement_path, class: "button" %> -
    - <% end %> - -
    - <%= link_to t("proposals.proposal.share.view_proposal"), legislation_process_proposal_path(@proposal.legislation_process_id, @proposal) %> -
    -
    - -
    -
    -

    - <%= @proposal.title %>
    - <%= t("proposals.show.code") %> <%= @proposal.code %> -

    -
    -
    -
    -
    -<% end %> diff --git a/config/routes.rb b/config/routes.rb index d98ca98e2..491127439 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -139,7 +139,6 @@ Rails.application.routes.draw do post :vote put :flag put :unflag - get :share end collection do get :map From 00309aa157c8342a0e131e27cb0c272808760d70 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 17:51:10 +0200 Subject: [PATCH 36/46] changes message for not verified users --- app/views/legislation/proposals/_votes.html.erb | 4 ++-- config/locales/en/legislation.yml | 3 ++- config/locales/es/legislation.yml | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index cfc80aa1b..79e332e82 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -49,10 +49,10 @@ <%= t("votes.organizations") %>

    - <% elsif user_signed_in? && !proposal.votable_by?(current_user)%> + <% elsif user_signed_in? && !proposal.votable_by?(current_user) %> diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index 6d130e1c2..4924e1f3f 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -122,4 +122,5 @@ en: share_comment: Comment on %{version_name} from process draft %{process_name} proposals: form: - tags_label: "Categories" \ No newline at end of file + tags_label: "Categories" + not_verified: "For vote proposals %{verify_account}." \ No newline at end of file diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index fe5804e91..19038c747 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -122,4 +122,5 @@ es: share_comment: Comentario sobre la %{version_name} del borrador del proceso %{process_name} proposals: form: - tags_label: "Categorías" \ No newline at end of file + tags_label: "Categorías" + not_verified: Para votar propuestas %{verify_account}. \ No newline at end of file From dea820f3e8159431cf9d6dd66e22b8d7b031dd56 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 17:58:15 +0200 Subject: [PATCH 37/46] removes follow button on proposal show --- app/views/legislation/proposals/show.html.erb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index 48dae91b6..6a7a9286c 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -102,12 +102,7 @@ url: proposal_url(@proposal) } %> - <% if current_user %> - <%= render 'follows/follow_button', follow: find_or_build_follow(current_user, @proposal) %> - <% end %> - <%= render 'communities/access_button', community: @proposal.community %> -
    From 50b2ab5a6956e6ed333cc002153ae936ba2e6325 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 18:47:18 +0200 Subject: [PATCH 38/46] adds categories list on proposal sidebar --- app/views/legislation/processes/proposals.html.erb | 1 + app/views/legislation/proposals/_categories.html.erb | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index 102766755..a6346671e 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -21,6 +21,7 @@

    <%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %>

    + <%= render 'legislation/proposals/categories', taggable: @process %>
    diff --git a/app/views/legislation/proposals/_categories.html.erb b/app/views/legislation/proposals/_categories.html.erb index a694eb555..d0c34d23f 100644 --- a/app/views/legislation/proposals/_categories.html.erb +++ b/app/views/legislation/proposals/_categories.html.erb @@ -3,10 +3,12 @@
      - <% @categories.each do |category| %> + <% @process.tag_list_on(:customs).each do |tag| %>
    • - <% css_class = { class: 'active' } if params[:search] == category.name %> - <%= link_to category.name, proposals_path(search: category.name), css_class || {} %> + <% css_class = { class: 'active' } if params[:search] == tag %> + <%= link_to tag, + legislation_process_proposals_path(process_id: @process, search: tag), + css_class || {} %>
    • <% end %>
    From 702bfec248835bed6f5d366f8b58ce71cbf77789 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 18:47:44 +0200 Subject: [PATCH 39/46] removes unnecessary legislation proposal index view --- .../legislation/proposals/index.html.erb | 102 ------------------ 1 file changed, 102 deletions(-) delete mode 100644 app/views/legislation/proposals/index.html.erb diff --git a/app/views/legislation/proposals/index.html.erb b/app/views/legislation/proposals/index.html.erb deleted file mode 100644 index 69a8df4a3..000000000 --- a/app/views/legislation/proposals/index.html.erb +++ /dev/null @@ -1,102 +0,0 @@ -<% provide :title do %><%= t('proposals.index.title') %><% end %> -<% content_for :header_addon do %> - <%= render "shared/search_form", - search_path: proposals_path(page: 1), - i18n_namespace: "proposals.index.search_form" %> -<% end %> -<% content_for :canonical do %> - <%= render "shared/canonical", href: proposals_url %> -<% end %> - -
    - <% if @search_terms || @advanced_search_terms || @tag_filter || params[:retired].present? %> -
    -
    -
    - <% if @search_terms || @advanced_search_terms %> -

    <%= t("shared.search_results") %>

    -

    - <%= page_entries_info @proposals %> - <% if !@advanced_search_terms %> - <%= t("proposals.index.search_results_html", count: @proposals.size, search_term: @search_terms) %> - <% end %> -

    - <% elsif @tag_filter %> -

    <%= t("shared.search_results") %>

    -

    - <%= page_entries_info @proposals %> - <%= t("proposals.index.filter_topic", count: @proposals.size, topic: @tag_filter) %> -

    - <% elsif params[:retired].present? %> -

    <%= t("proposals.index.retired_proposals") %>

    - <% end %> -
    -
    -
    - <% else %> - <%= render "shared/section_header", i18n_namespace: "proposals.index.section_header", image: "proposals" %> - <% end %> - -
    -
    - - <% if has_banners? %> - <%= render "shared/banner" %> - <% end %> - - <% if @featured_proposals.present? %> - - <% end %> - - <%= render("shared/advanced_search", search_path: proposals_path(page: 1)) unless params[:retired].present? %> - - <%= render 'shared/order_links', i18n_namespace: "proposals.index" %> - - <% if @proposals.any? %> -
    - <%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button expanded' %> -
    - <% end %> - -
    - <%= render partial: 'proposals/proposal', collection: @proposals %> - <%= paginate @proposals %> - - <% unless @search_terms || @advanced_search_terms || @tag_filter %> -
    -

    - <%= t("proposals.index.section_footer.title") %> -

    -

    <%= t("proposals.index.section_footer.help_text_1") %>

    -

    <%= t("proposals.index.section_footer.help_text_2", - org: link_to(setting['org_name'], new_user_registration_path)).html_safe %>

    -

    <%= t("proposals.index.section_footer.help_text_3") %>

    -
    - <% end %> -
    -
    - -
    - -
    - -
    -
    From bb61b76790aef864fa88f2619104bf0321d2c90e Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 18:48:07 +0200 Subject: [PATCH 40/46] removes communities partial on proposals show --- app/views/legislation/proposals/show.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index 6a7a9286c..bdabe926f 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -101,8 +101,6 @@ title: @proposal.title, url: proposal_url(@proposal) } %> - - <%= render 'communities/access_button', community: @proposal.community %>
    From 4019786a26d6a06697cf5833fde97c9aa8623b68 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 19:01:03 +0200 Subject: [PATCH 41/46] hides vote buttons if process proposal phase are closed --- .../legislation/proposals/_votes.html.erb | 72 ++++++++++--------- config/locales/en/legislation.yml | 3 +- config/locales/es/legislation.yml | 3 +- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index 79e332e82..f56c0ead2 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -1,43 +1,47 @@ <% voted_classes = css_classes_for_vote(@legislation_proposal_votes, proposal) %>
    -
    - <% if user_signed_in? %> - <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: 'yes'), - class: "like #{voted_classes[:in_favor]}", title: t('votes.agree'), method: "post", remote: true do %> - - <%= t('votes.agree') %> - - <%= votes_percentage('likes', proposal) %> + <% if @process.proposals_phase.open? %> +
    + <% if user_signed_in? %> + <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: 'yes'), + class: "like #{voted_classes[:in_favor]}", title: t('votes.agree'), method: "post", remote: true do %> + + <%= t('votes.agree') %> + + <%= votes_percentage('likes', proposal) %> + <% end %> + <% else %> + <% end %> - <% else %> - - <% end %> -
    +
    - + -
    - <% if user_signed_in? %> - <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: 'no'), class: "unlike #{voted_classes[:against]}", title: t('votes.disagree'), method: "post", remote: true do %> - - <%= t('votes.disagree') %> - - <%= votes_percentage('dislikes', proposal) %> +
    + <% if user_signed_in? %> + <%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: 'no'), class: "unlike #{voted_classes[:against]}", title: t('votes.disagree'), method: "post", remote: true do %> + + <%= t('votes.disagree') %> + + <%= votes_percentage('dislikes', proposal) %> + <% end %> + <% else %> +
    + + <%= t('votes.disagree') %> + + <%= votes_percentage('dislikes', proposal) %> +
    <% end %> - <% else %> -
    - - <%= t('votes.disagree') %> - - <%= votes_percentage('dislikes', proposal) %> -
    - <% end %> -
    +
    + <% else %> +

    <%= t("legislation.proposals.closed") %>

    + <% end %> <%= t("proposals.proposal.votes", count: proposal.total_votes) %> diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index 4924e1f3f..5dd0d0196 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -123,4 +123,5 @@ en: proposals: form: tags_label: "Categories" - not_verified: "For vote proposals %{verify_account}." \ No newline at end of file + not_verified: "For vote proposals %{verify_account}." + closed: "This process has been closed and can not receive votes." \ No newline at end of file diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index 19038c747..0ded24d65 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -123,4 +123,5 @@ es: proposals: form: tags_label: "Categorías" - not_verified: Para votar propuestas %{verify_account}. \ No newline at end of file + not_verified: Para votar propuestas %{verify_account}. + closed: "Este proceso se ha cerrado y ya no puede recoger votos." \ No newline at end of file From f068eef6ce7644768caa7d9c63086075bf296a78 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 19:01:18 +0200 Subject: [PATCH 42/46] changes back link on proposal show --- app/views/legislation/proposals/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index bdabe926f..8ad9e4f54 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -14,7 +14,7 @@
    - <%= back_link_to %> + <%= back_link_to legislation_process_proposals_path(process_id: @process) %>

    <%= @proposal.title %>

    <% if @proposal.conflictive? %> From 69f29b4f49279544d8a0b94ec3de27cb0412b9b8 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 19:07:47 +0200 Subject: [PATCH 43/46] shows create button and categories only if proposals phase is open --- app/views/legislation/processes/proposals.html.erb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index a6346671e..cf6bd25b2 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -19,10 +19,12 @@
    -
    -

    <%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %>

    - <%= render 'legislation/proposals/categories', taggable: @process %> -
    + <% if @process.proposals_phase.open? %> +
    +

    <%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %>

    + <%= render 'legislation/proposals/categories', taggable: @process %> +
    + <% end %>
    From 392a787a2de90b2806dc3099ab0dcded6ae8361b Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 26 Oct 2017 19:09:02 +0200 Subject: [PATCH 44/46] hides only the create button --- app/views/legislation/processes/proposals.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/legislation/processes/proposals.html.erb b/app/views/legislation/processes/proposals.html.erb index cf6bd25b2..6159e9143 100644 --- a/app/views/legislation/processes/proposals.html.erb +++ b/app/views/legislation/processes/proposals.html.erb @@ -19,12 +19,12 @@
    - <% if @process.proposals_phase.open? %> -
    +
    + <% if @process.proposals_phase.open? %>

    <%= link_to t("proposals.index.start_proposal"), new_legislation_process_proposal_path(@process), class: 'button expanded' %>

    - <%= render 'legislation/proposals/categories', taggable: @process %> -
    - <% end %> + <% end %> + <%= render 'legislation/proposals/categories', taggable: @process %> +
    From 4e06fc52ce24e29ad36a65ca7aade2cc19859bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 27 Oct 2017 10:40:28 +0200 Subject: [PATCH 45/46] Removed `question`, `external_url` and `responsible_name` fields from legislation proposal form --- .../legislation/proposals/_form.html.erb | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 495a78190..23c61a671 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -11,17 +11,6 @@ <%= f.invisible_captcha :subtitle %> -
    - <%= f.label :question, t("proposals.form.proposal_question") %> -

    - <%= t("proposals.form.proposal_question_example_html") %> -

    - <%= f.text_field :question, maxlength: Legislation::Proposal.question_max_length, - placeholder: t("proposals.form.proposal_question"), - label: false, - aria: {describedby: "question-help-text"} %> -
    -
    <%= f.label :summary, t("proposals.form.proposal_summary") %>

    <%= t("proposals.form.proposal_summary_note") %>

    @@ -42,11 +31,6 @@ aria: {describedby: "video-url-help-text"} %>
    -
    - <%= f.label :external_url, t("proposals.form.proposal_external_url") %> - <%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %> -
    -
    <%= render 'documents/nested_documents', documentable: @proposal, f: f %>
    @@ -74,15 +58,6 @@ aria: {describedby: "tag-list-help-text"} %>
    - <% if current_user.unverified? %> -
    - <%= f.label :responsible_name, t("proposals.form.proposal_responsible_name") %> -

    <%= t("proposals.form.proposal_responsible_name_note") %>

    - <%= f.text_field :responsible_name, placeholder: t("proposals.form.proposal_responsible_name"), label: false, - aria: {describedby: "responsible-name-help-text"} %> -
    - <% end %> -
    <% if @proposal.new_record? %> <%= f.label :terms_of_service do %> From 5ae31a6d0189d1ce8315399d81aee4cd2e1614b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 27 Oct 2017 10:43:37 +0200 Subject: [PATCH 46/46] Prevent `responsible_name` and `question` from validation --- app/controllers/legislation/proposals_controller.rb | 7 ++++--- app/models/legislation/proposal.rb | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index ee4d10c06..6aec36057 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -49,9 +49,10 @@ class Legislation::ProposalsController < Legislation::BaseController private def proposal_params - params.require(:legislation_proposal).permit(:legislation_process_id, :title, :question, :summary, :description, :external_url, :video_url, - :responsible_name, :tag_list, :terms_of_service, :geozone_id, - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) + params.require(:legislation_proposal).permit(:legislation_process_id, :title, + :question, :summary, :description, :video_url, :tag_list, + :terms_of_service, :geozone_id, + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) end def resource_model diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 32badbb46..ec3dc6410 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -25,15 +25,11 @@ class Legislation::Proposal < ActiveRecord::Base has_many :comments, as: :commentable validates :title, presence: true - validates :question, presence: true validates :summary, presence: true validates :author, presence: true - validates :responsible_name, presence: true validates :title, length: { in: 4..Legislation::Proposal.title_max_length } validates :description, length: { maximum: Legislation::Proposal.description_max_length } - validates :question, length: { in: 10..Legislation::Proposal.question_max_length } - validates :responsible_name, length: { in: 6..Legislation::Proposal.responsible_name_max_length } validates :terms_of_service, acceptance: { allow_nil: false }, on: :create