refactors sanitizable behaviour
This commit is contained in:
19
app/models/concerns/sanitizable.rb
Normal file
19
app/models/concerns/sanitizable.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Sanitizable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_validation :sanitize_description
|
||||
before_validation :sanitize_tag_list
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def sanitize_description
|
||||
self.description = WYSIWYGSanitizer.new.sanitize(description)
|
||||
end
|
||||
|
||||
def sanitize_tag_list
|
||||
self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -4,6 +4,7 @@ class Debate < ActiveRecord::Base
|
||||
include Taggable
|
||||
include Conflictable
|
||||
include Measurable
|
||||
include Sanitizable
|
||||
|
||||
apply_simple_captcha
|
||||
|
||||
@@ -23,9 +24,6 @@ class Debate < ActiveRecord::Base
|
||||
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
|
||||
before_validation :sanitize_description
|
||||
before_validation :sanitize_tag_list
|
||||
|
||||
before_save :calculate_hot_score, :calculate_confidence_score
|
||||
|
||||
scope :for_render, -> { includes(:tags) }
|
||||
@@ -39,6 +37,10 @@ class Debate < ActiveRecord::Base
|
||||
# Ahoy setup
|
||||
visitable # Ahoy will automatically assign visit_id on create
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
def likes
|
||||
cached_votes_up
|
||||
end
|
||||
@@ -83,10 +85,6 @@ class Debate < ActiveRecord::Base
|
||||
(cached_anonymous_votes_total.to_f / cached_votes_total) * 100
|
||||
end
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
def after_commented
|
||||
save # updates the hot_score because there is a before_save
|
||||
end
|
||||
@@ -120,14 +118,4 @@ class Debate < ActiveRecord::Base
|
||||
self.tags.each{ |t| t.increment_custom_counter_for('Debate') }
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def sanitize_description
|
||||
self.description = WYSIWYGSanitizer.new.sanitize(description)
|
||||
end
|
||||
|
||||
def sanitize_tag_list
|
||||
self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ class Proposal < ActiveRecord::Base
|
||||
include Taggable
|
||||
include Conflictable
|
||||
include Measurable
|
||||
include Sanitizable
|
||||
|
||||
apply_simple_captcha
|
||||
acts_as_votable
|
||||
@@ -25,8 +26,6 @@ class Proposal < ActiveRecord::Base
|
||||
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
|
||||
before_validation :sanitize_description
|
||||
before_validation :sanitize_tag_list
|
||||
before_validation :set_responsible_name
|
||||
|
||||
before_save :calculate_hot_score, :calculate_confidence_score
|
||||
@@ -39,18 +38,14 @@ class Proposal < ActiveRecord::Base
|
||||
scope :sort_by_random, -> { order("RANDOM()") }
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
def total_votes
|
||||
cached_votes_up
|
||||
end
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
def editable?
|
||||
total_votes <= Setting.value_for("max_votes_for_proposal_edit").to_i
|
||||
end
|
||||
@@ -107,14 +102,6 @@ class Proposal < ActiveRecord::Base
|
||||
|
||||
protected
|
||||
|
||||
def sanitize_description
|
||||
self.description = WYSIWYGSanitizer.new.sanitize(description)
|
||||
end
|
||||
|
||||
def sanitize_tag_list
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user