FEATURE: Groundwork for user-selectable theme components

* Phase 0 for user-selectable theme components

- Drops `key` column from the `themes` table
- Drops `theme_key` column from the `user_options` table
- Adds `theme_ids` (array of ints default []) column to the `user_options` table and migrates data from `theme_key` to the new column.
- Removes the `default_theme_key` site setting and adds `default_theme_id` instead.
- Replaces `theme_key` cookie with a new one called `theme_ids`
- no longer need Theme.settings_for_client
This commit is contained in:
OsamaSayegh
2018-07-12 07:18:21 +03:00
committed by Sam
parent f13a7226db
commit decf1f27cf
45 changed files with 289 additions and 241 deletions

View File

@@ -34,12 +34,12 @@ describe Middleware::AnonymousCache::Helper do
it "handles theme keys" do
theme = Theme.create(name: "test", user_id: -1, user_selectable: true)
with_bad_theme_key = new_helper("HTTP_COOKIE" => "theme_key=abc").cache_key
with_bad_theme_key = new_helper("HTTP_COOKIE" => "theme_ids=abc").cache_key
with_no_theme_key = new_helper().cache_key
expect(with_bad_theme_key).to eq(with_no_theme_key)
with_good_theme_key = new_helper("HTTP_COOKIE" => "theme_key=#{theme.key}").cache_key
with_good_theme_key = new_helper("HTTP_COOKIE" => "theme_ids=#{theme.id}").cache_key
expect(with_good_theme_key).not_to eq(with_no_theme_key)
end

View File

@@ -9,7 +9,7 @@ describe Stylesheet::Manager do
expect(link).to eq("")
theme = Theme.create(name: "embedded", user_id: -1)
SiteSetting.default_theme_key = theme.key
SiteSetting.default_theme_id = theme.id
link = Stylesheet::Manager.stylesheet_link_tag(:embedded_theme)
expect(link).not_to eq("")
@@ -41,9 +41,9 @@ describe Stylesheet::Manager do
theme.add_child_theme!(child_theme)
old_link = Stylesheet::Manager.stylesheet_link_tag(:desktop_theme, 'all', theme.key)
old_link = Stylesheet::Manager.stylesheet_link_tag(:desktop_theme, 'all', theme.id)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
manager = Stylesheet::Manager.new(:desktop_theme, theme.id)
manager.compile(force: true)
css = File.read(manager.stylesheet_fullpath)
@@ -57,7 +57,7 @@ describe Stylesheet::Manager do
child_theme.set_field(target: :desktop, name: :scss, value: ".nothing{color: green;}")
child_theme.save!
new_link = Stylesheet::Manager.stylesheet_link_tag(:desktop_theme, 'all', theme.key)
new_link = Stylesheet::Manager.stylesheet_link_tag(:desktop_theme, 'all', theme.id)
expect(new_link).not_to eq(old_link)
@@ -77,12 +77,12 @@ describe Stylesheet::Manager do
user_id: -1
)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
manager = Stylesheet::Manager.new(:desktop_theme, theme.id)
digest1 = manager.digest
DiscoursePluginRegistry.stylesheets.add "fake_file"
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
manager = Stylesheet::Manager.new(:desktop_theme, theme.id)
digest2 = manager.digest
expect(digest1).not_to eq(digest2)
@@ -107,7 +107,7 @@ describe Stylesheet::Manager do
type_id: ThemeField.types[:theme_upload_var]
)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
manager = Stylesheet::Manager.new(:desktop_theme, theme.id)
digest1 = manager.digest
field.destroy!
@@ -121,7 +121,7 @@ describe Stylesheet::Manager do
type_id: ThemeField.types[:theme_upload_var]
)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
manager = Stylesheet::Manager.new(:desktop_theme, theme.id)
digest2 = manager.digest
expect(digest1).not_to eq(digest2)
@@ -137,7 +137,7 @@ describe Stylesheet::Manager do
category1 = Fabricate(:category, uploaded_background_id: 123, updated_at: 1.week.ago)
category2 = Fabricate(:category, uploaded_background_id: 456, updated_at: 2.days.ago)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
manager = Stylesheet::Manager.new(:desktop_theme, theme.id)
digest1 = manager.color_scheme_digest

View File

@@ -155,7 +155,7 @@ describe Wizard::StepUpdater do
updater.update
expect(updater.success?).to eq(true)
expect(wizard.completed_steps?('colors')).to eq(true)
theme = Theme.find_by(key: SiteSetting.default_theme_key)
theme = Theme.find_by(id: SiteSetting.default_theme_id)
expect(theme.color_scheme.base_scheme_id).to eq('dark')
end
end
@@ -203,7 +203,7 @@ describe Wizard::StepUpdater do
expect(color_scheme).to be_present
expect(color_scheme.colors).to be_present
theme = Theme.find_by(key: SiteSetting.default_theme_key)
theme = Theme.find_by(id: SiteSetting.default_theme_id)
expect(theme.color_scheme_id).to eq(color_scheme.id)
expect(Theme.where(user_selectable: true).count).to eq(2)