Skip to content

A platform for community discussion. Free, open, simple.

FIX: Prevent deletion of custom color palettes when installing themes (#35754)

Krzysztof Kotlarekc02445a2cab6
diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb
index bdfe9661bf5..de5c83c3dbd 100644
--- a/app/models/remote_theme.rb
+++ b/app/models/remote_theme.rb
@@ -419,7 +419,12 @@ class RemoteTheme < ActiveRecord::Base
end
def update_theme_color_schemes(theme, schemes)
- existing_schemes = ColorScheme.unscoped.where(theme_id: theme.id)
+ existing_schemes =
+ if theme.id
+ ColorScheme.unscoped.where(theme_id: theme.id)
+ else
+ []
+ end
missing_scheme_names =
existing_schemes.reduce({}) do |hash, cs|
diff --git a/spec/integration/remote_theme_color_schemes_spec.rb b/spec/integration/remote_theme_color_schemes_spec.rb
index 4f3c13680fe..59e3bd32cf5 100644
--- a/spec/integration/remote_theme_color_schemes_spec.rb
+++ b/spec/integration/remote_theme_color_schemes_spec.rb
@@ -149,4 +149,16 @@ RSpec.describe "Remote theme update" do
expect(ColorScheme.unscoped.exists?(id: scheme1.id)).to eq(true)
expect(ColorScheme.unscoped.exists?(id: scheme2.id)).to eq(false)
end
+
+ it "does not delete custom color schemes when installing a new theme" do
+ custom_scheme = ColorScheme.create!(name: "My Custom Palette")
+ custom_scheme.color_scheme_colors.create!(name: "primary", hex: "ff0000")
+
+ expect(custom_scheme.theme_id).to be_nil
+ expect(ColorScheme.find_by(name: "My Custom Palette")).to be_present
+
+ new_theme = RemoteTheme.import_theme(initial_repo_url)
+
+ expect(ColorScheme.find_by(name: "My Custom Palette")).to be_present
+ end
end