Fallback to default theme when admin-selected theme does not exist (#38703)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user