Merge pull request #2726 from evazion/feat-log-tag-aliases+implications
Log tag aliases+implications
This commit is contained in:
@@ -4,6 +4,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
before_save :ensure_tags_exist
|
before_save :ensure_tags_exist
|
||||||
after_save :clear_all_cache
|
after_save :clear_all_cache
|
||||||
after_destroy :clear_all_cache
|
after_destroy :clear_all_cache
|
||||||
|
after_save :create_mod_action
|
||||||
before_validation :initialize_creator, :on => :create
|
before_validation :initialize_creator, :on => :create
|
||||||
before_validation :normalize_names
|
before_validation :normalize_names
|
||||||
validates_format_of :status, :with => /\A(active|deleted|pending|processing|queued|error: .*)\Z/
|
validates_format_of :status, :with => /\A(active|deleted|pending|processing|queued|error: .*)\Z/
|
||||||
@@ -106,15 +107,14 @@ class TagAlias < ActiveRecord::Base
|
|||||||
begin
|
begin
|
||||||
admin = CurrentUser.user || approver || User.admins.first
|
admin = CurrentUser.user || approver || User.admins.first
|
||||||
CurrentUser.scoped(admin, "127.0.0.1") do
|
CurrentUser.scoped(admin, "127.0.0.1") do
|
||||||
update_column(:status, "processing")
|
update({ :status => "processing" }, :as => CurrentUser.role)
|
||||||
move_aliases_and_implications
|
move_aliases_and_implications
|
||||||
move_saved_searches
|
move_saved_searches
|
||||||
clear_all_cache
|
clear_all_cache
|
||||||
ensure_category_consistency
|
ensure_category_consistency
|
||||||
update_posts
|
update_posts
|
||||||
update_forum_topic_for_approve if update_topic
|
update_forum_topic_for_approve if update_topic
|
||||||
update_column(:post_count, consequent_tag.post_count)
|
update({ :status => "active", :post_count => consequent_tag.post_count }, :as => CurrentUser.role)
|
||||||
update_column(:status, "active")
|
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
if tries < 5
|
if tries < 5
|
||||||
@@ -124,7 +124,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
update_forum_topic_for_error(e)
|
update_forum_topic_for_error(e)
|
||||||
update_column(:status, "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})
|
NewRelic::Agent.notice_error(e, :custom_params => {:tag_alias_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -312,7 +312,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reject!
|
def reject!
|
||||||
update_column(:status, "deleted")
|
update({ :status => "deleted", }, :as => CurrentUser.role)
|
||||||
clear_all_cache
|
clear_all_cache
|
||||||
update_forum_topic_for_reject
|
update_forum_topic_for_reject
|
||||||
destroy
|
destroy
|
||||||
@@ -340,4 +340,24 @@ class TagAlias < ActiveRecord::Base
|
|||||||
execute_sql("UPDATE tag_aliases SET post_count = tags.post_count FROM tags WHERE tags.name = tag_aliases.consequent_name")
|
execute_sql("UPDATE tag_aliases SET post_count = tags.post_count FROM tags WHERE tags.name = tag_aliases.consequent_name")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_mod_action
|
||||||
|
alias_desc = %Q("tag alias ##{id}":[#{Rails.application.routes.url_helpers.tag_alias_path(self)}] ([[#{antecedent_name}]] -> [[#{consequent_name}]]))
|
||||||
|
|
||||||
|
if id_changed?
|
||||||
|
ModAction.create(:description => "created #{status} #{alias_desc}.")
|
||||||
|
else
|
||||||
|
# format the changes hash more nicely.
|
||||||
|
change_desc = changes.except(:updated_at).map do |attribute, values|
|
||||||
|
old, new = values[0], values[1]
|
||||||
|
if old.nil?
|
||||||
|
%Q(set #{attribute} to "#{new}")
|
||||||
|
else
|
||||||
|
%Q(changed #{attribute} from "#{old}" to "#{new}")
|
||||||
|
end
|
||||||
|
end.join(", ")
|
||||||
|
|
||||||
|
ModAction.create(:description => "updated #{alias_desc}: #{change_desc}.")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ class TagImplication < ActiveRecord::Base
|
|||||||
before_save :update_descendant_names
|
before_save :update_descendant_names
|
||||||
after_save :update_descendant_names_for_parents
|
after_save :update_descendant_names_for_parents
|
||||||
after_destroy :update_descendant_names_for_parents
|
after_destroy :update_descendant_names_for_parents
|
||||||
|
after_save :create_mod_action
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
belongs_to :approver, :class_name => "User"
|
belongs_to :approver, :class_name => "User"
|
||||||
belongs_to :forum_topic
|
belongs_to :forum_topic
|
||||||
@@ -57,7 +58,7 @@ class TagImplication < ActiveRecord::Base
|
|||||||
def update_descendant_names!
|
def update_descendant_names!
|
||||||
clear_descendants_cache
|
clear_descendants_cache
|
||||||
update_descendant_names
|
update_descendant_names
|
||||||
update_column(:descendant_names, descendant_names)
|
update({ :descendant_names => descendant_names }, :as => CurrentUser.role)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_descendant_names_for_parents
|
def update_descendant_names_for_parents
|
||||||
@@ -139,9 +140,9 @@ class TagImplication < ActiveRecord::Base
|
|||||||
begin
|
begin
|
||||||
admin = CurrentUser.user || approver || User.admins.first
|
admin = CurrentUser.user || approver || User.admins.first
|
||||||
CurrentUser.scoped(admin, "127.0.0.1") do
|
CurrentUser.scoped(admin, "127.0.0.1") do
|
||||||
update_column(:status, "processing")
|
update({ :status => "processing" }, :as => CurrentUser.role)
|
||||||
update_posts
|
update_posts
|
||||||
update_column(:status, "active")
|
update({ :status => "active" }, :as => CurrentUser.role)
|
||||||
update_descendant_names_for_parents
|
update_descendant_names_for_parents
|
||||||
update_forum_topic_for_approve if update_topic
|
update_forum_topic_for_approve if update_topic
|
||||||
end
|
end
|
||||||
@@ -153,7 +154,7 @@ class TagImplication < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
update_forum_topic_for_error(e)
|
update_forum_topic_for_error(e)
|
||||||
update_column(:status, "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})
|
NewRelic::Agent.notice_error(e, :custom_params => {:tag_implication_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -287,7 +288,28 @@ class TagImplication < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reject!
|
def reject!
|
||||||
|
update({ :status => "deleted", }, :as => CurrentUser.role)
|
||||||
update_forum_topic_for_reject
|
update_forum_topic_for_reject
|
||||||
destroy
|
destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_mod_action
|
||||||
|
implication = %Q("tag implication ##{id}":[#{Rails.application.routes.url_helpers.tag_implication_path(self)}] ([[#{antecedent_name}]] -> [[#{consequent_name}]]))
|
||||||
|
|
||||||
|
if id_changed?
|
||||||
|
ModAction.create(:description => "created #{status} #{implication}.")
|
||||||
|
else
|
||||||
|
# format the changes hash more nicely.
|
||||||
|
change_desc = changes.except(:updated_at).map do |attribute, values|
|
||||||
|
old, new = values[0], values[1]
|
||||||
|
if old.nil?
|
||||||
|
%Q(set #{attribute} to "#{new}")
|
||||||
|
else
|
||||||
|
%Q(changed #{attribute} from "#{old}" to "#{new}")
|
||||||
|
end
|
||||||
|
end.join(", ")
|
||||||
|
|
||||||
|
ModAction.create(:description => "updated #{implication}: #{change_desc}.")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,12 +25,32 @@ class TagImplicationRequestsControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "create action" do
|
context "create action" do
|
||||||
should "render" do
|
should "create forum post" do
|
||||||
assert_difference("ForumTopic.count", 1) do
|
assert_difference("ForumTopic.count", 1) do
|
||||||
post :create, {:tag_implication_request => {:antecedent_name => "aaa", :consequent_name => "bbb", :reason => "ccc", :skip_secondary_validations => true}}, {:user_id => @user.id}
|
post :create, {:tag_implication_request => {:antecedent_name => "aaa", :consequent_name => "bbb", :reason => "ccc", :skip_secondary_validations => true}}, {:user_id => @user.id}
|
||||||
end
|
end
|
||||||
assert_redirected_to(forum_topic_path(ForumTopic.last))
|
assert_redirected_to(forum_topic_path(ForumTopic.last))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "create a pending implication" do
|
||||||
|
params = {
|
||||||
|
:tag_implication_request => {
|
||||||
|
:antecedent_name => "foo",
|
||||||
|
:consequent_name => "bar",
|
||||||
|
:reason => "blah blah",
|
||||||
|
:skip_secondary_validations => true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post :create, params, {:user_id => @user.id}
|
||||||
|
|
||||||
|
tir = assigns(:tag_implication_request)
|
||||||
|
assert_redirected_to(forum_topic_path(tir.forum_topic))
|
||||||
|
|
||||||
|
assert("foo", tir.tag_implication.antecedent_name)
|
||||||
|
assert("bar", tir.tag_implication.consequent_name)
|
||||||
|
assert("pending", tir.tag_implication.status)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user