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] 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