aliases/implications: remove forum topic updating code.

Remove code for updating forum topics when an alias or implication is
approved or rejected. This code was only used when approving single
alias or implication requests. This is no longer used now that all
alias/implication requests are done through BURs.
This commit is contained in:
evazion
2020-03-10 20:48:08 -05:00
parent 6504d44223
commit 0e7632ed8a
12 changed files with 20 additions and 202 deletions

View File

@@ -1,7 +1,7 @@
class ProcessTagAliasJob < ApplicationJob class ProcessTagAliasJob < ApplicationJob
queue_as :bulk_update queue_as :bulk_update
def perform(tag_alias, update_topic: true) def perform(tag_alias)
tag_alias.process!(update_topic: update_topic) tag_alias.process!
end end
end end

View File

@@ -1,7 +1,7 @@
class ProcessTagImplicationJob < ApplicationJob class ProcessTagImplicationJob < ApplicationJob
queue_as :bulk_update queue_as :bulk_update
def perform(tag_implication, update_topic: true) def perform(tag_implication)
tag_implication.process!(update_topic: update_topic) tag_implication.process!
end end
end end

View File

@@ -114,24 +114,24 @@ class AliasAndImplicationImporter
raise Error, "Error: #{tag_alias.errors.full_messages.join("; ")} (create alias #{tag_alias.antecedent_name} -> #{tag_alias.consequent_name})" raise Error, "Error: #{tag_alias.errors.full_messages.join("; ")} (create alias #{tag_alias.antecedent_name} -> #{tag_alias.consequent_name})"
end end
tag_alias.rename_wiki_and_artist if rename_aliased_pages? tag_alias.rename_wiki_and_artist if rename_aliased_pages?
tag_alias.approve!(approver: approver, update_topic: false) tag_alias.approve!(approver: approver)
when :create_implication when :create_implication
tag_implication = TagImplication.create(creator: approver, forum_topic_id: forum_id, status: "pending", antecedent_name: token[1], consequent_name: token[2], skip_secondary_validations: skip_secondary_validations) tag_implication = TagImplication.create(creator: approver, forum_topic_id: forum_id, status: "pending", antecedent_name: token[1], consequent_name: token[2], skip_secondary_validations: skip_secondary_validations)
unless tag_implication.valid? unless tag_implication.valid?
raise Error, "Error: #{tag_implication.errors.full_messages.join("; ")} (create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name})" raise Error, "Error: #{tag_implication.errors.full_messages.join("; ")} (create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name})"
end end
tag_implication.approve!(approver: approver, update_topic: false) tag_implication.approve!(approver: approver)
when :remove_alias when :remove_alias
tag_alias = TagAlias.active.find_by(antecedent_name: token[1], consequent_name: token[2]) tag_alias = TagAlias.active.find_by(antecedent_name: token[1], consequent_name: token[2])
raise Error, "Alias for #{token[1]} not found" if tag_alias.nil? raise Error, "Alias for #{token[1]} not found" if tag_alias.nil?
tag_alias.reject!(update_topic: false) tag_alias.reject!
when :remove_implication when :remove_implication
tag_implication = TagImplication.active.find_by(antecedent_name: token[1], consequent_name: token[2]) tag_implication = TagImplication.active.find_by(antecedent_name: token[1], consequent_name: token[2])
raise Error, "Implication for #{token[1]} not found" if tag_implication.nil? raise Error, "Implication for #{token[1]} not found" if tag_implication.nil?
tag_implication.reject!(update_topic: false) tag_implication.reject!
when :mass_update when :mass_update
TagBatchChangeJob.perform_later(token[1], token[2], User.system, "127.0.0.1") TagBatchChangeJob.perform_later(token[1], token[2], User.system, "127.0.0.1")

View File

