FIX: Use default locale for edit reason when owner of post gets changed

This commit is contained in:
Gerhard Schlager 2017-09-14 16:15:07 +02:00
parent efef422416
commit f3d3129113
2 changed files with 28 additions and 5 deletions

View File

@ -498,16 +498,22 @@ class Post < ActiveRecord::Base
def set_owner(new_user, actor, skip_revision = false)
return if user_id == new_user.id
edit_reason = I18n.t('change_owner.post_revision_text',
old_user: (self.user.username_lower rescue nil) || I18n.t('change_owner.deleted_user'),
new_user: new_user.username_lower
edit_reason = I18n.with_locale(SiteSetting.default_locale) do
I18n.t('change_owner.post_revision_text',
old_user: (self.user.username_lower rescue nil) || I18n.t('change_owner.deleted_user'),
new_user: new_user.username_lower
)
end
revise(
actor,
{ raw: self.raw, user_id: new_user.id, edit_reason: edit_reason },
bypass_bump: true, skip_revision: skip_revision
)
revise(actor, { raw: self.raw, user_id: new_user.id, edit_reason: edit_reason }, bypass_bump: true, skip_revision: skip_revision)
if post_number == topic.highest_post_number
topic.update_columns(last_post_user_id: new_user.id)
end
end
before_create do

View File

@ -919,6 +919,23 @@ describe Post do
expect(post.user).to eq(coding_horror)
expect(post.revisions.size).to eq(0)
end
it "uses default locale for edit reason" do
I18n.locale = 'de'
old_username = post.user.username_lower
post.set_owner(coding_horror, Discourse.system_user)
post.reload
expected_reason = I18n.with_locale(SiteSetting.default_locale) do
I18n.t('change_owner.post_revision_text',
old_user: old_username,
new_user: coding_horror.username_lower
)
end
expect(post.edit_reason).to eq(expected_reason)
end
end
describe ".rebake_old" do