Extracts Flammable module from comment & debate
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
class Comment < ActiveRecord::Base
|
class Comment < ActiveRecord::Base
|
||||||
|
include Flaggable
|
||||||
|
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
@@ -16,14 +17,9 @@ class Comment < ActiveRecord::Base
|
|||||||
belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true
|
belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true
|
||||||
belongs_to :user, -> { with_hidden }
|
belongs_to :user, -> { with_hidden }
|
||||||
|
|
||||||
has_many :flags, as: :flaggable
|
|
||||||
|
|
||||||
scope :recent, -> { order(id: :desc) }
|
scope :recent, -> { order(id: :desc) }
|
||||||
|
|
||||||
scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :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) }
|
scope :for_render, -> { with_hidden.includes(user: :organization) }
|
||||||
|
|
||||||
@@ -68,14 +64,6 @@ class Comment < ActiveRecord::Base
|
|||||||
cached_votes_down
|
cached_votes_down
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignored_flag?
|
|
||||||
ignored_flag_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def ignore_flag
|
|
||||||
update(ignored_flag_at: Time.now)
|
|
||||||
end
|
|
||||||
|
|
||||||
def as_administrator?
|
def as_administrator?
|
||||||
administrator_id.present?
|
administrator_id.present?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
require 'numeric'
|
require 'numeric'
|
||||||
class Debate < ActiveRecord::Base
|
class Debate < ActiveRecord::Base
|
||||||
|
include Flaggable
|
||||||
apply_simple_captcha
|
apply_simple_captcha
|
||||||
|
|
||||||
acts_as_votable
|
acts_as_votable
|
||||||
@@ -9,7 +10,6 @@ class Debate < ActiveRecord::Base
|
|||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :flags, as: :flaggable
|
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :description, presence: true
|
validates :description, presence: true
|
||||||
@@ -26,9 +26,6 @@ class Debate < ActiveRecord::Base
|
|||||||
before_save :calculate_hot_score, :calculate_confidence_score
|
before_save :calculate_hot_score, :calculate_confidence_score
|
||||||
|
|
||||||
scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :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.not(ignored_flag_at: nil).where(hidden_at: nil) }
|
|
||||||
scope :flagged, -> { where("flags_count > 0") }
|
|
||||||
scope :for_render, -> { includes(:tags) }
|
scope :for_render, -> { includes(:tags) }
|
||||||
scope :sort_by_hot_score , -> { order(hot_score: :desc) }
|
scope :sort_by_hot_score , -> { order(hot_score: :desc) }
|
||||||
scope :sort_by_confidence_score , -> { order(confidence_score: :desc) }
|
scope :sort_by_confidence_score , -> { order(confidence_score: :desc) }
|
||||||
@@ -100,14 +97,6 @@ class Debate < ActiveRecord::Base
|
|||||||
count < 0 ? 0 : count
|
count < 0 ? 0 : count
|
||||||
end
|
end
|
||||||
|
|
||||||
def ignored_flag?
|
|
||||||
ignored_flag_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def ignore_flag
|
|
||||||
update(ignored_flag_at: Time.now)
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_commented
|
def after_commented
|
||||||
save # updates the hot_score because there is a before_save
|
save # updates the hot_score because there is a before_save
|
||||||
end
|
end
|
||||||
|
|||||||
19
lib/flaggable.rb
Normal file
19
lib/flaggable.rb
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user