Fallback to default theme when admin-selected theme does not exist (#38703)
This commit is contained in:
parent
b15d234ccb
commit
bdad4f78f3
@ -47,9 +47,15 @@ module ThemeHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_theme
|
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
|
end
|
||||||
|
|
||||||
def color_scheme
|
def color_scheme
|
||||||
|
|||||||
@ -109,10 +109,19 @@ RSpec.describe ThemeHelper do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when theme is changed in settings' do
|
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') }
|
it { is_expected.to eq('contrast') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when theme is changed to invalid value' do
|
||||||
|
before { Setting.theme = 'fakethemename' }
|
||||||
|
|
||||||
|
it { is_expected.to eq('default') }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is signed in' do
|
context 'when user is signed in' do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user