Extracts Flammable module from comment & debate

This commit is contained in:
kikito
2015-09-12 14:03:38 +02:00
parent 800fa7c47f
commit d57d538f3b
3 changed files with 21 additions and 25 deletions

View File

@@ -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

View File

@@ -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

19
lib/flaggable.rb Normal file
View 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