flags: move status locked check to post_flag.rb.
This commit is contained in:
@@ -296,10 +296,6 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def flag!(reason, options = {})
|
def flag!(reason, options = {})
|
||||||
if is_status_locked?
|
|
||||||
raise PostFlag::Error.new("Post is locked and cannot be flagged")
|
|
||||||
end
|
|
||||||
|
|
||||||
flag = flags.create(:reason => reason, :is_resolved => false, :is_deletion => options[:is_deletion])
|
flag = flags.create(:reason => reason, :is_resolved => false, :is_deletion => options[:is_deletion])
|
||||||
|
|
||||||
if flag.errors.any?
|
if flag.errors.any?
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class PostFlag < ActiveRecord::Base
|
|||||||
belongs_to :post
|
belongs_to :post
|
||||||
validates_presence_of :reason, :creator_id, :creator_ip_addr
|
validates_presence_of :reason, :creator_id, :creator_ip_addr
|
||||||
validate :validate_creator_is_not_limited
|
validate :validate_creator_is_not_limited
|
||||||
validate :validate_post_is_active
|
validate :validate_post
|
||||||
before_validation :initialize_creator, :on => :create
|
before_validation :initialize_creator, :on => :create
|
||||||
validates_uniqueness_of :creator_id, :scope => :post_id, :on => :create, :unless => :is_deletion, :message => "have already flagged this post"
|
validates_uniqueness_of :creator_id, :scope => :post_id, :on => :create, :unless => :is_deletion, :message => "have already flagged this post"
|
||||||
before_save :update_post
|
before_save :update_post
|
||||||
@@ -146,10 +146,9 @@ class PostFlag < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_post_is_active
|
def validate_post
|
||||||
if post.is_deleted?
|
errors[:post] << "is locked and cannot be flagged" if post.is_status_locked?
|
||||||
errors[:post] << "is deleted"
|
errors[:post] << "is deleted" if post.is_deleted?
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_creator
|
def initialize_creator
|
||||||
|
|||||||
Reference in New Issue
Block a user