Remove people proposal model

This model isn't used anywhere, since it was created as part of a
feature which couldn't be completed.

This commit reverts commit 46e5d6a9.
This commit is contained in:
Javi Martín
2019-10-30 02:26:42 +01:00
parent a1dce46754
commit f3df3f4fbc
13 changed files with 28 additions and 383 deletions

View File

@@ -9,7 +9,7 @@ class Comment < ApplicationRecord
COMMENTABLE_TYPES = %w[Debate Proposal Budget::Investment Poll Topic
Legislation::Question Legislation::Annotation
Legislation::Proposal Legislation::PeopleProposal].freeze
Legislation::Proposal].freeze
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases

View File

@@ -1,152 +0,0 @@
class Legislation::PeopleProposal < ApplicationRecord
include ActsAsParanoidAliases
include Flaggable
include Taggable
include Conflictable
include Measurable
include Sanitizable
include Searchable
include Filterable
include Followable
include Communitable
include Documentable
include Notifiable
include Imageable
include Randomizable
accepts_nested_attributes_for :documents, allow_destroy: true
acts_as_votable
acts_as_paranoid column: :hidden_at
belongs_to :process, foreign_key: "legislation_process_id", inverse_of: :people_proposals
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :people_proposals
has_many :comments, as: :commentable, inverse_of: :commentable
validates :title, presence: true
validates :summary, presence: true
validates :author, presence: true
validates :process, presence: true
validates :title, length: { in: 4..Legislation::PeopleProposal.title_max_length }
validates :description, length: { maximum: Legislation::PeopleProposal.description_max_length }
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_title, -> { reorder(title: :asc) }
scope :sort_by_id, -> { reorder(id: :asc) }
scope :sort_by_supports, -> { reorder(cached_votes_score: :desc) }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :last_week, -> { where("people_proposals.created_at >= ?", 7.days.ago) }
scope :validated, -> { where(validated: true) }
scope :selected, -> { where(selected: true) }
scope :winners, -> { selected.sort_by_confidence_score }
def to_param
"#{id}-#{title}".parameterize
end
def searchable_values
{ title => "A",
author.username => "B",
tag_list.join(" ") => "B",
summary => "C",
description => "D" }
end
def self.search(terms)
by_code = search_by_code(terms.strip)
by_code.presence || 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 likes
cached_votes_up
end
def dislikes
cached_votes_down
end
def total_votes
cached_votes_total
end
def votes_score
cached_votes_score
end
def voters
User.active.where(id: votes_for.voters)
end
def editable?
total_votes <= Setting["max_votes_for_people_proposal_edit"].to_i
end
def editable_by?(user)
author_id == user.id && editable?
end
def votable_by?(user)
user&.level_two_or_three_verified?
end
def register_vote(user, vote_value)
vote_by(voter: user, vote: vote_value) if votable_by?(user)
end
def code
"#{Setting["proposal_code_prefix"]}-#{created_at.strftime("%Y-%m")}-#{id}"
end
def after_commented
save # update cache when it has a new comment
end
def calculate_hot_score
self.hot_score = ScoreCalculator.hot_score(self)
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("LegislationPeopleProposal") }
end
def after_restore
tags.each { |t| t.increment_custom_counter_for("LegislationPeopleProposal") }
end
def contact_info
[phone, email, website].compact
end
protected
def set_responsible_name
if author&.document_number?
self.responsible_name = author.document_number
end
end
end

View File

@@ -20,8 +20,7 @@ class Legislation::Process < ApplicationRecord
extend DownloadSettings::LegislationProcessCsv
PHASES_AND_PUBLICATIONS = %i[homepage_phase draft_phase debate_phase allegations_phase
proposals_phase people_proposals_phase draft_publication
result_publication].freeze
proposals_phase draft_publication result_publication].freeze
CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i.freeze
@@ -41,10 +40,6 @@ class Legislation::Process < ApplicationRecord
foreign_key: "legislation_process_id",
inverse_of: :process,
dependent: :destroy
has_many :people_proposals, -> { order(:id) },
foreign_key: "legislation_process_id",
inverse_of: :process,
dependent: :destroy
validates_translation :title, presence: true
validates :start_date, presence: true
@@ -56,8 +51,6 @@ class Legislation::Process < ApplicationRecord
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?
validates :people_proposals_phase_end_date, presence: true,
if: :people_proposals_phase_start_date?
validate :valid_date_ranges
validates :background_color, format: { allow_blank: true, with: CSS_HEX_COLOR }
validates :font_color, format: { allow_blank: true, with: CSS_HEX_COLOR }
@@ -101,11 +94,6 @@ class Legislation::Process < ApplicationRecord
proposals_phase_end_date, proposals_phase_enabled)
end
def people_proposals_phase
Legislation::Process::Phase.new(people_proposals_phase_start_date,
people_proposals_phase_end_date, people_proposals_phase_enabled)
end
def draft_publication
Legislation::Process::Publication.new(draft_publication_date, draft_publication_enabled)
end

View File

@@ -143,7 +143,6 @@ class Setting < ApplicationRecord
"max_ratio_anon_votes_on_debates": 50,
"max_votes_for_debate_edit": 1000,
"max_votes_for_proposal_edit": 1000,
"max_votes_for_people_proposal_edit": 1000,
"comments_body_max_length": 1000,
"proposal_code_prefix": "CONSUL",
"votes_for_proposal_success": 10000,

View File

@@ -23,7 +23,6 @@ class User < ApplicationRecord
has_many :identities, dependent: :destroy
has_many :debates, -> { with_hidden }, foreign_key: :author_id, inverse_of: :author
has_many :proposals, -> { with_hidden }, foreign_key: :author_id, inverse_of: :author
has_many :people_proposals, -> { with_hidden }, foreign_key: :author_id, inverse_of: :author
has_many :activities
has_many :budget_investments, -> { with_hidden },
class_name: "Budget::Investment",