discourse/app/models/staff_action_log.rb

51 lines
1.6 KiB
Ruby
Raw Normal View History

2013-07-24 05:58:26 +08:00
# StaffActionLog stores information about actions that staff members have taken,
# like deleting users, changing site settings, etc.
2013-07-24 05:58:26 +08: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-07-24 05:58:26 +08:00
validates_presence_of :staff_user_id
validates_presence_of :action
def self.actions
@actions ||= Enum.new(:delete_user, :change_trust_level, :change_site_setting)
end
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-10 04:58:57 +08: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
query
end
end
# == Schema Information
#
2013-07-24 05:58:26 +08:00
# Table name: staff_action_logs
#
# id :integer not null, primary key
# action :integer not null
2013-07-24 05:58:26 +08:00
# staff_user_id :integer not null
# target_user_id :integer
# details :text
# created_at :datetime not null
# updated_at :datetime not null
2013-08-14 04:09:27 +08:00
# context :string(255)
# ip_address :string(255)
# email :string(255)
#
# 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)
# index_staff_action_logs_on_target_user_id_and_id (target_user_id,id)
#