aliases/implications: refactor to share approve/reject messages.
This commit is contained in:
@@ -43,25 +43,9 @@ class TagAlias < TagRelationship
|
||||
end
|
||||
end
|
||||
|
||||
def approval_message
|
||||
"The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) has been approved."
|
||||
end
|
||||
|
||||
def failure_message(e = nil)
|
||||
"The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) failed during processing. Reason: #{e}"
|
||||
end
|
||||
|
||||
def reject_message
|
||||
"The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) has been rejected."
|
||||
end
|
||||
|
||||
def conflict_message
|
||||
"The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) 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
|
||||
end
|
||||
|
||||
module ForumMethods
|
||||
|
||||
@@ -148,7 +148,7 @@ class TagImplication < TagRelationship
|
||||
update_posts
|
||||
update({ :status => "active" }, :as => CurrentUser.role)
|
||||
update_descendant_names_for_parents
|
||||
forum_updater.update("The tag implication #{antecedent_name} -> #{consequent_name} has been approved.", "APPROVED") if update_topic
|
||||
forum_updater.update(approval_message, "APPROVED") if update_topic
|
||||
end
|
||||
rescue Exception => e
|
||||
if tries < 5
|
||||
@@ -157,7 +157,7 @@ class TagImplication < TagRelationship
|
||||
retry
|
||||
end
|
||||
|
||||
forum_updater.update("The tag implication #{antecedent_name} -> #{consequent_name} failed during processing. Reason: #{e}", "FAILED") if update_topic
|
||||
forum_updater.update(failure_message(e), "FAILED") if update_topic
|
||||
update({ :status => "error: #{e}" }, :as => CurrentUser.role)
|
||||
|
||||
if Rails.env.production?
|
||||
@@ -186,7 +186,7 @@ class TagImplication < TagRelationship
|
||||
|
||||
def reject!
|
||||
update({ :status => "deleted", }, :as => CurrentUser.role)
|
||||
forum_updater.update("The tag implication #{antecedent_name} -> #{consequent_name} has been rejected.", "REJECTED")
|
||||
forum_updater.update(reject_message, "REJECTED")
|
||||
destroy
|
||||
end
|
||||
|
||||
@@ -210,10 +210,6 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
end
|
||||
|
||||
def date_timestamp
|
||||
Time.now.strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
def forum_updater
|
||||
@forum_updater ||= begin
|
||||
post = if forum_topic
|
||||
|
||||
@@ -117,5 +117,29 @@ class TagRelationship < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module MessageMethods
|
||||
def relationship
|
||||
# "TagAlias" -> "tag alias", "TagImplication" -> "tag implication"
|
||||
self.class.name.underscore.tr("_", " ")
|
||||
end
|
||||
|
||||
def approval_message
|
||||
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] has been approved."
|
||||
end
|
||||
|
||||
def failure_message(e = nil)
|
||||
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] failed during processing. Reason: #{e}"
|
||||
end
|
||||
|
||||
def reject_message
|
||||
"The #{relationship} [[#{antecedent_name}]] -> [[#{consequent_name}]] has been rejected."
|
||||
end
|
||||
|
||||
def date_timestamp
|
||||
Time.now.strftime("%Y-%m-%d")
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include MessageMethods
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user