mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 09:44:06 +08:00
Previously, the admin dashboard rendered `{{setting:...}}` references in
problem messages as raw text, because `AdminNotice#message`
re-translated each notice without expanding the markers and its
sanitizer stripped the `class`/`data-setting-*` attributes the frontend
needs to link each setting.
This change expands the markers at that render seam (widening the
sanitizer allowlist via a shared constant on
`SiteSettings::LabelFormatter` so it can't drift from what `linkify`
emits) and applies the `linkifySettingLinks` modifier in both the
classic and redesigned dashboards, so setting references resolve to
their own config pages.
Ref - t/148687
**BEFORE**
<img width="1958" height="1380" alt="2026-07-16 @ 09 02 12"
src="https://github.com/user-attachments/assets/4a83deba-ae10-40e3-a91b-ca66d5178c08"
/>
**AFTER**
<img width="1958" height="1380" alt="2026-07-16 @ 09 01 53"
src="https://github.com/user-attachments/assets/8cd71db8-95d7-445a-9dde-f49af21b3446"
/>
25 lines
951 B
Ruby
Vendored
25 lines
951 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe AdminNotice do
|
|
it { is_expected.to validate_presence_of(:identifier) }
|
|
|
|
describe "#message" do
|
|
def store_problem_translation(text)
|
|
I18n.backend.store_translations(:en, { "dashboard" => { "problem" => { "test" => text } } })
|
|
end
|
|
|
|
it "interpolates the notice details into the translation" do
|
|
store_problem_translation("Something is wrong with the %{thing}")
|
|
notice = Fabricate(:admin_notice, identifier: "test", details: { thing: "world" })
|
|
expect(notice.message).to eq("Something is wrong with the world")
|
|
end
|
|
|
|
it "expands setting markers into links that survive sanitization" do
|
|
store_problem_translation("Configure {{setting:title}} to fix this")
|
|
notice = Fabricate(:admin_notice, identifier: "test")
|
|
expect(notice.message).to eq(
|
|
"Configure #{SiteSettings::LabelFormatter.linkify(:title)} to fix this",
|
|
)
|
|
end
|
|
end
|
|
end
|