DEV: Add additional hooks for theme-creator plugin
This commit is contained in:
parent
220944a38a
commit
59640ef373
|
@ -76,6 +76,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.get("model.user_id")) {
|
||||||
|
// Used by theme-creator
|
||||||
|
options.data["user_id"] = this.get("model.user_id");
|
||||||
|
}
|
||||||
|
|
||||||
this.set("loading", true);
|
this.set("loading", true);
|
||||||
ajax(this.get("importUrl"), options)
|
ajax(this.get("importUrl"), options)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
hijack do
|
hijack do
|
||||||
File.open(path) do |file|
|
File.open(path) do |file|
|
||||||
filename = params[:file]&.original_filename || File.basename(path)
|
filename = params[:file]&.original_filename || File.basename(path)
|
||||||
upload = UploadCreator.new(file, filename, for_theme: true).create_for(current_user.id)
|
upload = UploadCreator.new(file, filename, for_theme: true).create_for(theme_user.id)
|
||||||
if upload.errors.count > 0
|
if upload.errors.count > 0
|
||||||
render_json_error upload
|
render_json_error upload
|
||||||
else
|
else
|
||||||
|
@ -44,7 +44,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
json = JSON::parse(params[:theme].read)
|
json = JSON::parse(params[:theme].read)
|
||||||
theme = json['theme']
|
theme = json['theme']
|
||||||
|
|
||||||
@theme = Theme.new(name: theme["name"], user_id: current_user.id)
|
@theme = Theme.new(name: theme["name"], user_id: theme_user.id)
|
||||||
theme["theme_fields"]&.each do |field|
|
theme["theme_fields"]&.each do |field|
|
||||||
|
|
||||||
if field["raw_upload"]
|
if field["raw_upload"]
|
||||||
|
@ -54,7 +54,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
file = Base64.decode64(field["raw_upload"])
|
file = Base64.decode64(field["raw_upload"])
|
||||||
tmp.write(file)
|
tmp.write(file)
|
||||||
tmp.rewind
|
tmp.rewind
|
||||||
upload = UploadCreator.new(tmp, field["filename"]).create_for(current_user.id)
|
upload = UploadCreator.new(tmp, field["filename"]).create_for(theme_user.id)
|
||||||
field["upload_id"] = upload.id
|
field["upload_id"] = upload.id
|
||||||
ensure
|
ensure
|
||||||
tmp.unlink
|
tmp.unlink
|
||||||
|
@ -79,7 +79,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
elsif params[:remote]
|
elsif params[:remote]
|
||||||
begin
|
begin
|
||||||
branch = params[:branch] ? params[:branch] : nil
|
branch = params[:branch] ? params[:branch] : nil
|
||||||
@theme = RemoteTheme.import_theme(params[:remote], current_user, private_key: params[:private_key], branch: branch)
|
@theme = RemoteTheme.import_theme(params[:remote], theme_user, private_key: params[:private_key], branch: branch)
|
||||||
render json: @theme, status: :created
|
render json: @theme, status: :created
|
||||||
rescue RemoteTheme::ImportError => e
|
rescue RemoteTheme::ImportError => e
|
||||||
render_json_error e.message
|
render_json_error e.message
|
||||||
|
@ -90,7 +90,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
theme_id = params[:theme_id]
|
theme_id = params[:theme_id]
|
||||||
match_theme_by_name = !!params[:bundle] && !params.key?(:theme_id) # Old theme CLI behavior, match by name. Remove Jan 2020
|
match_theme_by_name = !!params[:bundle] && !params.key?(:theme_id) # Old theme CLI behavior, match by name. Remove Jan 2020
|
||||||
begin
|
begin
|
||||||
@theme = RemoteTheme.update_tgz_theme(bundle.path, match_theme: match_theme_by_name, user: current_user, theme_id: theme_id)
|
@theme = RemoteTheme.update_tgz_theme(bundle.path, match_theme: match_theme_by_name, user: theme_user, theme_id: theme_id)
|
||||||
log_theme_change(nil, @theme)
|
log_theme_change(nil, @theme)
|
||||||
render json: @theme, status: :created
|
render json: @theme, status: :created
|
||||||
rescue RemoteTheme::ImportError => e
|
rescue RemoteTheme::ImportError => e
|
||||||
|
@ -129,7 +129,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@theme = Theme.new(name: theme_params[:name],
|
@theme = Theme.new(name: theme_params[:name],
|
||||||
user_id: current_user.id,
|
user_id: theme_user.id,
|
||||||
user_selectable: theme_params[:user_selectable] || false,
|
user_selectable: theme_params[:user_selectable] || false,
|
||||||
color_scheme_id: theme_params[:color_scheme_id],
|
color_scheme_id: theme_params[:color_scheme_id],
|
||||||
component: [true, "true"].include?(theme_params[:component]))
|
component: [true, "true"].include?(theme_params[:component]))
|
||||||
|
@ -316,4 +316,9 @@ class Admin::ThemesController < Admin::AdminController
|
||||||
@theme.switch_to_component!
|
@theme.switch_to_component!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Overridden by theme-creator plugin
|
||||||
|
def theme_user
|
||||||
|
current_user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue