From 257fa3d9c108def5ee31f95b46b43cecde9a8184 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 4 Jan 2021 01:02:39 -0600 Subject: [PATCH] Fix #4645: Builders can alias empty non-artist tags --- app/logical/bulk_update_request_processor.rb | 11 +++++++++-- .../bulk_update_requests_controller_test.rb | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/logical/bulk_update_request_processor.rb b/app/logical/bulk_update_request_processor.rb index bb4ef8271..a6e257a66 100644 --- a/app/logical/bulk_update_request_processor.rb +++ b/app/logical/bulk_update_request_processor.rb @@ -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 diff --git a/test/functional/bulk_update_requests_controller_test.rb b/test/functional/bulk_update_requests_controller_test.rb index b72db21bc..0864f8a54 100644 --- a/test/functional/bulk_update_requests_controller_test.rb +++ b/test/functional/bulk_update_requests_controller_test.rb @@ -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")