Fix #4933: Don't allow mass update requests if both the antecedent and consequent are single tags

This commit is contained in:
evazion
2021-12-09 18:02:19 -06:00
parent 00153b9214
commit 7dbde7bc14
3 changed files with 21 additions and 11 deletions

View File

@@ -113,7 +113,15 @@ class BulkUpdateRequestProcessor
errors.add(:base, "Can't rename #{args[0]} -> #{args[1]} ('#{args[0]}' has more than #{MAXIMUM_RENAME_COUNT} posts, use an alias instead)")
end
when :mass_update, :nuke
when :mass_update
lhs = PostQueryBuilder.new(args[0])
rhs = PostQueryBuilder.new(args[1])
if lhs.is_simple_tag? && rhs.is_simple_tag?
errors.add(:base, "Can't mass update #{args[0]} -> #{args[1]} (use an alias or a rename instead for tag moves)")
end
when :nuke
# okay
when :invalid_line
@@ -210,11 +218,6 @@ class BulkUpdateRequestProcessor
case command
when :create_alias, :rename
BulkUpdateRequestProcessor.is_tag_move_allowed?(args[0], args[1])
when :mass_update
lhs = PostQueryBuilder.new(args[0])
rhs = PostQueryBuilder.new(args[1])
lhs.is_simple_tag? && rhs.is_simple_tag? && BulkUpdateRequestProcessor.is_tag_move_allowed?(args[0], args[1])
else
false
end

View File

@@ -171,7 +171,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
create(:tag, name: "artist1a", category: Tag.categories.artist, post_count: 10)
create(:tag, name: "artist1b", category: Tag.categories.general, post_count: 0)
create(:tag, name: "artist2a", category: Tag.categories.artist, post_count: 20)
@bulk_update_request = create(:bulk_update_request, script: "mass update artist1a -> artist1b\ncreate alias artist2a -> artist2b")
@bulk_update_request = create(:bulk_update_request, script: "rename artist1a -> artist1b\ncreate alias artist2a -> artist2b")
perform_enqueued_jobs do
post_auth approve_bulk_update_request_path(@bulk_update_request), @builder

View File

@@ -308,11 +308,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
context "the mass update command" do
setup do
@post = create(:post, tag_string: "foo")
@bur = create_bur!("mass update foo -> bar", @admin)
@bur = create_bur!("mass update foo -> bar baz", @admin)
end
should "update the tags" do
assert_equal("bar", @post.reload.tag_string)
assert_equal("bar baz", @post.reload.tag_string)
assert_equal("approved", @bur.reload.status)
assert_equal(User.system, @post.versions.last.updater)
end
@@ -324,6 +324,13 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal("Imageboard", @post.reload.source)
assert_equal("approved", @bur.reload.status)
end
should "not allow mass update for simple A -> B moves" do
@bur = build(:bulk_update_request, script: "mass update bunny -> rabbit")
assert_equal(false, @bur.valid?)
assert_equal(["Can't mass update bunny -> rabbit (use an alias or a rename instead for tag moves)"], @bur.errors.full_messages)
end
end
context "the rename command" do
@@ -535,7 +542,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
@script = '
create alias foo -> bar
create implication bar -> baz
mass update aaa -> bbb
mass update aaa -> bbb blah
'
@bur = create_bur!(@script, @admin)
@@ -554,7 +561,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
end
should "process mass updates" do
assert_equal("bar baz bbb", @post.reload.tag_string)
assert_equal("bar baz bbb blah", @post.reload.tag_string)
end
should "set the alias/implication approvers" do