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 %> -
- <%= t("proposals.proposal.successful", - voting: link_to(t("proposals.proposal.voting"), polls_path)).html_safe %> -
-- <%= 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.archived") %>
-- <%= 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") %>
-