0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/app/models/admin_notice.rb
Régis Hanol 1e4e6fe052
FIX: Linkify site setting references in dashboard problem messages (#41763)
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"
/>
2026-07-16 14:46:25 +02:00

45 lines
1.2 KiB
Ruby
Vendored

# frozen_string_literal: true
class AdminNotice < ActiveRecord::Base
MESSAGE_ALLOWED_TAGS = %w[a pre ul li].freeze
MESSAGE_ALLOWED_ATTRIBUTES =
(%w[href target rel] + SiteSettings::LabelFormatter::LINK_ATTRIBUTES).freeze
MESSAGE_SANITIZER = Rails::Html::SafeListSanitizer.new
validates :identifier, presence: true
enum :priority, %i[low high].freeze
enum :subject, %i[problem].freeze
def message
translated =
I18n.t(
"dashboard.#{subject}.#{identifier}",
**details.symbolize_keys.merge(base_path: Discourse.base_path),
)
MESSAGE_SANITIZER.sanitize(
SiteSettings::LabelFormatter.expand_setting_links(translated),
tags: MESSAGE_ALLOWED_TAGS,
attributes: MESSAGE_ALLOWED_ATTRIBUTES,
)
end
end
# == Schema Information
#
# Table name: admin_notices
#
# id :bigint not null, primary key
# details :json not null
# identifier :string not null
# priority :integer not null
# subject :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_admin_notices_on_identifier (identifier)
# index_admin_notices_on_subject (subject)
#