2013-04-11 16:04:20 -04:00
|
|
|
# Responsible for logging the actions of admins and moderators.
|
2013-07-23 17:58:26 -04:00
|
|
|
class StaffActionLogger
|
2013-04-11 16:04:20 -04:00
|
|
|
def initialize(admin)
|
|
|
|
@admin = admin
|
|
|
|
raise Discourse::InvalidParameters.new('admin is nil') unless @admin and @admin.is_a?(User)
|
|
|
|
end
|
|
|
|
|
2013-07-25 18:04:51 -04:00
|
|
|
def log_user_deletion(deleted_user, opts={})
|
2013-04-11 16:04:20 -04:00
|
|
|
raise Discourse::InvalidParameters.new('user is nil') unless deleted_user and deleted_user.is_a?(User)
|
2013-07-23 17:58:26 -04:00
|
|
|
StaffActionLog.create(
|
|
|
|
action: StaffActionLog.actions[:delete_user],
|
2013-07-25 18:04:51 -04:00
|
|
|
context: opts[:context], # should be the url from where the staff member deleted the user
|
2013-07-23 17:58:26 -04:00
|
|
|
staff_user_id: @admin.id,
|
2013-07-10 16:52:34 -04:00
|
|
|
target_user_id: deleted_user.id,
|
2013-07-25 18:04:51 -04:00
|
|
|
email: deleted_user.email,
|
|
|
|
ip_address: deleted_user.ip_address,
|
2013-04-11 16:04:20 -04:00
|
|
|
details: [:id, :username, :name, :created_at, :trust_level, :last_seen_at, :last_emailed_at].map { |x| "#{x}: #{deleted_user.send(x)}" }.join(', ')
|
|
|
|
)
|
|
|
|
end
|
2013-07-08 05:53:22 -04:00
|
|
|
|
2013-08-13 12:04:28 -04:00
|
|
|
def log_trust_level_change(user, old_trust_level, new_trust_level, opts={})
|
2013-07-08 05:53:22 -04:00
|
|
|
raise Discourse::InvalidParameters.new('user is nil') unless user and user.is_a?(User)
|
2013-08-13 12:04:28 -04:00
|
|
|
raise Discourse::InvalidParameters.new('old trust level is invalid') unless TrustLevel.levels.values.include? old_trust_level
|
2013-07-08 05:53:22 -04:00
|
|
|
raise Discourse::InvalidParameters.new('new trust level is invalid') unless TrustLevel.levels.values.include? new_trust_level
|
2013-07-23 17:58:26 -04:00
|
|
|
StaffActionLog.create!(
|
|
|
|
action: StaffActionLog.actions[:change_trust_level],
|
|
|
|
staff_user_id: @admin.id,
|
2013-08-07 17:01:59 -04:00
|
|
|
target_user_id: user.id,
|
2013-08-13 12:04:28 -04:00
|
|
|
details: "old trust level: #{old_trust_level}, new trust level: #{new_trust_level}"
|
2013-07-08 05:53:22 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|