@@ -5,7 +5,6 @@ class ForumUpdater
@forum_topic = forum_topic @forum_topic = forum_topic
@forum_post = options[:forum_post] @forum_post = options[:forum_post]
@expected_title = options[:expected_title] @expected_title = options[:expected_title]
@skip_update = options[:skip_update]
end end
def update(message, title_tag = nil) def update(message, title_tag = nil)
@@ -32,7 +31,6 @@ class ForumUpdater
end end
def update_post(body) def update_post(body)
return if @skip_update
forum_post.update(body: "#{forum_post.body}\n\nEDIT: #{body}", skip_mention_notifications: true) forum_post.update(body: "#{forum_post.body}\n\nEDIT: #{body}", skip_mention_notifications: true)
end end
end end

View File

@@ -1,9 +0,0 @@
class TagAliasRequest
def self.command_string(antecedent_name, consequent_name, id = nil)
if id
return "[ta:#{id}]"
end
"create alias [[#{antecedent_name}]] -> [[#{consequent_name}]]"
end
end

View File

@@ -1,9 +0,0 @@
class TagImplicationRequest
def self.command_string(antecedent_name, consequent_name, id = nil)
if id
return "[ti:#{id}]"
end
"create implication [[#{antecedent_name}]] -> [[#{consequent_name}]]"
end
end

View File

@@ -67,8 +67,7 @@ class BulkUpdateRequest < ApplicationRecord
ForumUpdater.new( ForumUpdater.new(
forum_topic, forum_topic,
forum_post: post, forum_post: post,
expected_title: title, expected_title: title
skip_update: !TagRelationship::SUPPORT_HARD_CODED
) )
end end
end end
@@ -88,10 +87,6 @@ class BulkUpdateRequest < ApplicationRecord
end end
end end
def date_timestamp
Time.now.strftime("%Y-%m-%d")
end
def create_forum_topic def create_forum_topic
CurrentUser.as(user) do CurrentUser.as(user) do
self.forum_topic = ForumTopic.create(title: title, category_id: 1, creator: user) unless forum_topic.present? self.forum_topic = ForumTopic.create(title: title, category_id: 1, creator: user) unless forum_topic.present?

View File

@@ -5,32 +5,13 @@ class TagAlias < TagRelationship
validate :wiki_pages_present, on: :create, unless: :skip_secondary_validations validate :wiki_pages_present, on: :create, unless: :skip_secondary_validations
module ApprovalMethods module ApprovalMethods
def approve!(approver: CurrentUser.user, update_topic: true) def approve!(approver: CurrentUser.user)
update(approver: approver, status: "queued") update(approver: approver, status: "queued")
ProcessTagAliasJob.perform_later(self, update_topic: update_topic) ProcessTagAliasJob.perform_later(self)
end
end
module ForumMethods
def forum_updater
@forum_updater ||= begin
post = if forum_topic
forum_post || forum_topic.posts.where("body like ?", TagAliasRequest.command_string(antecedent_name, consequent_name, id) + "%").last
else
nil
end
ForumUpdater.new(
forum_topic,
forum_post: post,
expected_title: "Tag alias: #{antecedent_name} -> #{consequent_name}",
skip_update: !TagRelationship::SUPPORT_HARD_CODED
)
end
end end
end end
include ApprovalMethods include ApprovalMethods
include ForumMethods
def self.to_aliased(names) def self.to_aliased(names)
names = Array(names).map(&:to_s) names = Array(names).map(&:to_s)
@@ -39,7 +20,7 @@ class TagAlias < TagRelationship
names.map { |name| aliases[name] || name } names.map { |name| aliases[name] || name }
end end
def process!(update_topic: true) def process!
unless valid? unless valid?
raise errors.full_messages.join("; ") raise errors.full_messages.join("; ")
end end
@@ -50,13 +31,11 @@ class TagAlias < TagRelationship
move_saved_searches move_saved_searches
ensure_category_consistency ensure_category_consistency
update_posts update_posts
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
rename_wiki_and_artist rename_wiki_and_artist
update!(status: "active") update!(status: "active")
end end
rescue Exception => e rescue Exception => e
CurrentUser.scoped(approver) do CurrentUser.scoped(approver) do
forum_updater.update(failure_message(e), "FAILED") if update_topic
update(status: "error: #{e}") update(status: "error: #{e}")
end end
@@ -122,8 +101,6 @@ class TagAlias < TagRelationship
if antecedent_wiki.present? if antecedent_wiki.present?
if WikiPage.titled(consequent_name).blank? if WikiPage.titled(consequent_name).blank?
antecedent_wiki.update!(title: consequent_name) antecedent_wiki.update!(title: consequent_name)
else
forum_updater.update(conflict_message)
end end
end end
@@ -136,7 +113,7 @@ class TagAlias < TagRelationship
def wiki_pages_present def wiki_pages_present
if antecedent_wiki.present? && consequent_wiki.present? if antecedent_wiki.present? && consequent_wiki.present?
errors[:base] << conflict_message errors[:base] << "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary."
elsif antecedent_wiki.blank? && consequent_wiki.blank? elsif antecedent_wiki.blank? && consequent_wiki.blank?
errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page" errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page"
end end

