* Remove the single alias and implication request forms. From now on, bulk update requests are the only way to request aliases or implications. * Remove the forum topic ID field from the bulk update request form. Instead, to attach a BUR to an existing topic you go to the topic then you click "Request alias/implication" at the top of the page. * Update the bulk update request form to give better examples for the script format and to explain the difference between aliases and implications.
110 lines
4.1 KiB
Ruby
110 lines
4.1 KiB
Ruby
module BulkUpdateRequestsHelper
|
|
def bur_script_example
|
|
<<~EOS
|
|
create alias kitty -> cat
|
|
remove alias kitty -> cat
|
|
|
|
create implication cat -> animal
|
|
remove implication cat -> animal
|
|
|
|
mass update kitty -> cat
|
|
category touhou -> copyright
|
|
EOS
|
|
end
|
|
|
|
def approved?(command, antecedent, consequent)
|
|
return false unless CurrentUser.is_moderator?
|
|
|
|
case command
|
|
when :create_alias
|
|
TagAlias.where(antecedent_name: antecedent, consequent_name: consequent, status: %w(active processing queued)).exists?
|
|
|
|
when :create_implication
|
|
TagImplication.where(antecedent_name: antecedent, consequent_name: consequent, status: %w(active processing queued)).exists?
|
|
|
|
when :remove_alias
|
|
TagAlias.where(antecedent_name: antecedent, consequent_name: consequent, status: "deleted").exists? || !TagAlias.where(antecedent_name: antecedent, consequent_name: consequent).exists?
|
|
|
|
when :remove_implication
|
|
TagImplication.where(antecedent_name: antecedent, consequent_name: consequent, status: "deleted").exists? || !TagImplication.where(antecedent_name: antecedent, consequent_name: consequent).exists?
|
|
|
|
when :change_category
|
|
tag, category = antecedent, consequent
|
|
Tag.where(name: tag, category: Tag.categories.value_for(category)).exists?
|
|
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
def failed?(command, antecedent, consequent)
|
|
return false unless CurrentUser.is_moderator?
|
|
|
|
case command
|
|
when :create_alias
|
|
TagAlias.where(antecedent_name: antecedent, consequent_name: consequent).where("status like ?", "error: %").exists?
|
|
|
|
when :create_implication
|
|
TagImplication.where(antecedent_name: antecedent, consequent_name: consequent).where("status like ?", "error: %").exists?
|
|
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
def script_with_line_breaks(script)
|
|
escaped_script = AliasAndImplicationImporter.tokenize(script).map do |cmd, arg1, arg2|
|
|
case cmd
|
|
when :create_alias, :create_implication, :remove_alias, :remove_implication, :mass_update, :change_category
|
|
if approved?(cmd, arg1, arg2)
|
|
btag = '<s class="approved">'
|
|
etag = '</s>'
|
|
elsif failed?(cmd, arg1, arg2)
|
|
btag = '<s class="failed">'
|
|
etag = "</s>"
|
|
else
|
|
btag = nil
|
|
etag = nil
|
|
end
|
|
end
|
|
|
|
case cmd
|
|
when :create_alias
|
|
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
|
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
|
|
|
"#{btag}create alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
|
|
|
when :create_implication
|
|
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
|
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
|
|
|
"#{btag}create implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
|
|
|
when :remove_alias
|
|
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
|
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
|
|
|
"#{btag}remove alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
|
|
|
when :remove_implication
|
|
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
|
arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i
|
|
|
|
"#{btag}remove implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}"
|
|
|
|
when :mass_update
|
|
"#{btag}mass update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2)) + "#{etag}"
|
|
|
|
when :change_category
|
|
arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i
|
|
|
|
"#{btag}category " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> (#{arg2})#{etag}"
|
|
|
|
end
|
|
end.join("\n")
|
|
|
|
escaped_script.gsub(/\n/m, "<br>").html_safe
|
|
end
|
|
end
|