Skip to content

Commit

Permalink
Merge pull request #3496 from BrokenEagle/feat-mod-action-event-ids
Browse files Browse the repository at this point in the history
Add categories to mod actions
  • Loading branch information
r888888888 committed Jan 15, 2018
2 parents 20487e1 + dd8d80e commit dfd343f
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 37 deletions.
2 changes: 2 additions & 0 deletions app/controllers/forum_topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ def update
def destroy
check_privilege(@forum_topic)
@forum_topic.delete!
@forum_topic.create_mod_action_for_delete
flash[:notice] = "Topic deleted"
respond_with(@forum_topic)
end

def undelete
check_privilege(@forum_topic)
@forum_topic.undelete!
@forum_topic.create_mod_action_for_undelete
flash[:notice] = "Topic undeleted"
respond_with(@forum_topic)
end
Expand Down
2 changes: 1 addition & 1 deletion app/logical/bulk_revert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ConstraintTooGeneralError < Exception ; end
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
Expand Down
2 changes: 1 addition & 1 deletion app/logical/moderator/tag_batch_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def perform
end
end

ModAction.log("processed mass update: #{antecedent} -> #{consequent}")
ModAction.log("processed mass update: #{antecedent} -> #{consequent}",:mass_update)
end
end
end
2 changes: 1 addition & 1 deletion app/logical/user_deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def delete!
private

def create_mod_action
ModAction.log("user ##{user.id} deleted")
ModAction.log("user ##{user.id} deleted",:user_delete)
end

def clear_saved_searches
Expand Down
4 changes: 2 additions & 2 deletions app/logical/user_promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def promote!

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

Expand Down
2 changes: 2 additions & 0 deletions app/models/artist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def unban!
end

update_column(:is_banned, false)
ModAction.log("unbanned artist ##{id}",:artist_unban)
end
end
end
Expand All @@ -458,6 +459,7 @@ def ban!
end

update_column(:is_banned, true)
ModAction.log("banned artist ##{id}",:artist_ban)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/ban.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ def expired?
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
6 changes: 3 additions & 3 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class Comment < ApplicationRecord
before_validation :initialize_creator, :on => :create
before_validation :initialize_updater
after_create :update_last_commented_at_on_create
after_update(:if => lambda {|rec| CurrentUser.id != rec.creator_id}) do |rec|
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.name}")
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}",: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]
Expand Down
4 changes: 2 additions & 2 deletions app/models/forum_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions app/models/forum_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ForumTopic < ApplicationRecord
validates :title, :length => {:maximum => 255}
accepts_nested_attributes_for :original_post
after_update :update_orignal_post
after_save(:if => lambda {|rec| rec.is_locked? && rec.is_locked_changed?}) do |rec|
ModAction.log("locked forum topic ##{id} (title: #{title})",:forum_topic_lock)
end

module CategoryMethods
extend ActiveSupport::Concern
Expand Down Expand Up @@ -154,6 +157,14 @@ def visible?(user)
user.level >= min_level
end

def create_mod_action_for_delete
ModAction.log("deleted forum topic ##{id} (title: #{title})",:forum_topic_delete)
end

def create_mod_action_for_undelete
ModAction.log("undeleted forum topic ##{id} (title: #{title})",:forum_topic_undelete)
end

def initialize_is_deleted
self.is_deleted = false if is_deleted.nil?
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/ip_ban.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
69 changes: 66 additions & 3 deletions app/models/mod_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,54 @@ 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,
artist_ban: 184,
artist_unban: 185,
comment_update: 81,
comment_delete: 82,
forum_topic_delete: 202,
forum_topic_undelete: 203,
forum_topic_lock: 206,
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")
Expand All @@ -12,11 +59,27 @@ def self.search(params = {})
q = q.where("creator_id = ?", params[:creator_id].to_i)
end

if params[:creator_name].present?
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].mb_chars.downcase)
end

if params[:category].present?
q = q.attribute_matches(:category, params[:category])
end

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
Expand Down
8 changes: 2 additions & 6 deletions app/models/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,11 @@ def updater_can_edit_deleted
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})")
end

def create_mod_action_for_destroy
ModAction.log("permanently deleted pool ##{id} name=#{name} post_ids=#{post_ids}")
ModAction.log("undeleted pool ##{id} (name: #{name})",:pool_undelete)
end

def add!(post)
Expand Down
10 changes: 5 additions & 5 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ def expunge!

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
Expand All @@ -1378,12 +1378,12 @@ def expunge!

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 = {})
Expand All @@ -1406,7 +1406,7 @@ def delete!(reason, options = {})
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
Expand All @@ -1429,7 +1429,7 @@ def undelete!
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)
Expand Down
2 changes: 1 addition & 1 deletion app/models/post_approval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def validate_approval
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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/tag_alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ 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.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|
Expand All @@ -265,7 +265,7 @@ def create_mod_action
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
4 changes: 2 additions & 2 deletions app/models/tag_implication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ 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.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|
Expand All @@ -206,7 +206,7 @@ def create_mod_action
end
end.join(", ")

ModAction.log("updated #{implication}\n#{change_desc}")
ModAction.log("updated #{implication}\n#{change_desc}",:tag_implication_update)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ def is_approver?

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
Expand Down
4 changes: 2 additions & 2 deletions app/models/user_feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions app/views/mod_actions/_search.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= simple_form_for(:search, method: :get, url: mod_actions_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %>
<%= f.input :category, label: "Category", collection: ModAction.categories.map {|k,v| [k.capitalize.tr("_"," "), v]}, include_blank: true,selected: params[:search][:category] %>
<%= f.submit "Search" %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/mod_actions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<div id="c-mod-actions">
<div id="a-index">
<h1>Mod Actions</h1>

<%= render "search" %>

<table class="striped" width="100%">
<thead>
<tr>
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20180113211343_add_category_to_mod_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddCategoryToModActions < ActiveRecord::Migration
def change
ModAction.without_timeout do
add_column :mod_actions, :category, :integer
end
end
end

0 comments on commit dfd343f

Please sign in to comment.