Add category for mod actions
This commit is contained in:
@@ -7,7 +7,7 @@ class BulkRevert
|
||||
def process(creator, constraints = {})
|
||||
@constraints = constraints
|
||||
|
||||
ModAction.log("Processed bulk revert for #{constraints.inspect} by #{creator.name}")
|
||||
ModAction.log("Processed bulk revert for #{constraints.inspect} by #{creator.name}",:bulk_revert)
|
||||
|
||||
CurrentUser.scoped(creator) do
|
||||
ApplicationRecord.without_timeout do
|
||||
|
||||
@@ -31,7 +31,7 @@ module Moderator
|
||||
end
|
||||
end
|
||||
|
||||
ModAction.log("processed mass update: #{antecedent} -> #{consequent}")
|
||||
ModAction.log("processed mass update: #{antecedent} -> #{consequent}",:mass_update)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ class UserDeletion
|
||||
private
|
||||
|
||||
def create_mod_action
|
||||
ModAction.log("user ##{user.id} deleted")
|
||||
ModAction.log("user ##{user.id} deleted",:user_delete)
|
||||
end
|
||||
|
||||
def clear_saved_searches
|
||||
|
||||
@@ -37,11 +37,11 @@ private
|
||||
|
||||
def create_mod_actions
|
||||
if old_can_approve_posts != user.can_approve_posts?
|
||||
ModAction.log("\"#{promoter.name}\":/users/#{promoter.id} changed approval privileges for \"#{user.name}\":/users/#{user.id} from #{old_can_approve_posts} to [b]#{user.can_approve_posts?}[/b]")
|
||||
ModAction.log("\"#{promoter.name}\":/users/#{promoter.id} changed approval privileges for \"#{user.name}\":/users/#{user.id} from #{old_can_approve_posts} to [b]#{user.can_approve_posts?}[/b]",:user_approval_privilege)
|
||||
end
|
||||
|
||||
if old_can_upload_free != user.can_upload_free?
|
||||
ModAction.log("\"#{promoter.name}\":/users/#{promoter.id} changed unlimited upload privileges for \"#{user.name}\":/users/#{user.id} from #{old_can_upload_free} to [b]#{user.can_upload_free?}[/b]")
|
||||
ModAction.log("\"#{promoter.name}\":/users/#{promoter.id} changed unlimited upload privileges for \"#{user.name}\":/users/#{user.id} from #{old_can_upload_free} to [b]#{user.can_upload_free?}[/b]",:user_upload_privilege)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -126,6 +126,6 @@ class Ban < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_mod_action
|
||||
ModAction.log(%{Banned "#{user_name}":/users/#{user_id} until #{expires_at}})
|
||||
ModAction.log(%{Banned "#{user_name}":/users/#{user_id} until #{expires_at}},:user_ban)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,11 +12,11 @@ class Comment < ApplicationRecord
|
||||
before_validation :initialize_updater
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_update(:if => lambda {|rec| (!rec.is_deleted? || !rec.is_deleted_changed?) && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.name}")
|
||||
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.name}",:comment_update)
|
||||
end
|
||||
after_save :update_last_commented_at_on_destroy, :if => lambda {|rec| rec.is_deleted? && rec.is_deleted_changed?}
|
||||
after_save(:if => lambda {|rec| rec.is_deleted? && rec.is_deleted_changed? && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log("comment ##{rec.id} deleted by #{CurrentUser.name}")
|
||||
ModAction.log("comment ##{rec.id} deleted by #{CurrentUser.name}",:comment_delete)
|
||||
end
|
||||
attr_accessible :body, :post_id, :do_not_bump_post, :is_deleted, :as => [:member, :gold, :platinum, :builder, :moderator, :admin]
|
||||
attr_accessible :is_sticky, :as => [:moderator, :admin]
|
||||
|
||||
@@ -20,10 +20,10 @@ class ForumPost < ApplicationRecord
|
||||
before_destroy :validate_topic_is_unlocked
|
||||
after_save :delete_topic_if_original_post
|
||||
after_update(:if => lambda {|rec| rec.updater_id != rec.creator_id}) do |rec|
|
||||
ModAction.log("#{CurrentUser.name} updated forum ##{rec.id}")
|
||||
ModAction.log("#{CurrentUser.name} updated forum ##{rec.id}",:forum_post_update)
|
||||
end
|
||||
after_destroy(:if => lambda {|rec| rec.updater_id != rec.creator_id}) do |rec|
|
||||
ModAction.log("#{CurrentUser.name} deleted forum ##{rec.id}")
|
||||
ModAction.log("#{CurrentUser.name} deleted forum ##{rec.id}",:forum_post_delete)
|
||||
end
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
|
||||
@@ -7,10 +7,10 @@ class IpBan < ApplicationRecord
|
||||
validates_uniqueness_of :ip_addr, :if => lambda {|rec| rec.ip_addr =~ IP_ADDR_REGEX}
|
||||
attr_accessible :ip_addr, :reason
|
||||
after_create do |rec|
|
||||
ModAction.log("#{CurrentUser.name} created ip ban for #{rec.ip_addr}")
|
||||
ModAction.log("#{CurrentUser.name} created ip ban for #{rec.ip_addr}",:ip_ban_create)
|
||||
end
|
||||
after_destroy do |rec|
|
||||
ModAction.log("#{CurrentUser.name} deleted ip ban for #{rec.ip_addr}")
|
||||
ModAction.log("#{CurrentUser.name} deleted ip ban for #{rec.ip_addr}",:ip_ban_delete)
|
||||
end
|
||||
|
||||
def self.is_banned?(ip_addr)
|
||||
|
||||
@@ -2,7 +2,49 @@ class ModAction < ApplicationRecord
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
validates_presence_of :creator_id
|
||||
attr_accessible :description
|
||||
attr_accessible :description, :category
|
||||
|
||||
#####DIVISIONS#####
|
||||
#Groups: 0-999
|
||||
#Individual: 1000-1999
|
||||
#####Actions#####
|
||||
#Create: 0
|
||||
#Update: 1
|
||||
#Delete: 2
|
||||
#Undelete: 3
|
||||
#Ban: 4
|
||||
#Unban: 5
|
||||
#Misc: 6-19
|
||||
enum category: {
|
||||
user_delete: 2,
|
||||
user_ban: 4,
|
||||
user_name_change: 6,
|
||||
user_level: 7,
|
||||
user_approval_privilege: 8,
|
||||
user_upload_privilege: 9,
|
||||
user_feedback_update: 21,
|
||||
user_feedback_delete: 22,
|
||||
post_delete: 42,
|
||||
post_undelete: 43,
|
||||
post_ban: 44,
|
||||
post_unban: 45,
|
||||
post_permanent_delete: 46,
|
||||
pool_delete: 62,
|
||||
pool_undelete: 63,
|
||||
comment_update: 81,
|
||||
comment_delete: 82,
|
||||
forum_post_update: 101,
|
||||
forum_post_delete: 102,
|
||||
tag_alias_create: 120,
|
||||
tag_alias_update: 121,
|
||||
tag_implication_create: 140,
|
||||
tag_implication_update: 141,
|
||||
ip_ban_create: 160,
|
||||
ip_ban_delete: 162,
|
||||
mass_update: 1000,
|
||||
bulk_revert: 1001,
|
||||
other: 2000
|
||||
}
|
||||
|
||||
def self.search(params = {})
|
||||
q = where("true")
|
||||
@@ -15,8 +57,16 @@ class ModAction < ApplicationRecord
|
||||
q
|
||||
end
|
||||
|
||||
def self.log(desc)
|
||||
create(:description => desc)
|
||||
def category_id
|
||||
self.class.categories[category]
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
super + [:category_id]
|
||||
end
|
||||
|
||||
def self.log(desc, cat = :other)
|
||||
create(:description => desc,:category => categories[cat])
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
|
||||
@@ -218,11 +218,11 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_mod_action_for_delete
|
||||
ModAction.log("deleted pool ##{id} (name: #{name})")
|
||||
ModAction.log("deleted pool ##{id} (name: #{name})",:pool_delete)
|
||||
end
|
||||
|
||||
def create_mod_action_for_undelete
|
||||
ModAction.log("undeleted pool ##{id} (name: #{name})")
|
||||
ModAction.log("undeleted pool ##{id} (name: #{name})",:pool_undelete)
|
||||
end
|
||||
|
||||
def add!(post)
|
||||
|
||||
@@ -1371,7 +1371,7 @@ class Post < ApplicationRecord
|
||||
|
||||
transaction do
|
||||
Post.without_timeout do
|
||||
ModAction.log("permanently deleted post ##{id}")
|
||||
ModAction.log("permanently deleted post ##{id}",:post_permanent_delete)
|
||||
|
||||
give_favorites_to_parent
|
||||
update_children_on_destroy
|
||||
@@ -1387,12 +1387,12 @@ class Post < ApplicationRecord
|
||||
|
||||
def ban!
|
||||
update_column(:is_banned, true)
|
||||
ModAction.log("banned post ##{id}")
|
||||
ModAction.log("banned post ##{id}",:post_ban)
|
||||
end
|
||||
|
||||
def unban!
|
||||
update_column(:is_banned, false)
|
||||
ModAction.log("unbanned post ##{id}")
|
||||
ModAction.log("unbanned post ##{id}",:post_unban)
|
||||
end
|
||||
|
||||
def delete!(reason, options = {})
|
||||
@@ -1415,7 +1415,7 @@ class Post < ApplicationRecord
|
||||
give_favorites_to_parent if options[:move_favorites]
|
||||
|
||||
unless options[:without_mod_action]
|
||||
ModAction.log("deleted post ##{id}, reason: #{reason}")
|
||||
ModAction.log("deleted post ##{id}, reason: #{reason}",:post_delete)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1438,7 +1438,7 @@ class Post < ApplicationRecord
|
||||
self.approver_id = CurrentUser.id
|
||||
flags.each {|x| x.resolve!}
|
||||
save
|
||||
ModAction.log("undeleted post ##{id}")
|
||||
ModAction.log("undeleted post ##{id}",:post_undelete)
|
||||
end
|
||||
|
||||
def replace!(params)
|
||||
|
||||
@@ -28,7 +28,7 @@ class PostApproval < ApplicationRecord
|
||||
end
|
||||
|
||||
def approve_post
|
||||
ModAction.log("undeleted post ##{post_id}") if post.is_deleted
|
||||
ModAction.log("undeleted post ##{post_id}",:post_undelete) if post.is_deleted
|
||||
|
||||
post.flags.each(&:resolve!)
|
||||
post.update({ approver: user, is_flagged: false, is_pending: false, is_deleted: false }, without_protection: true)
|
||||
|
||||
@@ -253,7 +253,7 @@ class TagAlias < TagRelationship
|
||||
alias_desc = %Q("tag alias ##{id}":[#{Rails.application.routes.url_helpers.tag_alias_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
|
||||
if id_changed?
|
||||
ModAction.log("created #{status} #{alias_desc}")
|
||||
ModAction.log("created #{status} #{alias_desc}",:tag_alias_create)
|
||||
else
|
||||
# format the changes hash more nicely.
|
||||
change_desc = changes.except(:updated_at).map do |attribute, values|
|
||||
@@ -265,7 +265,7 @@ class TagAlias < TagRelationship
|
||||
end
|
||||
end.join(", ")
|
||||
|
||||
ModAction.log("updated #{alias_desc}\n#{change_desc}")
|
||||
ModAction.log("updated #{alias_desc}\n#{change_desc}",:tag_alias_update)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -194,7 +194,7 @@ class TagImplication < TagRelationship
|
||||
implication = %Q("tag implication ##{id}":[#{Rails.application.routes.url_helpers.tag_implication_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
|
||||
if id_changed?
|
||||
ModAction.log("created #{status} #{implication}")
|
||||
ModAction.log("created #{status} #{implication}",:tag_implication_create)
|
||||
else
|
||||
# format the changes hash more nicely.
|
||||
change_desc = changes.except(:updated_at).map do |attribute, values|
|
||||
@@ -206,7 +206,7 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
end.join(", ")
|
||||
|
||||
ModAction.log("updated #{implication}\n#{change_desc}")
|
||||
ModAction.log("updated #{implication}\n#{change_desc}",:tag_implication_update)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -439,10 +439,10 @@ class User < ApplicationRecord
|
||||
|
||||
def create_mod_action
|
||||
if level_changed?
|
||||
ModAction.log(%{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}})
|
||||
ModAction.log(%{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}},:user_level)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def set_per_page
|
||||
if per_page.nil? || !is_gold?
|
||||
self.per_page = Danbooru.config.posts_per_page
|
||||
|
||||
@@ -11,10 +11,10 @@ class UserFeedback < ApplicationRecord
|
||||
validate :user_is_not_creator
|
||||
after_create :create_dmail
|
||||
after_update(:if => lambda {|rec| CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} updated user feedback for "#{rec.user_name}":/users/#{rec.user_id}})
|
||||
ModAction.log(%{#{CurrentUser.name} updated user feedback for "#{rec.user_name}":/users/#{rec.user_id}},:user_feedback_update)
|
||||
end
|
||||
after_destroy(:if => lambda {|rec| CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} deleted user feedback for "#{rec.user_name}":/users/#{rec.user_id}})
|
||||
ModAction.log(%{#{CurrentUser.name} deleted user feedback for "#{rec.user_name}":/users/#{rec.user_id}},:user_feedback_delete)
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
|
||||
7
db/migrate/20180113211343_add_category_to_mod_actions.rb
Normal file
7
db/migrate/20180113211343_add_category_to_mod_actions.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class AddCategoryToModActions < ActiveRecord::Migration
|
||||
def change
|
||||
ModAction.without_timeout do
|
||||
add_column :mod_actions, :category, :integer
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2315,7 +2315,8 @@ CREATE TABLE mod_actions (
|
||||
creator_id integer NOT NULL,
|
||||
description text NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone
|
||||
updated_at timestamp without time zone,
|
||||
category integer
|
||||
);
|
||||
|
||||
|
||||
@@ -7547,3 +7548,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171219001521');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20171230220225');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20180113211343');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user