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:
@@ -1,7 +1,7 @@
|
||||
class ProcessTagAliasJob < ApplicationJob
|
||||
queue_as :bulk_update
|
||||
|
||||
def perform(tag_alias, update_topic: true)
|
||||
tag_alias.process!(update_topic: update_topic)
|
||||
def perform(tag_alias)
|
||||
tag_alias.process!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class ProcessTagImplicationJob < ApplicationJob
|
||||
queue_as :bulk_update
|
||||
|
||||
def perform(tag_implication, update_topic: true)
|
||||
tag_implication.process!(update_topic: update_topic)
|
||||
def perform(tag_implication)
|
||||
tag_implication.process!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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})"
|
||||
end
|
||||
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
|
||||
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?
|
||||
raise Error, "Error: #{tag_implication.errors.full_messages.join("; ")} (create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name})"
|
||||
end
|
||||
tag_implication.approve!(approver: approver, update_topic: false)
|
||||
tag_implication.approve!(approver: approver)
|
||||
|
||||
when :remove_alias
|
||||
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?
|
||||
tag_alias.reject!(update_topic: false)
|
||||
tag_alias.reject!
|
||||
|
||||
when :remove_implication
|
||||
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?
|
||||
tag_implication.reject!(update_topic: false)
|
||||
tag_implication.reject!
|
||||
|
||||
when :mass_update
|
||||
TagBatchChangeJob.perform_later(token[1], token[2], User.system, "127.0.0.1")
|
||||
|
||||
@@ -5,7 +5,6 @@ class ForumUpdater
|
||||
@forum_topic = forum_topic
|
||||
@forum_post = options[:forum_post]
|
||||
@expected_title = options[:expected_title]
|
||||
@skip_update = options[:skip_update]
|
||||
end
|
||||
|
||||
def update(message, title_tag = nil)
|
||||
@@ -32,7 +31,6 @@ class ForumUpdater
|
||||
end
|
||||
|
||||
def update_post(body)
|
||||
return if @skip_update
|
||||
forum_post.update(body: "#{forum_post.body}\n\nEDIT: #{body}", skip_mention_notifications: true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -67,8 +67,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
ForumUpdater.new(
|
||||
forum_topic,
|
||||
forum_post: post,
|
||||
expected_title: title,
|
||||
skip_update: !TagRelationship::SUPPORT_HARD_CODED
|
||||
expected_title: title
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -88,10 +87,6 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def date_timestamp
|
||||
Time.now.strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
def create_forum_topic
|
||||
CurrentUser.as(user) do
|
||||
self.forum_topic = ForumTopic.create(title: title, category_id: 1, creator: user) unless forum_topic.present?
|
||||
|
||||
@@ -5,32 +5,13 @@ class TagAlias < TagRelationship
|
||||
validate :wiki_pages_present, on: :create, unless: :skip_secondary_validations
|
||||
|
||||
module ApprovalMethods
|
||||
def approve!(approver: CurrentUser.user, update_topic: true)
|
||||
def approve!(approver: CurrentUser.user)
|
||||
update(approver: approver, status: "queued")
|
||||
ProcessTagAliasJob.perform_later(self, update_topic: update_topic)
|
||||
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
|
||||
ProcessTagAliasJob.perform_later(self)
|
||||
end
|
||||
end
|
||||
|
||||
include ApprovalMethods
|
||||
include ForumMethods
|
||||
|
||||
def self.to_aliased(names)
|
||||
names = Array(names).map(&:to_s)
|
||||
@@ -39,7 +20,7 @@ class TagAlias < TagRelationship
|
||||
names.map { |name| aliases[name] || name }
|
||||
end
|
||||
|
||||
def process!(update_topic: true)
|
||||
def process!
|
||||
unless valid?
|
||||
raise errors.full_messages.join("; ")
|
||||
end
|
||||
@@ -50,13 +31,11 @@ class TagAlias < TagRelationship
|
||||
move_saved_searches
|
||||
ensure_category_consistency
|
||||
update_posts
|
||||
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
|
||||
rename_wiki_and_artist
|
||||
update!(status: "active")
|
||||
end
|
||||
rescue Exception => e
|
||||
CurrentUser.scoped(approver) do
|
||||
forum_updater.update(failure_message(e), "FAILED") if update_topic
|
||||
update(status: "error: #{e}")
|
||||
end
|
||||
|
||||
@@ -122,8 +101,6 @@ class TagAlias < TagRelationship
|
||||
if antecedent_wiki.present?
|
||||
if WikiPage.titled(consequent_name).blank?
|
||||
antecedent_wiki.update!(title: consequent_name)
|
||||
else
|
||||
forum_updater.update(conflict_message)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,7 +113,7 @@ class TagAlias < TagRelationship
|
||||
|
||||
def wiki_pages_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?
|
||||
errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page"
|
||||
end
|
||||
|
||||
@@ -120,7 +120,7 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
|
||||
module ApprovalMethods
|
||||
def process!(update_topic: true)
|
||||
def process!
|
||||
unless valid?
|
||||
raise errors.full_messages.join("; ")
|
||||
end
|
||||
@@ -129,18 +129,15 @@ class TagImplication < TagRelationship
|
||||
update(status: "processing")
|
||||
update_posts
|
||||
update(status: "active")
|
||||
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
|
||||
end
|
||||
rescue Exception => e
|
||||
forum_updater.update(failure_message(e), "FAILED") if update_topic
|
||||
update(status: "error: #{e}")
|
||||
|
||||
DanbooruLogger.log(e, tag_implication_id: id, antecedent_name: antecedent_name, consequent_name: consequent_name)
|
||||
end
|
||||
|
||||
def approve!(approver: CurrentUser.user, update_topic: true)
|
||||
def approve!(approver: CurrentUser.user)
|
||||
update(approver: approver, status: "queued")
|
||||
ProcessTagImplicationJob.perform_later(self, update_topic: update_topic)
|
||||
ProcessTagImplicationJob.perform_later(self)
|
||||
end
|
||||
|
||||
def create_mod_action
|
||||
@@ -162,20 +159,6 @@ class TagImplication < TagRelationship
|
||||
ModAction.log("updated #{implication}\n#{change_desc}", :tag_implication_update)
|
||||
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
|
||||
|
||||
include DescendantMethods
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class TagRelationship < ApplicationRecord
|
||||
self.abstract_class = true
|
||||
|
||||
SUPPORT_HARD_CODED = true
|
||||
EXPIRY = 60
|
||||
EXPIRY_WARNING = 55
|
||||
|
||||
@@ -69,11 +68,8 @@ class TagRelationship < ApplicationRecord
|
||||
user.is_admin?
|
||||
end
|
||||
|
||||
def reject!(update_topic: true)
|
||||
transaction do
|
||||
update!(status: "deleted")
|
||||
forum_updater.update(reject_message(CurrentUser.user), "REJECTED") if update_topic
|
||||
end
|
||||
def reject!
|
||||
update!(status: "deleted")
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
@@ -145,32 +141,8 @@ class TagRelationship < ApplicationRecord
|
||||
self.class.name.underscore.tr("_", " ")
|
||||
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
|
||||
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] #{forum_link} 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?
|
||||
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] has been retired."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user