Fix #3419: Deleting a post doesn't clear parent's "parent" status.
Bug: when deleting a child post and the "Move favorites to parent?" option is set, the parent's has_active_children flag is not cleared. `give_favorites_to_parent` moves the votes, and moving the votes has the side effect of reloading the post (to get the new score). But reloading the post wipes out the is_deleted_changed? flag, which is used by `update_parent_on_save`. Fix: update the `is_deleted` flag *before* moving favorites, so that the `update_parent_on_save` callback runs before `give_favorite_to_parent` runs.
This commit is contained in:
@@ -1369,18 +1369,15 @@ class Post < ApplicationRecord
|
|||||||
Post.transaction do
|
Post.transaction do
|
||||||
flag!(reason, is_deletion: true)
|
flag!(reason, is_deletion: true)
|
||||||
|
|
||||||
self.is_deleted = true
|
update({
|
||||||
self.is_pending = false
|
is_deleted: true,
|
||||||
self.is_flagged = false
|
is_pending: false,
|
||||||
self.is_banned = true if options[:ban] || has_tag?("banned_artist")
|
is_flagged: false,
|
||||||
update_columns(
|
is_banned: is_banned || options[:ban] || has_tag?("banned_artist")
|
||||||
:is_deleted => is_deleted,
|
}, without_protection: true)
|
||||||
:is_pending => is_pending,
|
|
||||||
:is_flagged => is_flagged,
|
# XXX This must happen *after* the `is_deleted` flag is set to true (issue #3419).
|
||||||
:is_banned => is_banned
|
|
||||||
)
|
|
||||||
give_favorites_to_parent if options[:move_favorites]
|
give_favorites_to_parent if options[:move_favorites]
|
||||||
update_parent_on_save
|
|
||||||
|
|
||||||
unless options[:without_mod_action]
|
unless options[:without_mod_action]
|
||||||
ModAction.log("deleted post ##{id}, reason: #{reason}")
|
ModAction.log("deleted post ##{id}, reason: #{reason}")
|
||||||
|
|||||||
@@ -353,6 +353,17 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
p1.reload
|
p1.reload
|
||||||
assert(p1.has_children?, "Parent should have children")
|
assert(p1.has_children?, "Parent should have children")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "clear the has_active_children flag when the 'move favorites' option is set" do
|
||||||
|
user = FactoryGirl.create(:gold_user)
|
||||||
|
p1 = FactoryGirl.create(:post)
|
||||||
|
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||||
|
c1.add_favorite!(user)
|
||||||
|
|
||||||
|
assert_equal(true, p1.reload.has_active_children?)
|
||||||
|
c1.delete!("test", :move_favorites => true)
|
||||||
|
assert_equal(false, p1.reload.has_active_children?)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "one child" do
|
context "one child" do
|
||||||
|
|||||||
Reference in New Issue
Block a user