Skip to content

Commit

Permalink
FIX: improve context when user deletes self
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan committed Jun 18, 2018
1 parent 3f167ae commit f1d1207
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/services/user_destroyer.rb
Expand Up @@ -81,9 +81,14 @@ def destroy(user, opts = {})
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
Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Expand Up @@ -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}"
7 changes: 6 additions & 1 deletion spec/services/user_destroyer_spec.rb
Expand Up @@ -71,10 +71,15 @@
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
Expand Down

1 comment on commit f1d1207

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/system-user-is-automatically-deleted-a-user/89775/5

Please sign in to comment.