adds responsible name to proposals
This commit is contained in:
@@ -75,7 +75,7 @@ class ProposalsController < ApplicationController
|
||||
private
|
||||
|
||||
def proposal_params
|
||||
params.require(:proposal).permit(:title, :question, :description, :external_url, :tag_list, :terms_of_service, :captcha, :captcha_key)
|
||||
params.require(:proposal).permit(:title, :question, :description, :external_url, :responsible_name, :tag_list, :terms_of_service, :captcha, :captcha_key)
|
||||
end
|
||||
|
||||
def load_featured_tags
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
<%= f.text_field :tag_list, value: @proposal.tag_list.to_s, label: false, placeholder: t("proposals.form.tags_placeholder"), class: 'js-tag-list' %>
|
||||
</div>
|
||||
|
||||
<% if current_user.unverified? %>
|
||||
<div class="small-12 column">
|
||||
<%= f.label :responsible_name, t("proposals.form.proposal_responsible_name") %>
|
||||
<%= f.text_field :responsible_name, placeholder: t("proposals.form.proposal_responsible_name"), label: false %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if @proposal.new_record? %>
|
||||
<%= f.label :terms_of_service do %>
|
||||
|
||||
Reference in New Issue
Block a user