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:
@@ -89,11 +89,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def approve!(approver_id)
|
def approve!(approver_id)
|
||||||
self.status = "queued"
|
update_attributes(:status => "queued", :approver_id => approver_id)
|
||||||
self.approver_id = approver_id
|
|
||||||
save
|
|
||||||
|
|
||||||
rename_wiki_and_artist
|
|
||||||
delay(:queue => "default").process!(true)
|
delay(:queue => "default").process!(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -103,6 +99,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
tries = 0
|
tries = 0
|
||||||
|
forum_message = []
|
||||||
|
|
||||||
begin
|
begin
|
||||||
admin = CurrentUser.user || approver || User.admins.first
|
admin = CurrentUser.user || approver || User.admins.first
|
||||||
@@ -113,7 +110,8 @@ class TagAlias < ActiveRecord::Base
|
|||||||
clear_all_cache
|
clear_all_cache
|
||||||
ensure_category_consistency
|
ensure_category_consistency
|
||||||
update_posts
|
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)
|
update({ :status => "active", :post_count => consequent_tag.post_count }, :as => CurrentUser.role)
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@@ -123,9 +121,18 @@ class TagAlias < ActiveRecord::Base
|
|||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
||||||
update_forum_topic_for_error(e)
|
forum_message << "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) failed during processing. Reason: #{e}"
|
||||||
update({ :status => "error: #{e}" }, :as => CurrentUser.role)
|
update({ :status => "error: #{e}" }, :as => approver.role)
|
||||||
NewRelic::Agent.notice_error(e, :custom_params => {:tag_alias_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -241,6 +248,8 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rename_wiki_and_artist
|
def rename_wiki_and_artist
|
||||||
|
message = ""
|
||||||
|
|
||||||
antecedent_wiki = WikiPage.titled(antecedent_name).first
|
antecedent_wiki = WikiPage.titled(antecedent_name).first
|
||||||
if antecedent_wiki.present?
|
if antecedent_wiki.present?
|
||||||
if WikiPage.titled(consequent_name).blank?
|
if WikiPage.titled(consequent_name).blank?
|
||||||
@@ -250,7 +259,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -264,6 +273,8 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
message
|
||||||
end
|
end
|
||||||
|
|
||||||
def deletable_by?(user)
|
def deletable_by?(user)
|
||||||
@@ -277,40 +288,14 @@ class TagAlias < ActiveRecord::Base
|
|||||||
deletable_by?(user)
|
deletable_by?(user)
|
||||||
end
|
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
|
def update_forum_topic_for_reject
|
||||||
if forum_topic
|
if forum_topic
|
||||||
forum_topic.posts.create(
|
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
|
||||||
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!
|
def reject!
|
||||||
update({ :status => "deleted", }, :as => CurrentUser.role)
|
update({ :status => "deleted", }, :as => CurrentUser.role)
|
||||||
clear_all_cache
|
clear_all_cache
|
||||||
|
|||||||
@@ -155,7 +155,10 @@ class TagImplication < ActiveRecord::Base
|
|||||||
|
|
||||||
update_forum_topic_for_error(e)
|
update_forum_topic_for_error(e)
|
||||||
update({ :status => "error: #{e}" }, :as => CurrentUser.role)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user