2019-05-02 02:57:12 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-18 17:15:46 -04:00
|
|
|
class Admin::EmbeddableHostsController < Admin::AdminController
|
|
|
|
def create
|
2019-03-29 12:05:51 -04:00
|
|
|
save_host(EmbeddableHost.new, :create)
|
2015-08-18 17:15:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
host = EmbeddableHost.where(id: params[:id]).first
|
2019-03-29 12:05:51 -04:00
|
|
|
save_host(host, :update)
|
2015-08-18 17:15:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
host = EmbeddableHost.where(id: params[:id]).first
|
|
|
|
host.destroy
|
2019-03-29 12:05:51 -04:00
|
|
|
StaffActionLogger.new(current_user).log_embeddable_host(
|
|
|
|
host,
|
|
|
|
UserHistory.actions[:embeddable_host_destroy],
|
|
|
|
)
|
2015-08-18 17:15:46 -04:00
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2019-03-29 12:05:51 -04:00
|
|
|
def save_host(host, action)
|
2015-08-18 17:15:46 -04:00
|
|
|
host.host = params[:embeddable_host][:host]
|
2020-07-26 20:23:54 -04:00
|
|
|
host.allowed_paths = params[:embeddable_host][:allowed_paths]
|
2017-05-05 18:08:18 -04:00
|
|
|
host.class_name = params[:embeddable_host][:class_name]
|
2015-08-18 17:15:46 -04:00
|
|
|
host.category_id = params[:embeddable_host][:category_id]
|
|
|
|
host.category_id = SiteSetting.uncategorized_category_id if host.category_id.blank?
|
|
|
|
|
|
|
|
if host.save
|
2019-03-29 12:05:51 -04:00
|
|
|
changes = host.saved_changes if action == :update
|
|
|
|
StaffActionLogger.new(current_user).log_embeddable_host(
|
|
|
|
host,
|
|
|
|
UserHistory.actions[:"embeddable_host_#{action}"],
|
|
|
|
changes: changes,
|
|
|
|
)
|
2015-08-18 17:15:46 -04:00
|
|
|
render_serialized(
|
|
|
|
host,
|
|
|
|
EmbeddableHostSerializer,
|
|
|
|
root: "embeddable_host",
|
|
|
|
rest_serializer: true,
|
|
|
|
)
|
|
|
|
else
|
|
|
|
render_json_error(host)
|
|
|
|
end
|
2018-06-07 01:28:18 -04:00
|
|
|
end
|
2015-08-18 17:15:46 -04:00
|
|
|
end
|