BURs: add nuke command.

Usage:

* `nuke touhou`
* `nuke pool:Disgustingly_Adorable`

Add a command for nuking tags. `nuke A` is a shortcut for `mass update A -> -A`.
This means it also works for pools.
This commit is contained in:
evazion
2020-12-02 13:08:34 -06:00
parent 86e4c21e48
commit b7b15b3d95
2 changed files with 34 additions and 1 deletions

View File

@@ -32,6 +32,8 @@ class BulkUpdateRequestProcessor
[:mass_update, $1, $2]
when /\Acategory (\S+) -> (#{Tag.categories.regexp})\z/i
[:change_category, Tag.normalize_name($1), $2.downcase]
when /\Anuke (\S+)\z/i
[:nuke, $1]
else
[:invalid_line, line]
end
@@ -90,7 +92,7 @@ class BulkUpdateRequestProcessor
errors[:base] << "Can't rename #{args[0]} -> #{args[1]} (the '#{args[0]}' tag doesn't exist)"
end
when :mass_update
when :mass_update, :nuke
# okay
when :invalid_line
@@ -129,6 +131,9 @@ class BulkUpdateRequestProcessor
when :mass_update
TagBatchChangeJob.perform_later(args[0], args[1])
when :nuke
TagBatchChangeJob.perform_later(args[0], "-#{args[0]}")
when :rename
TagRenameJob.perform_later(args[0], args[1])
@@ -152,6 +157,8 @@ class BulkUpdateRequestProcessor
when :mass_update
tags = PostQueryBuilder.new(args[0]).tags + PostQueryBuilder.new(args[1]).tags
tags.reject(&:negated).reject(&:optional).reject(&:wildcard).map(&:name)
when :nuke
PostQueryBuilder.new(args[0]).tags.map(&:name)
when :change_category
args[0]
end
@@ -181,6 +188,14 @@ class BulkUpdateRequestProcessor
"#{command.to_s.tr("_", " ")} [[#{args[0]}]] -> [[#{args[1]}]]"
when :mass_update
"mass update {{#{args[0]}}} -> #{args[1]}"
when :nuke
query = PostQueryBuilder.new(args[0])
if query.is_simple_tag?
"nuke [[#{args[0]}]]"
else
"nuke {{#{args[0]}}}"
end
when :change_category
"category [[#{args[0]}]] -> #{args[1]}"
else

View File

@@ -252,6 +252,24 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
end
end
context "the nuke command" do
should "remove tags" do
@p1 = create(:post, tag_string: "foo")
@p2 = create(:post, tag_string: "bar")
@bur = create_bur!("nuke foo", @admin)
assert_equal("tagme", @p1.reload.tag_string)
end
should "remove pools" do
@pool = create(:pool)
@post = create(:post, tag_string: "bar pool:#{@pool.id}")
@bur = create_bur!("nuke pool:#{@pool.id}", @admin)
assert_equal([], @pool.post_ids)
end
end
context "that contains a mass update followed by an alias" do
should "make the alias take effect after the mass update" do
@p1 = create(:post, tag_string: "maid_dress")