add modaction helper

This commit is contained in:
Albert Yi
2017-01-03 15:04:47 -08:00
parent ad4b55c334
commit 4d698bf98b
10 changed files with 23 additions and 19 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)