Fallback to default theme when admin-selected theme does not exist (#38703)

This commit is contained in:
Shlee
2026-04-18 02:27:38 +09:30
committed by GitHub
parent b15d234ccb
commit bdad4f78f3
2 changed files with 18 additions and 3 deletions

View File

@@ -47,9 +47,15 @@ module ThemeHelper
end
def current_theme
return Setting.theme unless Themes.instance.names.include? current_user&.setting_theme
available_themes = Themes.instance.names
current_user.setting_theme
user_theme = current_user&.setting_theme
return user_theme if user_theme && available_themes.include?(user_theme)
site_theme = Setting.theme
return site_theme if available_themes.include?(site_theme)
'default' # Fallback
end
def color_scheme

View File

@@ -109,10 +109,19 @@ RSpec.describe ThemeHelper do
end
context 'when theme is changed in settings' do
before { Setting.theme = 'contrast' }
before do
allow(Themes.instance).to receive(:names).and_return(%w(default contrast))
Setting.theme = 'contrast'
end
it { is_expected.to eq('contrast') }
end
context 'when theme is changed to invalid value' do
before { Setting.theme = 'fakethemename' }
it { is_expected.to eq('default') }
end
end
context 'when user is signed in' do