adds responsible name to proposals
This commit is contained in:
@@ -14,15 +14,18 @@ class Proposal < ActiveRecord::Base
|
||||
validates :question, presence: true
|
||||
validates :description, presence: true
|
||||
validates :author, presence: true
|
||||
validates :responsible_name, presence: true
|
||||
|
||||
validate :validate_title_length
|
||||
validate :validate_question_length
|
||||
validate :validate_description_length
|
||||
validate :validate_responsible_length
|
||||
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
|
||||
before_validation :sanitize_description
|
||||
before_validation :sanitize_tag_list
|
||||
before_validation :set_responsible_name
|
||||
|
||||
scope :for_render, -> { includes(:tags) }
|
||||
scope :sort_by_hot_score , -> { order(hot_score: :desc) }
|
||||
@@ -96,6 +99,10 @@ class Proposal < ActiveRecord::Base
|
||||
6000
|
||||
end
|
||||
|
||||
def self.responsible_name_max_length
|
||||
60
|
||||
end
|
||||
|
||||
def self.search(terms)
|
||||
terms.present? ? where("title ILIKE ? OR description ILIKE ? OR question ILIKE ?", "%#{terms}%", "%#{terms}%", "%#{terms}%") : none
|
||||
end
|
||||
@@ -114,6 +121,11 @@ class Proposal < ActiveRecord::Base
|
||||
self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
|
||||
end
|
||||
|
||||
def set_responsible_name
|
||||
if author && author.level_two_or_three_verified?
|
||||
self.responsible_name = author.document_number
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
def validate_description_length
|
||||
@@ -140,4 +152,12 @@ class Proposal < ActiveRecord::Base
|
||||
validator.validate(self)
|
||||
end
|
||||
|
||||
def validate_responsible_length
|
||||
validator = ActiveModel::Validations::LengthValidator.new(
|
||||
attributes: :title,
|
||||
minimum: 6,
|
||||
maximum: Proposal.responsible_name_max_length)
|
||||
validator.validate(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user