flags: add 3 day flagging cooldown period.
This commit is contained in:
@@ -7,6 +7,8 @@ class PostFlag < ActiveRecord::Base
|
||||
BANNED = "Artist requested removal"
|
||||
end
|
||||
|
||||
COOLDOWN_PERIOD = 3.days
|
||||
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :post
|
||||
validates_presence_of :reason, :creator_id, :creator_ip_addr
|
||||
@@ -18,6 +20,10 @@ class PostFlag < ActiveRecord::Base
|
||||
attr_accessible :post, :post_id, :reason, :is_resolved, :is_deletion
|
||||
attr_accessor :is_deletion
|
||||
|
||||
scope :by_users, lambda { where.not(creator: User.system) }
|
||||
scope :by_system, lambda { where(creator: User.system) }
|
||||
scope :in_cooldown, lambda { by_users.where("created_at >= ?", COOLDOWN_PERIOD.ago) }
|
||||
|
||||
module SearchMethods
|
||||
def reason_matches(query)
|
||||
if query =~ /\*/
|
||||
@@ -149,6 +155,11 @@ class PostFlag < ActiveRecord::Base
|
||||
def validate_post
|
||||
errors[:post] << "is locked and cannot be flagged" if post.is_status_locked?
|
||||
errors[:post] << "is deleted" if post.is_deleted?
|
||||
|
||||
flag = post.flags.in_cooldown.last
|
||||
if flag.present?
|
||||
errors[:post] << "cannot be flagged more than once every #{COOLDOWN_PERIOD.inspect} (last flagged: #{flag.created_at.to_s(:long)})"
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
|
||||
Reference in New Issue
Block a user