From f8768fd6b7565f9e5c549bc7f61ed9ffa394435e Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 11 Jan 2022 11:16:48 -0600 Subject: [PATCH] BURs: move the is_banned flag when aliasing artists. When a banned artist tag is aliased into a nonbanned artist tag, move the is_banned flag from the old artist entry to the new artist_entry. Related to #4940. Fixes a case where a banned artist could lose the banned status when it was moved. --- app/logical/tag_mover.rb | 2 ++ test/unit/tag_alias_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/logical/tag_mover.rb b/app/logical/tag_mover.rb index 9b439b9e3..45816d18b 100644 --- a/app/logical/tag_mover.rb +++ b/app/logical/tag_mover.rb @@ -156,12 +156,14 @@ class TagMover new_artist.group_name = old_artist.group_name unless new_artist.group_name.present? new_artist.url_string += "\n" + old_artist.url_string new_artist.is_deleted = false + new_artist.is_banned = old_artist.is_banned || new_artist.is_banned new_artist.save! old_artist.other_names = [new_artist.name] old_artist.group_name = "" old_artist.url_string = "" old_artist.is_deleted = true + old_artist.is_banned = false old_artist.save! end diff --git a/test/unit/tag_alias_test.rb b/test/unit/tag_alias_test.rb index e4b369231..c93b7e6c5 100644 --- a/test/unit/tag_alias_test.rb +++ b/test/unit/tag_alias_test.rb @@ -248,6 +248,17 @@ class TagAliasTest < ActiveSupport::TestCase assert_equal(%w[-https://twitter.com/222 -https://twitter.com/333 https://twitter.com/111 https://twitter.com/444], @artist2.url_array) end + should "move the is_banned flag from the old artist entry to the new artist entry" do + @old_artist = create(:artist, name: "old_artist", is_banned: true) + @new_artist = create(:artist, name: "new_artist", is_banned: false) + + TagAlias.approve!(antecedent_name: "old_artist", consequent_name: "new_artist", approver: @admin) + perform_enqueued_jobs + + assert_equal(true, @new_artist.reload.is_banned) + assert_equal(false, @old_artist.reload.is_banned) + end + should "ignore the old artist if it has been deleted" do @artist1 = create(:artist, name: "aaa", group_name: "g_aaa", other_names: "111 222", url_string: "https://twitter.com/111\n-https://twitter.com/222", is_deleted: true) @artist2 = create(:artist, name: "bbb", other_names: "111 333", url_string: "https://twitter.com/111\n-https://twitter.com/333\nhttps://twitter.com/444")