2019-05-02 14:57:12 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-19 05:15:46 +08:00
|
|
|
class Admin::EmbeddableHostsController < Admin::AdminController
|
|
|
|
|
|
|
|
def create
|
2019-03-30 00:05:51 +08:00
|
|
|
save_host(EmbeddableHost.new, :create)
|
2015-08-19 05:15:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
host = EmbeddableHost.where(id: params[:id]).first
|
2019-03-30 00:05:51 +08:00
|
|
|
save_host(host, :update)
|
2015-08-19 05:15:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
host = EmbeddableHost.where(id: params[:id]).first
|
|
|
|
host.destroy
|
2019-03-30 00:05:51 +08:00
|
|
|
StaffActionLogger.new(current_user).log_embeddable_host(host, UserHistory.actions[:embeddable_host_destroy])
|
2015-08-19 05:15:46 +08:00
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2019-03-30 00:05:51 +08:00
|
|
|
def save_host(host, action)
|
2015-08-19 05:15:46 +08:00
|
|
|
host.host = params[:embeddable_host][:host]
|
2016-08-24 02:55:52 +08:00
|
|
|
host.path_whitelist = params[:embeddable_host][:path_whitelist]
|
2017-05-06 06:08:18 +08:00
|
|
|
host.class_name = params[:embeddable_host][:class_name]
|
2015-08-19 05:15:46 +08: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-30 00:05:51 +08: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-19 05:15:46 +08:00
|
|
|
render_serialized(host, EmbeddableHostSerializer, root: 'embeddable_host', rest_serializer: true)
|
|
|
|
else
|
|
|
|
render_json_error(host)
|
|
|
|
end
|
2018-06-07 13:28:18 +08:00
|
|
|
end
|
2015-08-19 05:15:46 +08:00
|
|
|
|
|
|
|
end
|