A platform for community discussion. Free, open, simple.
FIX: Incorrect locale in badge granter (#8749)
Krzysztof Kotlarekaa04349cfdf4
diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rbindex f5b31484575..620e3cd0b17 100644--- a/app/services/badge_granter.rb+++ b/app/services/badge_granter.rb@@ -380,11 +380,13 @@ class BadgeGranterSQLend- def self.send_notification(user_id, username, locale, badge)- use_default_locale = !SiteSetting.allow_user_locale && locale.blank?- notification_locale = use_default_locale ? SiteSetting.default_locale : locale+ def self.notification_locale(locale)+ use_default_locale = !SiteSetting.allow_user_locale || locale.blank?+ use_default_locale ? SiteSetting.default_locale : locale+ end- I18n.with_locale(notification_locale) do+ def self.send_notification(user_id, username, locale, badge)+ I18n.with_locale(notification_locale(locale)) doNotification.create!(user_id: user_id,notification_type: Notification.types[:granted_badge],diff --git a/spec/services/badge_granter_spec.rb b/spec/services/badge_granter_spec.rbindex 1606a27ea88..e91b755e628 100644--- a/spec/services/badge_granter_spec.rb+++ b/spec/services/badge_granter_spec.rb@@ -322,4 +322,20 @@ describe BadgeGranter doendend+ context 'notification locales' do+ it 'is using default locales when user locales are not set' do+ SiteSetting.allow_user_locale = true+ expect(BadgeGranter.notification_locale('')).to eq(SiteSetting.default_locale)+ end++ it 'is using default locales when user locales are set but is not allowed' do+ SiteSetting.allow_user_locale = false+ expect(BadgeGranter.notification_locale('pl_PL')).to eq(SiteSetting.default_locale)+ end++ it 'is using user locales when set and allowed' do+ SiteSetting.allow_user_locale = true+ expect(BadgeGranter.notification_locale('pl_PL')).to eq('pl_PL')+ end+ endend