diff --git a/app/controllers/moderator/post/posts_controller.rb b/app/controllers/moderator/post/posts_controller.rb index 0a410cfb0..e8367e564 100644 --- a/app/controllers/moderator/post/posts_controller.rb +++ b/app/controllers/moderator/post/posts_controller.rb @@ -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)) diff --git a/app/models/post.rb b/app/models/post.rb index 492a6133a..6b2df0d28 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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("; ")) diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index 8d77e044d..fe5692497 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -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 diff --git a/test/functional/moderator/post/posts_controller_test.rb b/test/functional/moderator/post/posts_controller_test.rb index 1eb02ea51..6357740d2 100644 --- a/test/functional/moderator/post/posts_controller_test.rb +++ b/test/functional/moderator/post/posts_controller_test.rb @@ -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