mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
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:
parent
5f3e9131ed
commit
e076158789
@ -217,9 +217,13 @@ Discourse.AdminUser = Discourse.User.extend({
|
|||||||
var user = this;
|
var user = this;
|
||||||
|
|
||||||
var performDestroy = function(block) {
|
var performDestroy = function(block) {
|
||||||
|
var formData = { context: window.location.pathname };
|
||||||
|
if (block) {
|
||||||
|
formData["block_email"] = true;
|
||||||
|
}
|
||||||
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
data: block ? {block_email: true} : {}
|
data: formData
|
||||||
}).then(function(data) {
|
}).then(function(data) {
|
||||||
if (data.deleted) {
|
if (data.deleted) {
|
||||||
bootbox.alert(I18n.t("admin.user.deleted"), function() {
|
bootbox.alert(I18n.t("admin.user.deleted"), function() {
|
||||||
|
@ -118,7 +118,7 @@ class Admin::UsersController < Admin::AdminController
|
|||||||
user = User.where(id: params[:id]).first
|
user = User.where(id: params[:id]).first
|
||||||
guardian.ensure_can_delete_user!(user)
|
guardian.ensure_can_delete_user!(user)
|
||||||
begin
|
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}
|
render json: {deleted: true}
|
||||||
else
|
else
|
||||||
render json: {deleted: false, user: AdminDetailedUserSerializer.new(user, root: false).as_json}
|
render json: {deleted: false, user: AdminDetailedUserSerializer.new(user, root: false).as_json}
|
||||||
|
@ -5,17 +5,20 @@ class StaffActionLogger
|
|||||||
raise Discourse::InvalidParameters.new('admin is nil') unless @admin and @admin.is_a?(User)
|
raise Discourse::InvalidParameters.new('admin is nil') unless @admin and @admin.is_a?(User)
|
||||||
end
|
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)
|
raise Discourse::InvalidParameters.new('user is nil') unless deleted_user and deleted_user.is_a?(User)
|
||||||
StaffActionLog.create(
|
StaffActionLog.create(
|
||||||
action: StaffActionLog.actions[:delete_user],
|
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,
|
staff_user_id: @admin.id,
|
||||||
target_user_id: deleted_user.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(', ')
|
details: [:id, :username, :name, :created_at, :trust_level, :last_seen_at, :last_emailed_at].map { |x| "#{x}: #{deleted_user.send(x)}" }.join(', ')
|
||||||
)
|
)
|
||||||
end
|
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('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
|
raise Discourse::InvalidParameters.new('new trust level is invalid') unless TrustLevel.levels.values.include? new_trust_level
|
||||||
StaffActionLog.create!(
|
StaffActionLog.create!(
|
||||||
|
@ -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
|
@ -28,7 +28,7 @@ class UserDestroyer
|
|||||||
b.record_match! if b
|
b.record_match! if b
|
||||||
end
|
end
|
||||||
Post.with_deleted.where(user_id: user.id).update_all("nuked_user = true")
|
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?
|
DiscourseHub.unregister_nickname(user.username) if SiteSetting.call_discourse_hub?
|
||||||
MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id]
|
MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id]
|
||||||
end
|
end
|
||||||
|
@ -55,7 +55,7 @@ describe UserDestroyer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should log the action' do
|
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
|
destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user