diff --git a/app/models/comment.rb b/app/models/comment.rb index 73bd0b732..ae2734e23 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,4 +1,5 @@ class Comment < ActiveRecord::Base + include Flaggable acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases @@ -16,14 +17,9 @@ class Comment < ActiveRecord::Base belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true belongs_to :user, -> { with_hidden } - has_many :flags, as: :flaggable - scope :recent, -> { order(id: :desc) } scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } - scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } - scope :with_ignored_flag, -> { where(hidden_at: nil).where.not(ignored_flag_at: nil) } - scope :flagged, -> { where("flags_count > 0") } scope :for_render, -> { with_hidden.includes(user: :organization) } @@ -68,14 +64,6 @@ class Comment < ActiveRecord::Base cached_votes_down end - def ignored_flag? - ignored_flag_at.present? - end - - def ignore_flag - update(ignored_flag_at: Time.now) - end - def as_administrator? administrator_id.present? end diff --git a/app/models/debate.rb b/app/models/debate.rb index f1e9a621e..c2391a41f 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,5 +1,6 @@ require 'numeric' class Debate < ActiveRecord::Base + include Flaggable apply_simple_captcha acts_as_votable @@ -9,7 +10,6 @@ class Debate < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' has_many :comments, as: :commentable - has_many :flags, as: :flaggable validates :title, presence: true validates :description, presence: true @@ -26,9 +26,6 @@ class Debate < ActiveRecord::Base before_save :calculate_hot_score, :calculate_confidence_score scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } - scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } - scope :with_ignored_flag, -> { where.not(ignored_flag_at: nil).where(hidden_at: nil) } - scope :flagged, -> { where("flags_count > 0") } scope :for_render, -> { includes(:tags) } scope :sort_by_hot_score , -> { order(hot_score: :desc) } scope :sort_by_confidence_score , -> { order(confidence_score: :desc) } @@ -100,14 +97,6 @@ class Debate < ActiveRecord::Base count < 0 ? 0 : count end - def ignored_flag? - ignored_flag_at.present? - end - - def ignore_flag - update(ignored_flag_at: Time.now) - end - def after_commented save # updates the hot_score because there is a before_save end diff --git a/lib/flaggable.rb b/lib/flaggable.rb new file mode 100644 index 000000000..613ce360b --- /dev/null +++ b/lib/flaggable.rb @@ -0,0 +1,19 @@ +module Flaggable + extend ActiveSupport::Concern + + included do + has_many :flags, as: :flaggable + scope :flagged, -> { where("flags_count > 0") } + scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) } + scope :with_ignored_flag, -> { where.not(ignored_flag_at: nil).where(hidden_at: nil) } + end + + def ignored_flag? + ignored_flag_at.present? + end + + def ignore_flag + update(ignored_flag_at: Time.now) + end + +end