From 3411d06f9eddd6e52574b713bda5b5bac2008d0e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 17 Apr 2026 04:31:37 -0400 Subject: [PATCH] Pull user settings defaults from configuration (#38592) --- app/helpers/settings_helper.rb | 4 ++++ .../preferences/appearance/show.html.haml | 8 ++++---- .../preferences/notifications/show.html.haml | 2 +- .../preferences/posting_defaults/show.html.haml | 2 +- spec/helpers/settings_helper_spec.rb | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 44113f3d47..196eac52d5 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -23,6 +23,10 @@ module SettingsHelper ) end + def user_settings_collection(value) + UserSettings.definition_for(value)&.in || [] + end + def author_attribution_name(account) return if account.nil? diff --git a/app/views/settings/preferences/appearance/show.html.haml b/app/views/settings/preferences/appearance/show.html.haml index 4a63790256..c024d2d515 100644 --- a/app/views/settings/preferences/appearance/show.html.haml +++ b/app/views/settings/preferences/appearance/show.html.haml @@ -36,7 +36,7 @@ .input.horizontal-options = ff.input :'web.color_scheme', as: :radio_buttons, - collection: %w(auto light dark), + collection: user_settings_collection('web.color_scheme'), include_blank: false, label: I18n.t('simple_form.labels.defaults.setting_color_scheme'), label_method: ->(contrast) { I18n.t("color_scheme.#{contrast}", default: contrast) }, @@ -45,7 +45,7 @@ .input.horizontal-options = ff.input :'web.contrast', as: :radio_buttons, - collection: %w(auto high), + collection: user_settings_collection('web.contrast'), include_blank: false, label: I18n.t('simple_form.labels.defaults.setting_contrast'), label_method: ->(contrast) { I18n.t("contrast.#{contrast}", default: contrast) }, @@ -55,7 +55,7 @@ .fields-group = f.simple_fields_for :settings, current_user.settings do |ff| = ff.input :'web.emoji_style', - collection: %w(auto twemoji native), + collection: user_settings_collection('web.emoji_style'), include_blank: false, hint: I18n.t('simple_form.hints.defaults.setting_emoji_style'), label: I18n.t('simple_form.labels.defaults.setting_emoji_style'), @@ -110,7 +110,7 @@ = ff.input :'web.display_media', as: :radio_buttons, collection_wrapper_tag: 'ul', - collection: %w(default show_all hide_all), + collection: user_settings_collection('web.display_media'), hint: false, item_wrapper_tag: 'li', label_method: ->(item) { t("simple_form.hints.defaults.setting_display_media_#{item}") }, diff --git a/app/views/settings/preferences/notifications/show.html.haml b/app/views/settings/preferences/notifications/show.html.haml index 033cb15dd7..fb206b1308 100644 --- a/app/views/settings/preferences/notifications/show.html.haml +++ b/app/views/settings/preferences/notifications/show.html.haml @@ -35,7 +35,7 @@ - if SoftwareUpdate.check_enabled? && current_user.can?(:view_devops) .fields-group = ff.input :'notification_emails.software_updates', - collection: %w(none critical patch all), + collection: user_settings_collection('notification_emails.software_updates'), hint: false, include_blank: false, label_method: ->(setting) { I18n.t("simple_form.labels.notification_emails.software_updates.#{setting}") }, diff --git a/app/views/settings/preferences/posting_defaults/show.html.haml b/app/views/settings/preferences/posting_defaults/show.html.haml index 30a2f01f88..9e14585013 100644 --- a/app/views/settings/preferences/posting_defaults/show.html.haml +++ b/app/views/settings/preferences/posting_defaults/show.html.haml @@ -26,7 +26,7 @@ .fields-group = ff.input :default_quote_policy, - collection: %w(public followers nobody), + collection: user_settings_collection('default_quote_policy'), include_blank: false, label_method: ->(policy) { I18n.t("statuses.quote_policies.#{policy}") }, label: I18n.t('simple_form.labels.defaults.setting_default_quote_policy'), diff --git a/spec/helpers/settings_helper_spec.rb b/spec/helpers/settings_helper_spec.rb index ecff2edbfa..63773634e9 100644 --- a/spec/helpers/settings_helper_spec.rb +++ b/spec/helpers/settings_helper_spec.rb @@ -3,6 +3,22 @@ require 'rails_helper' RSpec.describe SettingsHelper do + describe '#user_settings_collection' do + subject { helper.user_settings_collection(value) } + + context 'with valid value' do + let(:value) { 'web.contrast' } + + it { is_expected.to eq(%w(auto high)) } + end + + context 'with invalid value' do + let(:value) { 'web.nothing_at_this_key_at_all_fake_fake_fake' } + + it { is_expected.to be_empty } + end + end + describe 'session_device_icon' do context 'with a mobile device' do let(:session) { SessionActivation.new(user_agent: 'Mozilla/5.0 (iPhone)') }