2013-07-23 17:58:26 -04:00
|
|
|
# StaffActionLog stores information about actions that staff members have taken,
|
2013-04-11 16:04:20 -04:00
|
|
|
# like deleting users, changing site settings, etc.
|
2013-07-23 17:58:26 -04:00
|
|
|
# Use the StaffActionLogger class to log records to this table.
|
|
|
|
class StaffActionLog < ActiveRecord::Base
|
|
|
|
belongs_to :staff_user, class_name: 'User'
|
|
|
|
belongs_to :target_user, class_name: 'User'
|
2013-04-11 16:04:20 -04:00
|
|
|
|
2013-07-23 17:58:26 -04:00
|
|
|
validates_presence_of :staff_user_id
|
2013-04-11 16:04:20 -04:00
|
|
|
validates_presence_of :action
|
|
|
|
|
|
|
|
def self.actions
|
2013-08-21 12:03:21 -04:00
|
|
|
@actions ||= Enum.new( :delete_user,
|
|
|
|
:change_trust_level,
|
|
|
|
:change_site_setting,
|
|
|
|
:change_site_customization,
|
|
|
|
:delete_site_customization)
|
2013-04-11 16:04:20 -04:00
|
|
|
end
|
2013-08-09 10:06:02 -04:00
|
|
|
|
|
|
|
def self.with_filters(filters)
|
|
|
|
query = self
|
|
|
|
if filters[:action_name] and action_id = StaffActionLog.actions[filters[:action_name].to_sym]
|
|
|
|
query = query.where('action = ?', action_id)
|
|
|
|
end
|
2013-08-09 16:58:57 -04:00
|
|
|
[:staff_user, :target_user].each do |key|
|
|
|
|
if filters[key] and obj_id = User.where(username_lower: filters[key].downcase).pluck(:id)
|
|
|
|
query = query.where("#{key.to_s}_id = ?", obj_id)
|
|
|
|
end
|
|
|
|
end
|
2013-08-20 13:50:51 -04:00
|
|
|
query = query.where("subject = ?", filters[:subject]) if filters[:subject]
|
2013-08-09 10:06:02 -04:00
|
|
|
query
|
|
|
|
end
|
2013-08-21 10:49:35 -04:00
|
|
|
|
|
|
|
def new_value_is_json?
|
2013-08-21 12:03:21 -04:00
|
|
|
[StaffActionLog.actions[:change_site_customization], StaffActionLog.actions[:delete_site_customization]].include?(action)
|
2013-08-21 10:49:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def previous_value_is_json?
|
|
|
|
new_value_is_json?
|
|
|
|
end
|
2013-04-11 16:04:20 -04:00
|
|
|
end
|
2013-05-23 22:48:32 -04:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
2013-07-23 17:58:26 -04:00
|
|
|
# Table name: staff_action_logs
|
2013-05-23 22:48:32 -04:00
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# action :integer not null
|
2013-07-23 17:58:26 -04:00
|
|
|
# staff_user_id :integer not null
|
2013-05-23 22:48:32 -04:00
|
|
|
# target_user_id :integer
|
|
|
|
# details :text
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2013-08-13 16:09:27 -04:00
|
|
|
# context :string(255)
|
|
|
|
# ip_address :string(255)
|
|
|
|
# email :string(255)
|
2013-08-27 20:42:58 -04:00
|
|
|
# subject :text
|
|
|
|
# previous_value :text
|
|
|
|
# new_value :text
|
2013-08-13 16:09:27 -04:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_staff_action_logs_on_action_and_id (action,id)
|
|
|
|
# index_staff_action_logs_on_staff_user_id_and_id (staff_user_id,id)
|
2013-08-27 20:42:58 -04:00
|
|
|
# index_staff_action_logs_on_subject_and_id (subject,id)
|
2013-08-13 16:09:27 -04:00
|
|
|
# index_staff_action_logs_on_target_user_id_and_id (target_user_id,id)
|
2013-05-23 22:48:32 -04:00
|
|
|
#
|
|
|
|
|