Fix #4645: Builders can alias empty non-artist tags

This commit is contained in:
evazion
2021-01-04 01:02:39 -06:00
parent 69cfa1696a
commit 257fa3d9c1
2 changed files with 20 additions and 2 deletions

View File

@@ -212,11 +212,18 @@ class BulkUpdateRequestProcessor
end.join("\n")
end
# Tag move is allowed if:
#
# * The antecedent tag is an artist tag.
# * The consequent_tag is a nonexistent tag, an empty tag (of any type), or an artist tag.
# * Both tags have less than 100 posts.
def self.is_tag_move_allowed?(antecedent_name, consequent_name)
antecedent_tag = Tag.find_by_name(Tag.normalize_name(antecedent_name))
consequent_tag = Tag.find_by_name(Tag.normalize_name(consequent_name))
(antecedent_tag.blank? || antecedent_tag.empty? || (antecedent_tag.artist? && antecedent_tag.post_count <= 100)) &&
(consequent_tag.blank? || consequent_tag.empty? || (consequent_tag.artist? && consequent_tag.post_count <= 100))
antecedent_allowed = antecedent_tag.present? && antecedent_tag.artist? && antecedent_tag.post_count < 100
consequent_allowed = consequent_tag.nil? || consequent_tag.empty? || (consequent_tag.artist? && consequent_tag.post_count < 100)
antecedent_allowed && consequent_allowed
end
end

View File

@@ -139,6 +139,17 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
end
context "for a builder" do
should "fail when moving a non-artist tag" do
create(:tag, name: "sfw", post_count: 0)
@bulk_update_request = create(:bulk_update_request, script: "alias sfw -> rating:s")
post_auth approve_bulk_update_request_path(@bulk_update_request), @builder
assert_response 403
assert_equal("pending", @bulk_update_request.reload.status)
assert_equal(false, TagAlias.exists?(antecedent_name: "sfw", consequent_name: "rating:s"))
end
should "fail for a large artist move" do
create(:tag, name: "artist1", category: Tag.categories.artist, post_count: 1000)
@bulk_update_request = create(:bulk_update_request, script: "create alias artist1 -> artist2")