View File

@@ -120,7 +120,7 @@ class TagImplication < TagRelationship
end end
module ApprovalMethods module ApprovalMethods
def process!(update_topic: true) def process!
unless valid? unless valid?
raise errors.full_messages.join("; ") raise errors.full_messages.join("; ")
end end
@@ -129,18 +129,15 @@ class TagImplication < TagRelationship
update(status: "processing") update(status: "processing")
update_posts update_posts
update(status: "active") update(status: "active")
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
end end
rescue Exception => e rescue Exception => e
forum_updater.update(failure_message(e), "FAILED") if update_topic
update(status: "error: #{e}") update(status: "error: #{e}")
DanbooruLogger.log(e, tag_implication_id: id, antecedent_name: antecedent_name, consequent_name: consequent_name) DanbooruLogger.log(e, tag_implication_id: id, antecedent_name: antecedent_name, consequent_name: consequent_name)
end end
def approve!(approver: CurrentUser.user, update_topic: true) def approve!(approver: CurrentUser.user)
update(approver: approver, status: "queued") update(approver: approver, status: "queued")
ProcessTagImplicationJob.perform_later(self, update_topic: update_topic) ProcessTagImplicationJob.perform_later(self)
end end
def create_mod_action def create_mod_action
@@ -162,20 +159,6 @@ class TagImplication < TagRelationship
ModAction.log("updated #{implication}\n#{change_desc}", :tag_implication_update) ModAction.log("updated #{implication}\n#{change_desc}", :tag_implication_update)
end end
end end
def forum_updater
post = if forum_topic
forum_post || forum_topic.posts.where("body like ?", TagImplicationRequest.command_string(antecedent_name, consequent_name, id) + "%").last
else
nil
end
ForumUpdater.new(
forum_topic,
forum_post: post,
expected_title: "Tag implication: #{antecedent_name} -> #{consequent_name}",
skip_update: !TagRelationship::SUPPORT_HARD_CODED
)
end
end end
include DescendantMethods include DescendantMethods

View File

@@ -1,7 +1,6 @@
class TagRelationship < ApplicationRecord class TagRelationship < ApplicationRecord
self.abstract_class = true self.abstract_class = true
SUPPORT_HARD_CODED = true
EXPIRY = 60 EXPIRY = 60
EXPIRY_WARNING = 55 EXPIRY_WARNING = 55
@@ -69,11 +68,8 @@ class TagRelationship < ApplicationRecord
user.is_admin? user.is_admin?
end end
def reject!(update_topic: true) def reject!
transaction do update!(status: "deleted")
update!(status: "deleted")
forum_updater.update(reject_message(CurrentUser.user), "REJECTED") if update_topic
end
end end
module SearchMethods module SearchMethods
@@ -145,32 +141,8 @@ class TagRelationship < ApplicationRecord
self.class.name.underscore.tr("_", " ") self.class.name.underscore.tr("_", " ")
end end
def approval_message(approver)
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has been approved by @#{approver.name}."
end
def failure_message(e = nil)
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} failed during processing. Reason: #{e}"
end
def reject_message(rejector)
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has been rejected by @#{rejector.name}."
end
def retirement_message def retirement_message
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has been retired." "The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] has been retired."
end
def conflict_message
"The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary."
end
def date_timestamp
Time.now.strftime("%Y-%m-%d")
end
def forum_link
"(forum ##{forum_post.id})" if forum_post.present?
end end
end end

