module CensorBear class ModLog < ApplicationRecord REASONS = %w(无 广告/SPAM 恶意灌水 违规内容 文不对题 重复发布 其它) belongs_to :record, polymorphic: true, required: false def record_path return '#' if record.blank? record.censor_show_path end def delete(reason) # ugc内容需要开软删,便于撤销&查看统计,可以定时删除统计并删除软删内容,类似回收站机制 raise NoMethodError.new("undefined censor_delete for record") unless record.respond_to?(:censor_delete) ret = record.censor_delete handled!(reason) if ret end def approve raise NoMethodError unless record.respond_to?(:censor_approve) ret = record.censor_approve handled! if ret end def ban_user raise NoMethodError unless record.respond_to?(:censor_ban_user) ret = record.censor_ban_user delete if ret end scope :pending, -> { where(status: 0) } scope :handled, -> { where(status: 1) } scope :suspended, -> { where(status: 2) } def handled!(reason = nil) update_columns(status: 1, reason: reason) end def pend! update_columns(status: 0) end def suspend! update_columns(status: 2) end end end