Skip to content

A platform for community discussion. Free, open, simple.

FIX: broken select badge as user title (#5474)

Joffrey JAFFEUX642645ba9a6b
diff --git a/app/assets/javascripts/discourse/templates/components/badge-title.hbs b/app/assets/javascripts/discourse/templates/components/badge-title.hbs
index 8101829c4d1..0ac803fdad8 100644
--- a/app/assets/javascripts/discourse/templates/components/badge-title.hbs
+++ b/app/assets/javascripts/discourse/templates/components/badge-title.hbs
@@ -10,7 +10,10 @@
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
- {{combo-box value=selectedUserBadgeId nameProperty="badge.name" content=selectableUserBadges}}
+ {{combo-box
+ value=selectedUserBadgeId
+ nameProperty="badge.name"
+ content=selectableUserBadges}}
</div>
</div>
diff --git a/app/assets/javascripts/discourse/templates/user/badge-title.hbs b/app/assets/javascripts/discourse/templates/user/badge-title.hbs
index f51fbd234bc..305593c49a9 100644
--- a/app/assets/javascripts/discourse/templates/user/badge-title.hbs
+++ b/app/assets/javascripts/discourse/templates/user/badge-title.hbs
@@ -1 +1,4 @@
-{{badge-title selectableUserBadges=selectableUserBadges user=user}}
+{{badge-title
+ selectedUserBadgeId=selectedUserBadgeId
+ selectableUserBadges=selectableUserBadges
+ user=user}}
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c81c28dc849..260586f154e 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -178,7 +178,7 @@ class UsersController < ApplicationController
user_badge = UserBadge.find_by(id: params[:user_badge_id])
if user_badge && user_badge.user == user && user_badge.badge.allow_title?
- user.title = user_badge.badge.name
+ user.title = user_badge.badge.display_name
user.user_profile.badge_granted_title = true
user.save!
user.user_profile.save!
diff --git a/config/locales/client.ca.yml b/config/locales/client.ca.yml
index 39c90056492..f767499825e 100644
--- a/config/locales/client.ca.yml
+++ b/config/locales/client.ca.yml
@@ -2021,7 +2021,7 @@ ca:
one: "1 concedit"
other: "%{count} concedits"
select_badge_for_title: Tria un distintiu per fer-lo servir com al teu títol
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Començant
diff --git a/config/locales/client.cs.yml b/config/locales/client.cs.yml
index 2681c52dfc1..e2fad4348eb 100644
--- a/config/locales/client.cs.yml
+++ b/config/locales/client.cs.yml
@@ -2065,7 +2065,7 @@ cs:
few: "%{count} přidělen"
other: "%{count} přidělen"
select_badge_for_title: Vyberte odznak, který chcete použít jako svůj titul
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Jak začít?
diff --git a/config/locales/client.da.yml b/config/locales/client.da.yml
index a2e70cf9a94..124d0288731 100644
--- a/config/locales/client.da.yml
+++ b/config/locales/client.da.yml
@@ -2085,7 +2085,7 @@ da:
one: "1 tildelt"
other: "%{count} tildelt"
select_badge_for_title: Vælg en badge, du vil bruge som din titel
- none: "<ingen>"
+ none: "(ingen)"
badge_grouping:
getting_started:
name: Sådan kommer du i gang
diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml
index 34969a65bed..b1bb1534baa 100644
--- a/config/locales/client.de.yml
+++ b/config/locales/client.de.yml
@@ -2267,7 +2267,7 @@ de:
one: "1-mal verliehen"
other: "%{count}-mal verliehen"
select_badge_for_title: Wähle ein Abzeichen als deinen Titel aus
- none: "<keines>"
+ none: "(keines)"
badge_grouping:
getting_started:
name: Erste Schritte
diff --git a/config/locales/client.el.yml b/config/locales/client.el.yml
index 0e4da15cb91..68e89828da3 100644
--- a/config/locales/client.el.yml
+++ b/config/locales/client.el.yml
@@ -2214,7 +2214,7 @@ el:
one: "1 χορηγήθηκε"
other: "%{count} χορηγήθηκε"
select_badge_for_title: Επίλεξε ένα παράσημο για να χρησιμοποιήσεις ως τίτλο
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Ξεκινώντας
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 88c4b93c1e4..0874271f332 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2482,7 +2482,7 @@ en:
one: "1 granted"
other: "%{count} granted"
select_badge_for_title: Select a badge to use as your title
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Getting Started
diff --git a/config/locales/client.es.yml b/config/locales/client.es.yml
index f38923daae3..82bd507f970 100644
--- a/config/locales/client.es.yml
+++ b/config/locales/client.es.yml
@@ -2271,7 +2271,7 @@ es:
one: "1 concedido"
other: "%{count} concedidos"
select_badge_for_title: Seleccionar una distinción para utilizar como tu título
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Primeros pasos
diff --git a/config/locales/client.et.yml b/config/locales/client.et.yml
index 1a5134206b6..c600f791910 100644
--- a/config/locales/client.et.yml
+++ b/config/locales/client.et.yml
@@ -1971,7 +1971,7 @@ et:
one: "1 lubatud"
other: "%{count} lubatud"
select_badge_for_title: Vali märgis, mida kasutada oma pealkirjana
- none: "<pole ühtegi>"
+ none: "(pole ühtegi)"
badge_grouping:
getting_started:
name: Alustamine
diff --git a/config/locales/client.fa_IR.yml b/config/locales/client.fa_IR.yml
index 7db29db301c..f309a191f9f 100644
--- a/config/locales/client.fa_IR.yml
+++ b/config/locales/client.fa_IR.yml
@@ -2009,7 +2009,7 @@ fa_IR:
granted:
other: "%{count} اعطا شده"
select_badge_for_title: انتخاب یک نشان برای استفاده در عنوان خود
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: شروع
diff --git a/config/locales/client.fi.yml b/config/locales/client.fi.yml
index ef7000ef8ad..ef665950e38 100644
--- a/config/locales/client.fi.yml
+++ b/config/locales/client.fi.yml
@@ -2268,7 +2268,7 @@ fi:
one: "1 myönnetty"
other: "%{count} myönnettyä"
select_badge_for_title: Valitse tittelisi ansiomerkeistä
- none: "<ei mitään>"
+ none: "(ei mitään)"
badge_grouping:
getting_started:
name: Ensiaskeleet
diff --git a/config/locales/client.fr.yml b/config/locales/client.fr.yml
index b91eda1c6ed..761149dec2a 100644
--- a/config/locales/client.fr.yml
+++ b/config/locales/client.fr.yml
@@ -2271,7 +2271,7 @@ fr:
one: "1 décerné"
other: "%{count} décernés"
select_badge_for_title: Sélectionner un badge comme titre
- none: "<aucun>"
+ none: "(aucun)"
badge_grouping:
getting_started:
name: Initiation
diff --git a/config/locales/client.he.yml b/config/locales/client.he.yml
index 575aba48d9d..2ce9731f1fd 100644
--- a/config/locales/client.he.yml
+++ b/config/locales/client.he.yml
@@ -2113,7 +2113,7 @@ he:
one: "הוענק"
other: "%{count} הוענקו"
select_badge_for_title: בחרו בעיטור לשימוש בכותרת שלכם
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: מתחילים
diff --git a/config/locales/client.it.yml b/config/locales/client.it.yml
index 3b0f4455128..dde85616333 100644
--- a/config/locales/client.it.yml
+++ b/config/locales/client.it.yml
@@ -2211,7 +2211,7 @@ it:
one: "1 assegnato"
other: "%{count} assegnati"
select_badge_for_title: Seleziona un distintivo da usare come tuo titolo
- none: "<nessuno>"
+ none: "(nessuno)"
badge_grouping:
getting_started:
name: Iniziali
diff --git a/config/locales/client.ko.yml b/config/locales/client.ko.yml
index 581fbf42b5a..6fc4bb78836 100644
--- a/config/locales/client.ko.yml
+++ b/config/locales/client.ko.yml
@@ -2091,7 +2091,7 @@ ko:
granted:
other: "%{count}개 수여됨"
select_badge_for_title: 타이틀로 사용할 배지 선택하기
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: 시작하기
diff --git a/config/locales/client.lv.yml b/config/locales/client.lv.yml
index f3e61363c7b..11525a18451 100644
--- a/config/locales/client.lv.yml
+++ b/config/locales/client.lv.yml
@@ -2199,7 +2199,7 @@ lv:
one: "1 piešķirts"
other: "%{count} piešķirti"
select_badge_for_title: Izvēlieties žetonu, ko lietot kā jūsu titulu
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Uzsākt darbu
diff --git a/config/locales/client.nb_NO.yml b/config/locales/client.nb_NO.yml
index 122535a6aba..523f16bbc2b 100644
--- a/config/locales/client.nb_NO.yml
+++ b/config/locales/client.nb_NO.yml
@@ -2268,7 +2268,7 @@ nb_NO:
one: "ett tildelt"
other: "%{count} tildelt"
select_badge_for_title: Velg et merke å bruke som din tittel
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Kom i gang
diff --git a/config/locales/client.nl.yml b/config/locales/client.nl.yml
index c5bfc95ea30..2ffe3f7247c 100644
--- a/config/locales/client.nl.yml
+++ b/config/locales/client.nl.yml
@@ -2175,7 +2175,7 @@ nl:
one: "1 toegekend"
other: "%{count} toegekend"
select_badge_for_title: Kies een badge om als uw titel te gebruiken
- none: "<geen>"
+ none: "(geen)"
badge_grouping:
getting_started:
name: Aan de slag
diff --git a/config/locales/client.pl_PL.yml b/config/locales/client.pl_PL.yml
index 3bbb08e58b8..e173f3eedc1 100644
--- a/config/locales/client.pl_PL.yml
+++ b/config/locales/client.pl_PL.yml
@@ -2430,7 +2430,7 @@ pl_PL:
many: "%{count} przyznanych"
other: "%{count} przyznanych"
select_badge_for_title: Wybierz odznakę do użycia jako twój tytuł
- none: "<brak>"
+ none: "(brak)"
badge_grouping:
getting_started:
name: Pierwsze kroki
diff --git a/config/locales/client.pt.yml b/config/locales/client.pt.yml
index 08e25bb8196..911e82260e7 100644
--- a/config/locales/client.pt.yml
+++ b/config/locales/client.pt.yml
@@ -2024,7 +2024,7 @@ pt:
one: "1 concedido"
other: "%{count} concedidos"
select_badge_for_title: Selecionar um distintivo para usar como seu título
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Começar
diff --git a/config/locales/client.pt_BR.yml b/config/locales/client.pt_BR.yml
index 2acb10f26aa..036ec78002b 100644
--- a/config/locales/client.pt_BR.yml
+++ b/config/locales/client.pt_BR.yml
@@ -2126,7 +2126,7 @@ pt_BR:
one: "1 concedido"
other: "%{count} concedidos"
select_badge_for_title: Selecione um emblema para usar como o seu título
- none: "<nenhum>"
+ none: "(nenhum)"
badge_grouping:
getting_started:
name: Primeiros Passos
diff --git a/config/locales/client.ro.yml b/config/locales/client.ro.yml
index a313c055dd3..e723a5fdd98 100644
--- a/config/locales/client.ro.yml
+++ b/config/locales/client.ro.yml
@@ -2034,7 +2034,7 @@ ro:
few: "%{count} acordate"
other: "%{count} acordate"
select_badge_for_title: Selectați un ecuson pentru a-l folosi ca titlu
- none: "<niciunul>"
+ none: "(niciunul)"
badge_grouping:
getting_started:
name: Cum începem
diff --git a/config/locales/client.ru.yml b/config/locales/client.ru.yml
index 9c9298f8d07..0d1ef9a7d5c 100644
--- a/config/locales/client.ru.yml
+++ b/config/locales/client.ru.yml
@@ -2294,7 +2294,7 @@ ru:
many: "выдано %{count}"
other: "выдано %{count}"
select_badge_for_title: Использовать награду в качестве Вашего титула
- none: "<отсутствует>"
+ none: "(отсутствует)"
badge_grouping:
getting_started:
name: Начало работы
diff --git a/config/locales/client.sk.yml b/config/locales/client.sk.yml
index b8525ef9645..560c99251e2 100644
--- a/config/locales/client.sk.yml
+++ b/config/locales/client.sk.yml
@@ -1915,7 +1915,7 @@ sk:
one: "1 udelený"
few: "%{count} udelené"
other: "%{count} udelených"
- none: "<žiadne>"
+ none: "(žiadne)"
badge_grouping:
getting_started:
name: Začíname
diff --git a/config/locales/client.sq.yml b/config/locales/client.sq.yml
index 81b758a2b1c..653cde116da 100644
--- a/config/locales/client.sq.yml
+++ b/config/locales/client.sq.yml
@@ -1883,7 +1883,7 @@ sq:
one: "1 e akorduar"
other: "%{count} të akorduara"
select_badge_for_title: Zgjidhni një stemë për ta përdorur si titullin tuaj
- none: "<asnjë>"
+ none: "(asnjë)"
badge_grouping:
getting_started:
name: Fillestar
diff --git a/config/locales/client.sv.yml b/config/locales/client.sv.yml
index dba0cfdc2fa..22b16d6c5d7 100644
--- a/config/locales/client.sv.yml
+++ b/config/locales/client.sv.yml
@@ -2022,7 +2022,7 @@ sv:
one: "1 utfärdad"
other: "%{count} utfärdade"
select_badge_for_title: Välj en utmärkelse att använda som din titel
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Komma igång
diff --git a/config/locales/client.tr_TR.yml b/config/locales/client.tr_TR.yml
index 90631af3f39..2feba94923f 100644
--- a/config/locales/client.tr_TR.yml
+++ b/config/locales/client.tr_TR.yml
@@ -1986,7 +1986,7 @@ tr_TR:
granted:
other: "%{count} izin verildi"
select_badge_for_title: Başlık yazısı olarak kullanılacak bir rozet seçin
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Başlangıç
diff --git a/config/locales/client.ur.yml b/config/locales/client.ur.yml
index 0b2bdf21a27..21604d91b50 100644
--- a/config/locales/client.ur.yml
+++ b/config/locales/client.ur.yml
@@ -1980,7 +1980,7 @@ ur:
one: "1 عطا کیا گیا"
other: "%{count} عطا کیے گئے"
select_badge_for_title: اپنے عنوان کے طور پر استعمال کرنے کے لئے ایک بیج منتخب کریں
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: شروعات
diff --git a/config/locales/client.vi.yml b/config/locales/client.vi.yml
index 7f14104b468..d923c430804 100644
--- a/config/locales/client.vi.yml
+++ b/config/locales/client.vi.yml
@@ -1834,7 +1834,7 @@ vi:
title: Huy hiệu
badge_count:
other: "%{count} huy hiệu"
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: Bắt đầu
diff --git a/config/locales/client.zh_CN.yml b/config/locales/client.zh_CN.yml
index db4deb91957..cc068f080d4 100644
--- a/config/locales/client.zh_CN.yml
+++ b/config/locales/client.zh_CN.yml
@@ -2142,7 +2142,7 @@ zh_CN:
granted:
other: "%{count} 授予"
select_badge_for_title: 选择一个徽章作为你的头衔使用
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: 开始
diff --git a/config/locales/client.zh_TW.yml b/config/locales/client.zh_TW.yml
index 83409b1f3e4..0f762fe0a2d 100644
--- a/config/locales/client.zh_TW.yml
+++ b/config/locales/client.zh_TW.yml
@@ -1884,7 +1884,7 @@ zh_TW:
granted:
other: "%{count} 授予"
select_badge_for_title: 選擇一個徽章作為你的頭銜使用
- none: "<none>"
+ none: "(none)"
badge_grouping:
getting_started:
name: 開始
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index e5715baf88d..d061c76b7be 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -1640,14 +1640,14 @@ describe UsersController do
user_badge_id: user_badge.id, username: user.username
}, format: :json
- expect(user.reload.title).not_to eq(badge.name)
+ expect(user.reload.title).not_to eq(badge.display_name)
badge.update_attributes allow_title: true
put :badge_title, params: {
user_badge_id: user_badge.id, username: user.username
}, format: :json
- expect(user.reload.title).to eq(badge.name)
+ expect(user.reload.title).to eq(badge.display_name)
expect(user.user_profile.badge_granted_title).to eq(true)
user.title = "testing"
@@ -1658,6 +1658,30 @@ describe UsersController do
end
end
+ describe "badge_title with overrided name" do
+ let(:user) { Fabricate(:user) }
+ let(:badge) { Fabricate(:badge, name: 'Demogorgon', allow_title: true) }
+ let(:user_badge) { BadgeGranter.grant(badge, user) }
+
+ before do
+ TranslationOverride.upsert!('en', 'badges.demogorgon.name', 'Boss')
+ end
+
+ after do
+ TranslationOverride.revert!('en', ['badges.demogorgon.name'])
+ end
+
+ it "uses the badge display name as user title" do
+ log_in_user user
+
+ put :badge_title, params: {
+ user_badge_id: user_badge.id, username: user.username
+ }, format: :json
+
+ expect(user.reload.title).to eq(badge.display_name)
+ end
+ end
+
describe 'send_activation_email' do
context 'for an existing user' do
let(:user) { Fabricate(:user, active: false) }