From 4d698bf98b488dfb59d6164fe7f8fead2185dbc8 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Tue, 3 Jan 2017 15:04:47 -0800 Subject: [PATCH] add modaction helper --- app/logical/moderator/tag_batch_change.rb | 2 +- app/logical/user_deletion.rb | 2 +- app/models/ban.rb | 2 +- app/models/mod_action.rb | 4 ++++ app/models/pool.rb | 6 +++--- app/models/post.rb | 14 +++++++------- app/models/tag_alias.rb | 4 ++-- app/models/tag_implication.rb | 4 ++-- app/models/user.rb | 2 +- app/models/user_name_change_request.rb | 2 +- 10 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/logical/moderator/tag_batch_change.rb b/app/logical/moderator/tag_batch_change.rb index f84e28e13..6c8d2ac2b 100644 --- a/app/logical/moderator/tag_batch_change.rb +++ b/app/logical/moderator/tag_batch_change.rb @@ -12,7 +12,7 @@ module Moderator CurrentUser.without_safe_mode do CurrentUser.scoped(updater, updater_ip_addr) do - ModAction.create(:description => "processed mass update: #{antecedent} -> #{consequent}") + ModAction.log("processed mass update: #{antecedent} -> #{consequent}") ::Post.tag_match(antecedent).where("true /* Moderator::TagBatchChange#perform */").find_each do |post| post.reload diff --git a/app/logical/user_deletion.rb b/app/logical/user_deletion.rb index 326b0cf29..0b23215a8 100644 --- a/app/logical/user_deletion.rb +++ b/app/logical/user_deletion.rb @@ -30,7 +30,7 @@ class UserDeletion private def create_mod_action - ModAction.create(:description => "user ##{user.id} deleted") + ModAction.log("user ##{user.id} deleted") end def clear_tag_subscriptions diff --git a/app/models/ban.rb b/app/models/ban.rb index fe3cdfb3e..6cbf0d39b 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -100,6 +100,6 @@ class Ban < ActiveRecord::Base end def create_mod_action - ModAction.create(:description => %{Banned "#{user_name}":/users/#{user_id} until #{expires_at}}) + ModAction.log(%{Banned "#{user_name}":/users/#{user_id} until #{expires_at}}) end end diff --git a/app/models/mod_action.rb b/app/models/mod_action.rb index 035ef7cbe..fc63bfb14 100644 --- a/app/models/mod_action.rb +++ b/app/models/mod_action.rb @@ -15,6 +15,10 @@ class ModAction < ActiveRecord::Base q end + def self.log(desc) + create(:description => desc) + end + def initialize_creator self.creator_id = CurrentUser.id end diff --git a/app/models/pool.rb b/app/models/pool.rb index 11696c2fb..c99c2d81a 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -227,15 +227,15 @@ class Pool < ActiveRecord::Base end def create_mod_action_for_delete - ModAction.create(:description => "deleted pool ##{id} (name: #{name})") + ModAction.log("deleted pool ##{id} (name: #{name})") end def create_mod_action_for_undelete - ModAction.create(:description => "undeleted pool ##{id} (name: #{name})") + ModAction.log("undeleted pool ##{id} (name: #{name})") end def create_mod_action_for_destroy - ModAction.create(:description => "permanently deleted pool ##{id} name=#{name} post_ids=#{post_ids}") + ModAction.log("permanently deleted pool ##{id} name=#{name} post_ids=#{post_ids}") end def add!(post) diff --git a/app/models/post.rb b/app/models/post.rb index e138fc230..b1ebe0f38 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -332,7 +332,7 @@ class Post < ActiveRecord::Base PostApproval.create(user_id: CurrentUser.id, post_id: id) if is_deleted_was == true - ModAction.create(:description => "undeleted post ##{id}") + ModAction.log("undeleted post ##{id}") end save! @@ -1339,7 +1339,7 @@ class Post < ActiveRecord::Base return false end - ModAction.create(:description => "permanently deleted post ##{id}") + ModAction.log("permanently deleted post ##{id}") delete!(:without_mod_action => true) Post.without_timeout do give_favorites_to_parent @@ -1354,12 +1354,12 @@ class Post < ActiveRecord::Base def ban! update_column(:is_banned, true) - ModAction.create(:description => "banned post ##{id}") + ModAction.log("banned post ##{id}") end def unban! update_column(:is_banned, false) - ModAction.create(:description => "unbanned post ##{id}") + ModAction.log("unbanned post ##{id}") end def delete!(options = {}) @@ -1384,9 +1384,9 @@ class Post < ActiveRecord::Base unless options[:without_mod_action] if options[:reason] - ModAction.create(:description => "deleted post ##{id}, reason: #{options[:reason]}") + ModAction.log("deleted post ##{id}, reason: #{options[:reason]}") else - ModAction.create(:description => "deleted post ##{id}") + ModAction.log("deleted post ##{id}") end end end @@ -1410,7 +1410,7 @@ class Post < ActiveRecord::Base self.approver_id = CurrentUser.id save Post.expire_cache_for_all(tag_array) - ModAction.create(:description => "undeleted post ##{id}") + ModAction.log("undeleted post ##{id}") end end diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 8efb2c95c..ab224685f 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -332,7 +332,7 @@ class TagAlias < ActiveRecord::Base 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}") + ModAction.log("created #{status} #{alias_desc}") else # format the changes hash more nicely. change_desc = changes.except(:updated_at).map do |attribute, values| @@ -344,7 +344,7 @@ class TagAlias < ActiveRecord::Base end end.join(", ") - ModAction.create(:description => "updated #{alias_desc}\n#{change_desc}") + ModAction.log("updated #{alias_desc}\n#{change_desc}") end end end diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index b54f94a31..96d2a58b3 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -297,7 +297,7 @@ class TagImplication < ActiveRecord::Base 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}") + ModAction.log("created #{status} #{implication}") else # format the changes hash more nicely. change_desc = changes.except(:updated_at).map do |attribute, values| @@ -309,7 +309,7 @@ class TagImplication < ActiveRecord::Base end end.join(", ") - ModAction.create(:description => "updated #{implication}\n#{change_desc}") + ModAction.log("updated #{implication}\n#{change_desc}") end end end diff --git a/app/models/user.rb b/app/models/user.rb index 2ebe5366e..687699046 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -423,7 +423,7 @@ class User < ActiveRecord::Base def create_mod_action if level_changed? - ModAction.create(:description => %{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}}) + ModAction.log(%{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}}) end end diff --git a/app/models/user_name_change_request.rb b/app/models/user_name_change_request.rb index 4f12b024d..633d94f17 100644 --- a/app/models/user_name_change_request.rb +++ b/app/models/user_name_change_request.rb @@ -49,7 +49,7 @@ class UserNameChangeRequest < ActiveRecord::Base body = "Your name change request has been approved. Be sure to log in with your new user name." Dmail.create_split(:title => "Name change request approved", :body => body, :to_id => user_id) UserFeedback.create(:user_id => user_id, :category => "neutral", :body => "Name changed from #{original_name} to #{desired_name}") - ModAction.create(:description => "Name changed from #{original_name} to #{desired_name}") + ModAction.log("Name changed from #{original_name} to #{desired_name}") end def reject!(reason)