FIX: allow selecting site's default theme from preference

This commit is contained in:
Osama Sayegh 2018-08-10 14:12:02 +03:00 committed by GitHub
parent 2b2612d0f5
commit 865cb3feb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -88,6 +88,7 @@ class UserUpdater
# special handling for theme_id cause we need to bump a sequence number
if attributes.key?(:theme_ids)
user_guardian = Guardian.new(user)
attributes[:theme_ids].reject!(&:blank?)
attributes[:theme_ids].map!(&:to_i)
if user_guardian.allow_themes?(attributes[:theme_ids])
user.user_option.theme_key_seq += 1 if user.user_option.theme_ids != attributes[:theme_ids]

View File

@ -359,6 +359,8 @@ class Guardian
end
def allow_themes?(theme_ids)
return true if theme_ids.blank?
if is_staff? && (theme_ids - Theme.theme_ids).blank?
return true
end

View File

@ -129,6 +129,29 @@ describe UserUpdater do
expect(user.user_option.mailing_list_mode).to eq true
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
it 'does not change bio' do
SiteSetting.sso_url = "https://www.example.com/sso"