View File

@@ -92,7 +92,7 @@ class TagAliasTest < ActiveSupport::TestCase
ti = FactoryBot.build(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", skip_secondary_validations: false) ti = FactoryBot.build(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", skip_secondary_validations: false)
assert(ti.invalid?) assert(ti.invalid?)
assert_includes(ti.errors[:base], "The tag alias [[aaa]] -> [[bbb]] has conflicting wiki pages. [[bbb]] should be updated to include information from [[aaa]] if necessary.") assert_includes(ti.errors[:base], "The tag alias [[aaa]] -> [[bbb]] has conflicting wiki pages. [[bbb]] should be updated to include information from [[aaa]] if necessary.")
end end
end end
@@ -198,66 +198,5 @@ class TagAliasTest < ActiveSupport::TestCase
assert_equal(1, tag2.reload.category) assert_equal(1, tag2.reload.category)
end end
context "with an associated forum topic" do
setup do
@admin = FactoryBot.create(:admin_user)
CurrentUser.scoped(@admin) do
@topic = FactoryBot.create(:forum_topic, :title => "Tag alias: aaa -> bbb")
@post = FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => TagAliasRequest.command_string("aaa", "bbb"))
@alias = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :forum_post => @post, :status => "pending")
end
end
context "and conflicting wiki pages" do
setup do
CurrentUser.scoped(@admin) do
@wiki1 = FactoryBot.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryBot.create(:wiki_page, :title => "bbb")
@alias.approve!(approver: @admin)
perform_enqueued_jobs
end
end
should "update the forum topic when approved" do
assert_equal("[APPROVED] Tag alias: aaa -> bbb", @topic.reload.title)
assert_match(/The tag alias .* been approved/m, @topic.posts.second.body)
end
should "warn about conflicting wiki pages when approved" do
assert_match(/has conflicting wiki pages/m, @topic.posts.third.body)
end
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.approve!(approver: @admin)
perform_enqueued_jobs
end
end
should "update the parent post" do
previous = @post.body
@alias.approve!(approver: @admin)
perform_enqueued_jobs
assert_not_equal(previous, @post.reload.body)
end
should "update the topic when rejected" do
assert_difference("ForumPost.count") do
@alias.reject!
end
end
should "update the topic when failed" do
@alias.stubs(:sleep).returns(true)
@alias.stubs(:update_posts).raises(Exception, "oh no")
@alias.process!
assert_equal("[FAILED] Tag alias: aaa -> bbb", @topic.reload.title)
assert_match(/error: oh no/, @alias.status)
assert_match(/The tag alias .* failed during processing/, @topic.posts.last.body)
end
end
end end
end end

View File

@@ -181,33 +181,5 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal([], TagImplication.tags_implied_by("d").map(&:name)) assert_equal([], TagImplication.tags_implied_by("d").map(&:name))
end end
end end
context "with an associated forum topic" do
setup do
@topic = FactoryBot.create(:forum_topic, :title => "Tag implication: aaa -> bbb")
@post = FactoryBot.create(:forum_post, topic_id: @topic.id, :body => TagImplicationRequest.command_string("aaa", "bbb"))
@implication = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :forum_post => @post, :status => "pending")
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@implication.approve!
perform_enqueued_jobs
end
assert_match(/The tag implication .* has been approved/, @post.reload.body)
assert_equal("[APPROVED] Tag implication: aaa -> bbb", @topic.reload.title)
end
should "update the topic when rejected" do
assert_difference("ForumPost.count") do
@implication.reject!
end
@post.reload
@topic.reload
assert_match(/The tag implication .* has been rejected/, @post.body)
assert_equal("[REJECTED] Tag implication: aaa -> bbb", @topic.title)
end
end
end end
end end