FIX: reset embedding settings when no embeddable host, log host changes (#7264)

This commit is contained in:
Maja Komel
2019-03-29 17:05:51 +01:00
committed by Régis Hanol
parent 9b00ca30ed
commit 4a3daacb1b
8 changed files with 115 additions and 18 deletions

View File

@ -1,23 +1,24 @@
class Admin::EmbeddableHostsController < Admin::AdminController
def create
save_host(EmbeddableHost.new)
save_host(EmbeddableHost.new, :create)
end
def update
host = EmbeddableHost.where(id: params[:id]).first
save_host(host)
save_host(host, :update)
end
def destroy
host = EmbeddableHost.where(id: params[:id]).first
host.destroy
StaffActionLogger.new(current_user).log_embeddable_host(host, UserHistory.actions[:embeddable_host_destroy])
render json: success_json
end
protected
def save_host(host)
def save_host(host, action)
host.host = params[:embeddable_host][:host]
host.path_whitelist = params[:embeddable_host][:path_whitelist]
host.class_name = params[:embeddable_host][:class_name]
@ -25,6 +26,8 @@ class Admin::EmbeddableHostsController < Admin::AdminController
host.category_id = SiteSetting.uncategorized_category_id if host.category_id.blank?
if host.save
changes = host.saved_changes if action == :update
StaffActionLogger.new(current_user).log_embeddable_host(host, UserHistory.actions[:"embeddable_host_#{action}"], changes: changes)
render_serialized(host, EmbeddableHostSerializer, root: 'embeddable_host', rest_serializer: true)
else
render_json_error(host)