2015-08-19 05:15:46 +08:00
|
|
|
class Admin::EmbeddableHostsController < Admin::AdminController
|
|
|
|
|
|
|
|
def create
|
|
|
|
save_host(EmbeddableHost.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
host = EmbeddableHost.where(id: params[:id]).first
|
|
|
|
save_host(host)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
host = EmbeddableHost.where(id: params[:id]).first
|
|
|
|
host.destroy
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2018-06-07 13:28:18 +08:00
|
|
|
def save_host(host)
|
|
|
|
host.host = params[:embeddable_host][:host]
|
|
|
|
host.path_whitelist = params[:embeddable_host][:path_whitelist]
|
|
|
|
host.class_name = params[:embeddable_host][:class_name]
|
|
|
|
host.category_id = params[:embeddable_host][:category_id]
|
|
|
|
host.category_id = SiteSetting.uncategorized_category_id if host.category_id.blank?
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2018-06-07 13:28:18 +08:00
|
|
|
if host.save
|
|
|
|
render_serialized(host, EmbeddableHostSerializer, root: 'embeddable_host', rest_serializer: true)
|
|
|
|
else
|
|
|
|
render_json_error(host)
|
2015-08-19 05:15:46 +08:00
|
|
|
end
|
2018-06-07 13:28:18 +08:00
|
|
|
end
|
2015-08-19 05:15:46 +08:00
|
|
|
|
|
|
|
end
|