mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: allow selecting site's default theme from preference
This commit is contained in:
parent
2b2612d0f5
commit
865cb3feb9
|
@ -88,6 +88,7 @@ class UserUpdater
|
||||||
# special handling for theme_id cause we need to bump a sequence number
|
# special handling for theme_id cause we need to bump a sequence number
|
||||||
if attributes.key?(:theme_ids)
|
if attributes.key?(:theme_ids)
|
||||||
user_guardian = Guardian.new(user)
|
user_guardian = Guardian.new(user)
|
||||||
|
attributes[:theme_ids].reject!(&:blank?)
|
||||||
attributes[:theme_ids].map!(&:to_i)
|
attributes[:theme_ids].map!(&:to_i)
|
||||||
if user_guardian.allow_themes?(attributes[:theme_ids])
|
if user_guardian.allow_themes?(attributes[:theme_ids])
|
||||||
user.user_option.theme_key_seq += 1 if user.user_option.theme_ids != attributes[:theme_ids]
|
user.user_option.theme_key_seq += 1 if user.user_option.theme_ids != attributes[:theme_ids]
|
||||||
|
|
|
@ -359,6 +359,8 @@ class Guardian
|
||||||
end
|
end
|
||||||
|
|
||||||
def allow_themes?(theme_ids)
|
def allow_themes?(theme_ids)
|
||||||
|
return true if theme_ids.blank?
|
||||||
|
|
||||||
if is_staff? && (theme_ids - Theme.theme_ids).blank?
|
if is_staff? && (theme_ids - Theme.theme_ids).blank?
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
|
@ -129,6 +129,29 @@ describe UserUpdater do
|
||||||
expect(user.user_option.mailing_list_mode).to eq true
|
expect(user.user_option.mailing_list_mode).to eq true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "filters theme_ids blank values before updating perferences" do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
user.user_option.update!(theme_ids: [1])
|
||||||
|
updater = UserUpdater.new(acting_user, user)
|
||||||
|
|
||||||
|
updater.update(theme_ids: [""])
|
||||||
|
user.reload
|
||||||
|
expect(user.user_option.theme_ids).to eq([])
|
||||||
|
|
||||||
|
updater.update(theme_ids: [nil])
|
||||||
|
user.reload
|
||||||
|
expect(user.user_option.theme_ids).to eq([])
|
||||||
|
|
||||||
|
theme = Fabricate(:theme)
|
||||||
|
child = Fabricate(:theme)
|
||||||
|
theme.add_child_theme!(child)
|
||||||
|
theme.set_default!
|
||||||
|
|
||||||
|
updater.update(theme_ids: [theme.id.to_s, child.id.to_s, "", nil])
|
||||||
|
user.reload
|
||||||
|
expect(user.user_option.theme_ids).to eq([theme.id, child.id])
|
||||||
|
end
|
||||||
|
|
||||||
context 'when sso overrides bio' do
|
context 'when sso overrides bio' do
|
||||||
it 'does not change bio' do
|
it 'does not change bio' do
|
||||||
SiteSetting.sso_url = "https://www.example.com/sso"
|
SiteSetting.sso_url = "https://www.example.com/sso"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user