FIX: improve context when user deletes self

This commit is contained in:
Arpit Jalan 2018-06-18 11:27:51 +05:30
parent 3f167ae5ce
commit f1d1207725
3 changed files with 14 additions and 3 deletions

View File

@ -81,9 +81,14 @@ class UserDestroyer
end
unless opts[:quiet]
StaffActionLogger.new(@actor == user ? Discourse.system_user : @actor).log_user_deletion(user, opts.slice(:context))
if @actor == user
deleted_by = Discourse.system_user
opts[:context] = I18n.t("staff_action_logs.user_delete_self", url: opts[:context])
else
deleted_by = @actor
end
StaffActionLogger.new(deleted_by).log_user_deletion(user, opts.slice(:context))
end
MessageBus.publish "/file-change", ["refresh"], user_ids: [u.id]
end
end

View File

@ -3897,3 +3897,4 @@ en:
not_found: "not found"
unknown: "unknown"
user_merged: "%{username} was merged into this account"
user_delete_self: "Deleted by self from %{url}"

View File

@ -71,10 +71,15 @@ describe UserDestroyer do
end
context 'user deletes self' do
let(:destroy_opts) { { delete_posts: true } }
let(:destroy_opts) { { delete_posts: true, context: "/u/username/preferences/account" } }
subject(:destroy) { UserDestroyer.new(@user).destroy(@user, destroy_opts) }
include_examples "successfully destroy a user"
it 'should log proper context' do
destroy
expect(UserHistory.where(action: UserHistory.actions[:delete_user]).last.context).to eq(I18n.t("staff_action_logs.user_delete_self", url: "/u/username/preferences/account"))
end
end
context "with a queued post" do