forked from e621ng/e621ng
[TagAliases] Fix locked artist preventing approval
Everything is already scoped to the approver. Switching to the creator doesn't make much sense here. In addition, this sent the success message 5 times because the rename happened at the wrong place
This commit is contained in:
parent
201292a00a
commit
aeb2076b80
@ -128,8 +128,8 @@ class TagAlias < TagRelationship
|
||||
update_posts_locked_tags_undo
|
||||
update_blacklists_undo
|
||||
update_posts_undo
|
||||
forum_updater.update(retirement_message, "UNDONE") if update_topic
|
||||
rename_artist_undo
|
||||
forum_updater.update(retirement_message, "UNDONE") if update_topic
|
||||
end
|
||||
tag_rel_undos.update_all(applied: true)
|
||||
end
|
||||
@ -138,9 +138,7 @@ class TagAlias < TagRelationship
|
||||
Post.without_timeout do
|
||||
Post.where_ilike(:locked_tags, "*#{consequent_name}*").find_each(batch_size: 50) do |post|
|
||||
fixed_tags = TagAlias.to_aliased_query(post.locked_tags, overrides: {consequent_name => antecedent_name})
|
||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||
post.update_column(:locked_tags, fixed_tags)
|
||||
end
|
||||
post.update_column(:locked_tags, fixed_tags)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -173,9 +171,7 @@ class TagAlias < TagRelationship
|
||||
def rename_artist_undo
|
||||
if consequent_tag.category == Tag.categories.artist
|
||||
if consequent_tag.artist.present? && antecedent_tag.artist.blank?
|
||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||
consequent_tag.artist.update!(name: antecedent_name)
|
||||
end
|
||||
consequent_tag.artist.update!(name: antecedent_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -191,8 +187,8 @@ class TagAlias < TagRelationship
|
||||
update_posts_locked_tags
|
||||
update_blacklists
|
||||
update_posts
|
||||
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
|
||||
rename_artist
|
||||
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
|
||||
update(status: 'active', post_count: consequent_tag.post_count)
|
||||
# TODO: Race condition with indexing jobs here.
|
||||
antecedent_tag.fix_post_count if antecedent_tag
|
||||
@ -275,9 +271,7 @@ class TagAlias < TagRelationship
|
||||
Post.without_timeout do
|
||||
Post.where_ilike(:locked_tags, "*#{antecedent_name}*").find_each(batch_size: 50) do |post|
|
||||
fixed_tags = TagAlias.to_aliased_query(post.locked_tags)
|
||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||
post.update_column(:locked_tags, fixed_tags)
|
||||
end
|
||||
post.update_column(:locked_tags, fixed_tags)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -297,9 +291,7 @@ class TagAlias < TagRelationship
|
||||
def rename_artist
|
||||
if antecedent_tag.category == Tag.categories.artist
|
||||
if antecedent_tag.artist.present? && consequent_tag.artist.blank?
|
||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||
antecedent_tag.artist.update!(name: consequent_name)
|
||||
end
|
||||
antecedent_tag.artist.update!(name: consequent_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -152,6 +152,17 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
assert_equal(3, tag2.reload.category)
|
||||
end
|
||||
|
||||
should "not fail if an artist with the same name is locked" do
|
||||
ta = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
|
||||
artist = as(@admin) { create(:artist, name: "aaa", is_locked: true) }
|
||||
artist.tag.update(category: Tag.categories.artist)
|
||||
|
||||
with_inline_jobs { ta.approve!(approver: @admin) }
|
||||
|
||||
assert_equal("active", ta.reload.status)
|
||||
assert_equal("bbb", artist.reload.name)
|
||||
end
|
||||
|
||||
should "error on approve if its not valid anymore" do
|
||||
create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "active")
|
||||
ta = build(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "pending", creator: @admin)
|
||||
@ -179,6 +190,16 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
assert_equal "deleted", ta.reload.status
|
||||
end
|
||||
|
||||
should "update locked tags on approve" do
|
||||
ta = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "pending")
|
||||
post1 = create(:post, locked_tags: "aaa foo")
|
||||
post2 = create(:post, locked_tags: "-aaa foo")
|
||||
with_inline_jobs { ta.approve!(approver: @admin) }
|
||||
|
||||
assert_equal("bbb foo", post1.reload.locked_tags)
|
||||
assert_equal("-bbb foo", post2.reload.locked_tags)
|
||||
end
|
||||
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
|
Loading…
Reference in New Issue
Block a user