FEATURE: Add auto update field to themes (#11102)
Themes marked for auto update will be automatically updated when Discourse is updated. This is triggered by discourse_docker or docker_manager running Rake task 'themes:update'.
This commit is contained in:
parent
0853208d67
commit
bc8423a1bf
|
@ -35,6 +35,11 @@ export default Controller.extend({
|
||||||
childThemesNames: mapBy("model.childThemes", "name"),
|
childThemesNames: mapBy("model.childThemes", "name"),
|
||||||
extraFiles: filterBy("model.theme_fields", "target", "extra_js"),
|
extraFiles: filterBy("model.theme_fields", "target", "extra_js"),
|
||||||
|
|
||||||
|
@discourseComputed("model.component", "model.remote_theme")
|
||||||
|
showCheckboxes() {
|
||||||
|
return !this.model.component || this.model.remote_theme;
|
||||||
|
},
|
||||||
|
|
||||||
@discourseComputed("model.editedFields")
|
@discourseComputed("model.editedFields")
|
||||||
editedFieldsFormatted() {
|
editedFieldsFormatted() {
|
||||||
const descriptions = [];
|
const descriptions = [];
|
||||||
|
@ -304,6 +309,10 @@ export default Controller.extend({
|
||||||
this.model.saveChanges("user_selectable");
|
this.model.saveChanges("user_selectable");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
applyAutoUpdateable() {
|
||||||
|
this.model.saveChanges("auto_update");
|
||||||
|
},
|
||||||
|
|
||||||
addChildTheme() {
|
addChildTheme() {
|
||||||
let themeId = parseInt(this.selectedChildThemeId, 10);
|
let themeId = parseInt(this.selectedChildThemeId, 10);
|
||||||
let theme = this.allThemes.findBy("id", themeId);
|
let theme = this.allThemes.findBy("id", themeId);
|
||||||
|
|
|
@ -134,12 +134,17 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#unless model.component}}
|
{{#if showCheckboxes}}
|
||||||
<div class="control-unit">
|
<div class="control-unit">
|
||||||
{{inline-edit-checkbox action=(action "applyDefault") labelKey="admin.customize.theme.is_default" checked=model.default}}
|
{{#unless model.component}}
|
||||||
{{inline-edit-checkbox action=(action "applyUserSelectable") labelKey="admin.customize.theme.user_selectable" checked=model.user_selectable}}
|
{{inline-edit-checkbox action=(action "applyDefault") labelKey="admin.customize.theme.is_default" checked=model.default}}
|
||||||
|
{{inline-edit-checkbox action=(action "applyUserSelectable") labelKey="admin.customize.theme.user_selectable" checked=model.user_selectable}}
|
||||||
|
{{/unless}}
|
||||||
|
{{#if model.remote_theme}}
|
||||||
|
{{inline-edit-checkbox action=(action "applyAutoUpdateable") labelKey="admin.customize.theme.auto_update" checked=model.auto_update}}
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{/unless}}
|
{{/if}}
|
||||||
|
|
||||||
{{#unless model.component}}
|
{{#unless model.component}}
|
||||||
{{#d-section class="form-horizontal theme settings control-unit"}}
|
{{#d-section class="form-horizontal theme settings control-unit"}}
|
||||||
|
|
|
@ -178,7 +178,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
disables_component = [false, "false"].include?(theme_params[:enabled])
|
disables_component = [false, "false"].include?(theme_params[:enabled])
|
||||||
enables_component = [true, "true"].include?(theme_params[:enabled])
|
enables_component = [true, "true"].include?(theme_params[:enabled])
|
||||||
|
|
||||||
[:name, :color_scheme_id, :user_selectable, :enabled].each do |field|
|
[:name, :color_scheme_id, :user_selectable, :enabled, :auto_update].each do |field|
|
||||||
if theme_params.key?(field)
|
if theme_params.key?(field)
|
||||||
@theme.public_send("#{field}=", theme_params[field])
|
@theme.public_send("#{field}=", theme_params[field])
|
||||||
end
|
end
|
||||||
|
@ -348,6 +348,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
:user_selectable,
|
:user_selectable,
|
||||||
:component,
|
:component,
|
||||||
:enabled,
|
:enabled,
|
||||||
|
:auto_update,
|
||||||
settings: {},
|
settings: {},
|
||||||
translations: {},
|
translations: {},
|
||||||
theme_fields: [:name, :target, :value, :upload_id, :type_id],
|
theme_fields: [:name, :target, :value, :upload_id, :type_id],
|
||||||
|
|
|
@ -606,6 +606,7 @@ end
|
||||||
# remote_theme_id :integer
|
# remote_theme_id :integer
|
||||||
# component :boolean default(FALSE), not null
|
# component :boolean default(FALSE), not null
|
||||||
# enabled :boolean default(TRUE), not null
|
# enabled :boolean default(TRUE), not null
|
||||||
|
# auto_update :boolean default(TRUE), not null
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|
|
@ -63,8 +63,9 @@ class RemoteThemeSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
class ThemeSerializer < BasicThemeSerializer
|
class ThemeSerializer < BasicThemeSerializer
|
||||||
attributes :color_scheme, :color_scheme_id, :user_selectable, :remote_theme_id,
|
attributes :color_scheme, :color_scheme_id, :user_selectable, :auto_update,
|
||||||
:settings, :errors, :supported?, :description, :enabled?, :disabled_at
|
:remote_theme_id, :settings, :errors, :supported?, :description,
|
||||||
|
:enabled?, :disabled_at
|
||||||
|
|
||||||
has_one :user, serializer: UserNameSerializer, embed: :object
|
has_one :user, serializer: UserNameSerializer, embed: :object
|
||||||
has_one :disabled_by, serializer: UserNameSerializer, embed: :object
|
has_one :disabled_by, serializer: UserNameSerializer, embed: :object
|
||||||
|
|
|
@ -3980,6 +3980,7 @@ en:
|
||||||
is_default: "Theme is enabled by default"
|
is_default: "Theme is enabled by default"
|
||||||
user_selectable: "Theme can be selected by users"
|
user_selectable: "Theme can be selected by users"
|
||||||
color_scheme_user_selectable: "Color scheme can be selected by users"
|
color_scheme_user_selectable: "Color scheme can be selected by users"
|
||||||
|
auto_update: "Auto update when Discourse is updated"
|
||||||
color_scheme: "Color Palette"
|
color_scheme: "Color Palette"
|
||||||
default_light_scheme: "Light (default)"
|
default_light_scheme: "Light (default)"
|
||||||
color_scheme_select: "Select colors to be used by theme"
|
color_scheme_select: "Select colors to be used by theme"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddAutoUpdateToThemes < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_column :themes, :auto_update, :boolean, null: false, default: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -51,6 +51,22 @@ task "themes:install" => :environment do |task, args|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Update themes & theme components"
|
||||||
|
task "themes:update" => :environment do |task, args|
|
||||||
|
Theme.where(auto_update: true).find_each do |theme|
|
||||||
|
begin
|
||||||
|
if theme.remote_theme.present?
|
||||||
|
puts "Updating #{theme.name}..."
|
||||||
|
theme.remote_theme.update_from_remote
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
STDERR.puts "Failed to update #{theme.name}"
|
||||||
|
STDERR.puts e
|
||||||
|
STDERR.puts e.backtrace
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "List all the installed themes on the site"
|
desc "List all the installed themes on the site"
|
||||||
task "themes:audit" => :environment do
|
task "themes:audit" => :environment do
|
||||||
components = Set.new
|
components = Set.new
|
||||||
|
|
Loading…
Reference in New Issue