mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08:00
ccb345bd88
This commit implements many changes to topic and comments embedding. It deprecates the class_name field from EmbeddableHost and suggests using the className parameter. discourse_username parameter has been deprecated and it will fetch it from embedded site from the author or discourse-username meta. See the updated code sample from Admin > Customize > Embedding page. * FEATURE: Add className parameter for Discourse embed * DEV: Hide class_name from EmbeddableHost * DEV: Deprecate class_name field of EmbeddableHost * FEATURE: Use either author or discourse-username meta tag * DEV: Deprecate discourse_username parameter * DEV: Improve embed code sample
49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Admin::EmbeddableHostsController < Admin::AdminController
|
|
def create
|
|
save_host(EmbeddableHost.new, :create)
|
|
end
|
|
|
|
def update
|
|
host = EmbeddableHost.where(id: params[:id]).first
|
|
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, action)
|
|
host.host = params[:embeddable_host][:host]
|
|
host.allowed_paths = params[:embeddable_host][:allowed_paths]
|
|
host.category_id = params[:embeddable_host][:category_id]
|
|
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)
|
|
end
|
|
end
|
|
end
|