Merge wiki conflict and tag alias approval forum posts (#2715).

* Attribute the "tag alias has conflicting wiki pages" message to the
  alias approver, not to the first admin.
* Merge the conflict message and alias approval message into one forum post.
* Fix an error with NewRelic gem not installed in test environment.
This commit is contained in:
evazion
2016-10-13 10:56:11 +00:00
parent 24d44dd4f8
commit abbf834256
2 changed files with 26 additions and 38 deletions

View File

@@ -89,11 +89,7 @@ class TagAlias < ActiveRecord::Base
end
def approve!(approver_id)
self.status = "queued"
self.approver_id = approver_id
save
rename_wiki_and_artist
update_attributes(:status => "queued", :approver_id => approver_id)
delay(:queue => "default").process!(true)
end
@@ -103,6 +99,7 @@ class TagAlias < ActiveRecord::Base
end
tries = 0
forum_message = []
begin
admin = CurrentUser.user || approver || User.admins.first
@@ -113,7 +110,8 @@ class TagAlias < ActiveRecord::Base
clear_all_cache
ensure_category_consistency
update_posts
update_forum_topic_for_approve if update_topic
forum_message << "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) has been approved."
forum_message << rename_wiki_and_artist
update({ :status => "active", :post_count => consequent_tag.post_count }, :as => CurrentUser.role)
end
rescue Exception => e
@@ -123,9 +121,18 @@ class TagAlias < ActiveRecord::Base
retry
end
update_forum_topic_for_error(e)
update({ :status => "error: #{e}" }, :as => CurrentUser.role)
NewRelic::Agent.notice_error(e, :custom_params => {:tag_alias_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
forum_message << "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) failed during processing. Reason: #{e}"
update({ :status => "error: #{e}" }, :as => approver.role)
if Rails.env.production?
NewRelic::Agent.notice_error(e, :custom_params => {:tag_alias_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
end
ensure
if update_topic && forum_topic.present?
CurrentUser.scoped(approver, CurrentUser.ip_addr) do
forum_topic.posts.create(:body => forum_message.join("\n\n"))
end
end
end
end
@@ -241,6 +248,8 @@ class TagAlias < ActiveRecord::Base
end
def rename_wiki_and_artist
message = ""
antecedent_wiki = WikiPage.titled(antecedent_name).first
if antecedent_wiki.present?
if WikiPage.titled(consequent_name).blank?
@@ -250,7 +259,7 @@ class TagAlias < ActiveRecord::Base
)
end
else
update_forum_topic_for_wiki_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
end
@@ -264,6 +273,8 @@ class TagAlias < ActiveRecord::Base
end
end
end
message
end
def deletable_by?(user)
@@ -277,40 +288,14 @@ class TagAlias < ActiveRecord::Base
deletable_by?(user)
end
def update_forum_topic_for_approve
if forum_topic
forum_topic.posts.create(
:body => "The tag alias #{antecedent_name} -> #{consequent_name} has been approved."
)
end
end
def update_forum_topic_for_error(e)
if forum_topic
forum_topic.posts.create(
:body => "The tag alias #{antecedent_name} -> #{consequent_name} failed during processing. Reason: #{e}"
)
end
end
def update_forum_topic_for_reject
if forum_topic
forum_topic.posts.create(
:body => "The tag alias #{antecedent_name} -> #{consequent_name} has been rejected."
:body => "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) has been rejected."
)
end
end
def update_forum_topic_for_wiki_conflict
if forum_topic
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
forum_topic.posts.create(
:body => "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary."
)
end
end
end
def reject!
update({ :status => "deleted", }, :as => CurrentUser.role)
clear_all_cache

View File

@@ -155,7 +155,10 @@ class TagImplication < ActiveRecord::Base
update_forum_topic_for_error(e)
update({ :status => "error: #{e}" }, :as => CurrentUser.role)
NewRelic::Agent.notice_error(e, :custom_params => {:tag_implication_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
if Rails.env.production?
NewRelic::Agent.notice_error(e, :custom_params => {:tag_implication_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
end
end
end