0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 01:40:29 +01:00
discourse-custom-wizard/controllers/custom_wizard/admin/admin.rb

36 Zeilen
1 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
2020-04-13 14:17:22 +02:00
class CustomWizard::AdminController < ::Admin::AdminController
before_action :ensure_admin
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
def index
2021-09-24 11:58:42 +02:00
render_json_dump(
#TODO replace with appropriate static?
2021-10-22 20:24:28 +02:00
api_section: ["business"].include?(CustomWizard::Subscription.type),
2021-11-01 14:52:29 +01:00
active_notice_count: CustomWizard::Notice.active_count,
featured_notices: ActiveModel::ArraySerializer.new(
CustomWizard::Notice.list(
type: CustomWizard::Notice.types[:info],
archetype: CustomWizard::Notice.archetypes[:subscription_message]
),
2021-09-24 11:58:42 +02:00
each_serializer: CustomWizard::NoticeSerializer
)
)
2020-04-13 14:17:22 +02:00
end
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
private
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
def find_wizard
params.require(:wizard_id)
@wizard = CustomWizard::Wizard.create(params[:wizard_id].underscore)
2020-11-03 01:24:20 +01:00
raise Discourse::InvalidParameters.new(:wizard_id) unless @wizard
2020-04-13 14:17:22 +02:00
end
2021-03-11 07:30:15 +01:00
2020-10-20 07:40:23 +02:00
def custom_field_list
serialize_data(CustomWizard::CustomField.full_list, CustomWizard::CustomFieldSerializer)
2020-10-20 07:40:23 +02:00
end
2021-03-11 07:30:15 +01:00
def render_error(message)
render json: failed_json.merge(error: message)
end
2021-03-11 07:30:15 +01:00
end