UX: Set silence_reason using the system locale

Previously we would use the user's locale, which can be confusing for moderators.
This commit is contained in:
David Taylor 2020-08-10 18:51:54 +01:00
parent fe7a7ecf6c
commit 4476680d4b
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
2 changed files with 25 additions and 6 deletions

View File

@ -157,12 +157,14 @@ class NewPostManager
result = manager.enqueue(reason)
if is_fast_typer?(manager)
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.new_user_typed_too_fast"))
elsif matches_auto_silence_regex?(manager)
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.content_matches_auto_silence_regex"))
elsif reason == :email_spam && is_first_post?(manager)
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.email_in_spam_header"))
I18n.with_locale(SiteSetting.default_locale) do
if is_fast_typer?(manager)
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.new_user_typed_too_fast"))
elsif matches_auto_silence_regex?(manager)
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.content_matches_auto_silence_regex"))
elsif reason == :email_spam && is_first_post?(manager)
UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.email_in_spam_header"))
end
end
result

View File

@ -182,6 +182,23 @@ describe NewPostManager do
end
end
context 'with a fast typer' do
let(:manager) { NewPostManager.new(topic.user, raw: 'this is new post content', topic_id: topic.id, first_post_checks: true) }
let(:user) { manager.user }
before do
user.update!(trust_level: 0)
end
it "adds the silence reason in the system locale" do
I18n.with_locale(:fr) do # Simulate french user
result = NewPostManager.default_handler(manager)
end
expect(user.silenced?).to eq(true)
expect(user.silence_reason).to eq(I18n.t("user.new_user_typed_too_fast", locale: :en))
end
end
end
context "new topic handler" do