Exempt deletions from dupe flag checking
This commit is contained in:
@@ -12,7 +12,7 @@ module Moderator
|
||||
def delete
|
||||
@post = ::Post.find(params[:id])
|
||||
if params[:commit] == "Delete"
|
||||
@post.flag!(params[:reason])
|
||||
@post.flag!(params[:reason], :is_deletion => true)
|
||||
@post.delete!(:reason => params[:reason], :move_favorites => params[:move_favorites].present?)
|
||||
end
|
||||
redirect_to(post_path(@post))
|
||||
|
||||
@@ -218,12 +218,12 @@ class Post < ActiveRecord::Base
|
||||
!is_status_locked? && (is_pending? || is_flagged? || is_deleted?) && approver_id != CurrentUser.id
|
||||
end
|
||||
|
||||
def flag!(reason)
|
||||
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)
|
||||
flag = flags.create(:reason => reason, :is_resolved => false, :is_deletion => options[:is_deletion])
|
||||
|
||||
if flag.errors.any?
|
||||
raise PostFlag::Error.new(flag.errors.full_messages.join("; "))
|
||||
|
||||
@@ -7,9 +7,10 @@ class PostFlag < ActiveRecord::Base
|
||||
validate :validate_creator_is_not_limited
|
||||
validate :validate_post_is_active
|
||||
before_validation :initialize_creator, :on => :create
|
||||
validates_uniqueness_of :creator_id, :scope => :post_id, :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
|
||||
attr_accessible :post, :post_id, :reason, :is_resolved
|
||||
attr_accessible :post, :post_id, :reason, :is_resolved, :is_deletion
|
||||
attr_accessor :is_deletion
|
||||
|
||||
module SearchMethods
|
||||
def resolved
|
||||
|
||||
@@ -20,6 +20,13 @@ module Moderator
|
||||
@post.reload
|
||||
assert(@post.is_deleted?)
|
||||
end
|
||||
|
||||
should "work even if the deleter has flagged the post previously" do
|
||||
PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
||||
post :delete, {:id => @post.id, :reason => "xxx", :format => "js", :commit => "Delete"}, {:user_id => @admin.id}
|
||||
@post.reload
|
||||
assert(@post.is_deleted?)
|
||||
end
|
||||
end
|
||||
|
||||
context "undelete action" do
|
||||
|
||||
Reference in New Issue
Block a user