Add ip_address, email, and context to staff_action_logs table. Context should usually be the url from which the staff member performed the action, but could be any string that describes what the staff member was doing when the action was performed.

This commit is contained in:
Neil Lalonde 2013-07-25 18:04:51 -04:00
parent 5f3e9131ed
commit e076158789
6 changed files with 20 additions and 6 deletions

View File

@ -217,9 +217,13 @@ Discourse.AdminUser = Discourse.User.extend({
var user = this;
var performDestroy = function(block) {
var formData = { context: window.location.pathname };
if (block) {
formData["block_email"] = true;
}
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
type: 'DELETE',
data: block ? {block_email: true} : {}
data: formData
}).then(function(data) {
if (data.deleted) {
bootbox.alert(I18n.t("admin.user.deleted"), function() {

View File

@ -118,7 +118,7 @@ class Admin::UsersController < Admin::AdminController
user = User.where(id: params[:id]).first
guardian.ensure_can_delete_user!(user)
begin
if UserDestroyer.new(current_user).destroy(user, params.slice(:delete_posts, :block_email))
if UserDestroyer.new(current_user).destroy(user, params.slice(:delete_posts, :block_email, :context))
render json: {deleted: true}
else
render json: {deleted: false, user: AdminDetailedUserSerializer.new(user, root: false).as_json}

View File

@ -5,17 +5,20 @@ class StaffActionLogger
raise Discourse::InvalidParameters.new('admin is nil') unless @admin and @admin.is_a?(User)
end
def log_user_deletion(deleted_user)
def log_user_deletion(deleted_user, opts={})
raise Discourse::InvalidParameters.new('user is nil') unless deleted_user and deleted_user.is_a?(User)
StaffActionLog.create(
action: StaffActionLog.actions[:delete_user],
context: opts[:context], # should be the url from where the staff member deleted the user
staff_user_id: @admin.id,
target_user_id: deleted_user.id,
email: deleted_user.email,
ip_address: deleted_user.ip_address,
details: [:id, :username, :name, :created_at, :trust_level, :last_seen_at, :last_emailed_at].map { |x| "#{x}: #{deleted_user.send(x)}" }.join(', ')
)
end
def log_trust_level_change(user, new_trust_level)
def log_trust_level_change(user, new_trust_level, opts={})
raise Discourse::InvalidParameters.new('user is nil') unless user and user.is_a?(User)
raise Discourse::InvalidParameters.new('new trust level is invalid') unless TrustLevel.levels.values.include? new_trust_level
StaffActionLog.create!(

View File

@ -0,0 +1,7 @@
class AddMoreToStaffActionLog < ActiveRecord::Migration
def change
add_column :staff_action_logs, :context, :string
add_column :staff_action_logs, :ip_address, :string
add_column :staff_action_logs, :email, :string
end
end

View File

@ -28,7 +28,7 @@ class UserDestroyer
b.record_match! if b
end
Post.with_deleted.where(user_id: user.id).update_all("nuked_user = true")
StaffActionLogger.new(@admin).log_user_deletion(user)
StaffActionLogger.new(@admin).log_user_deletion(user, opts.slice(:context))
DiscourseHub.unregister_nickname(user.username) if SiteSetting.call_discourse_hub?
MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id]
end

View File

@ -55,7 +55,7 @@ describe UserDestroyer do
end
it 'should log the action' do
StaffActionLogger.any_instance.expects(:log_user_deletion).with(@user).once
StaffActionLogger.any_instance.expects(:log_user_deletion).with(@user, anything).once
destroy
end