A platform for community discussion. Free, open, simple.
FIX: allow selecting site's default theme from preference
Osama Sayegh865cb3feb9de
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rbindex a580e968da6..de238e50ec0 100644--- a/app/services/user_updater.rb+++ b/app/services/user_updater.rb@@ -88,6 +88,7 @@ class UserUpdater# special handling for theme_id cause we need to bump a sequence numberif 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]diff --git a/lib/guardian.rb b/lib/guardian.rbindex db7d168428a..30bf87acd4d 100644--- a/lib/guardian.rb+++ b/lib/guardian.rb@@ -359,6 +359,8 @@ class Guardianenddef allow_themes?(theme_ids)+ return true if theme_ids.blank?+if is_staff? && (theme_ids - Theme.theme_ids).blank?return trueenddiff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rbindex 47e37edc0d0..34daad1b64b 100644--- a/spec/services/user_updater_spec.rb+++ b/spec/services/user_updater_spec.rb@@ -129,6 +129,29 @@ describe UserUpdater doexpect(user.user_option.mailing_list_mode).to eq trueend+ 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' doit 'does not change bio' doSiteSetting.sso_url = "https://www.example.com/sso"