Fix #4933: Don't allow mass update requests if both the antecedent and consequent are single tags
This commit is contained in:
@@ -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)")
|
errors.add(:base, "Can't rename #{args[0]} -> #{args[1]} ('#{args[0]}' has more than #{MAXIMUM_RENAME_COUNT} posts, use an alias instead)")
|
||||||
end
|
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
|
# okay
|
||||||
|
|
||||||
when :invalid_line
|
when :invalid_line
|
||||||
@@ -210,11 +218,6 @@ class BulkUpdateRequestProcessor
|
|||||||
case command
|
case command
|
||||||
when :create_alias, :rename
|
when :create_alias, :rename
|
||||||
BulkUpdateRequestProcessor.is_tag_move_allowed?(args[0], args[1])
|
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
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
create(:tag, name: "artist1a", category: Tag.categories.artist, post_count: 10)
|
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: "artist1b", category: Tag.categories.general, post_count: 0)
|
||||||
create(:tag, name: "artist2a", category: Tag.categories.artist, post_count: 20)
|
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
|
perform_enqueued_jobs do
|
||||||
post_auth approve_bulk_update_request_path(@bulk_update_request), @builder
|
post_auth approve_bulk_update_request_path(@bulk_update_request), @builder
|
||||||
|
|||||||
@@ -308,11 +308,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
context "the mass update command" do
|
context "the mass update command" do
|
||||||
setup do
|
setup do
|
||||||
@post = create(:post, tag_string: "foo")
|
@post = create(:post, tag_string: "foo")
|
||||||
@bur = create_bur!("mass update foo -> bar", @admin)
|
@bur = create_bur!("mass update foo -> bar baz", @admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "update the tags" do
|
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("approved", @bur.reload.status)
|
||||||
assert_equal(User.system, @post.versions.last.updater)
|
assert_equal(User.system, @post.versions.last.updater)
|
||||||
end
|
end
|
||||||
@@ -324,6 +324,13 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
assert_equal("Imageboard", @post.reload.source)
|
assert_equal("Imageboard", @post.reload.source)
|
||||||
assert_equal("approved", @bur.reload.status)
|
assert_equal("approved", @bur.reload.status)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "the rename command" do
|
context "the rename command" do
|
||||||
@@ -535,7 +542,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
@script = '
|
@script = '
|
||||||
create alias foo -> bar
|
create alias foo -> bar
|
||||||
create implication bar -> baz
|
create implication bar -> baz
|
||||||
mass update aaa -> bbb
|
mass update aaa -> bbb blah
|
||||||
'
|
'
|
||||||
|
|
||||||
@bur = create_bur!(@script, @admin)
|
@bur = create_bur!(@script, @admin)
|
||||||
@@ -554,7 +561,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "process mass updates" do
|
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
|
end
|
||||||
|
|
||||||
should "set the alias/implication approvers" do
|
should "set the alias/implication approvers" do
|
||||||
|
|||||||
Reference in New Issue
Block a user