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

156 Zeilen
3,6 KiB
Ruby

2020-04-13 14:17:22 +02:00
class CustomWizard::AdminWizardController < CustomWizard::AdminController
before_action :find_wizard, only: [:show, :remove]
def index
render_json_dump(
wizard_list: ActiveModel::ArraySerializer.new(
CustomWizard::Wizard.list,
each_serializer: CustomWizard::BasicWizardSerializer
),
field_types: CustomWizard::Field.types
)
end
def show
params.require(:wizard_id)
if data = CustomWizard::Wizard.find(params[:wizard_id].underscore)
render json: data.as_json
else
render json: { none: true }
end
end
def remove
CustomWizard::Wizard.remove(@wizard.id)
render json: success_json
end
def save
opts = {}
opts[:create] = params[:create] if params[:create]
2020-04-14 01:39:21 +02:00
2020-04-13 14:17:22 +02:00
validator = CustomWizard::Validator.new(save_wizard_params.to_h, opts)
validation = validator.perform
if validation[:error]
render json: { error: validation[:error] }
2020-04-14 01:39:21 +02:00
else
if wizard_id = CustomWizard::Wizard.save(validation[:wizard])
2020-04-13 14:17:22 +02:00
render json: success_json.merge(wizard_id: wizard_id)
else
render json: failed_json
end
end
end
private
def mapped_params
[
:type,
:connector,
:output,
:output_type,
:output_connector,
pairs: [
:index,
:key,
:key_type,
:value,
:value_type,
:connector,
value: [],
key: [],
],
output: [],
]
end
def save_wizard_params
params.require(:wizard).permit(
:id,
:name,
:background,
:save_submissions,
:multiple_submissions,
:after_signup,
:after_time,
:after_time_scheduled,
:required,
:prompt_completion,
:restart_on_revisit,
:theme_id,
permitted: mapped_params,
steps: [
:id,
:title,
:key,
:banner,
:raw_description,
:required_data_message,
required_data: mapped_params,
permitted_params: mapped_params,
fields: [
:id,
:label,
:image,
:description,
:required,
:key,
:type,
:min_length,
:file_types,
2020-07-16 05:26:56 +02:00
:format,
2020-04-13 14:17:22 +02:00
:limit,
:property,
prefill: mapped_params,
content: mapped_params
]
],
actions: [
:id,
:run_after,
:type,
:code,
:skip_redirect,
2020-04-14 01:39:21 +02:00
:post,
2020-04-15 03:23:41 +02:00
:post_builder,
2020-04-14 01:39:21 +02:00
:post_template,
:notification_level,
2020-05-30 21:26:14 +02:00
:api,
:api_endpoint,
:api_body,
2020-07-20 05:06:36 +02:00
:wizard_user,
2020-04-13 14:17:22 +02:00
title: mapped_params,
category: mapped_params,
tags: mapped_params,
custom_fields: mapped_params,
2020-07-20 06:26:11 +02:00
visible: mapped_params,
2020-04-13 14:17:22 +02:00
required: mapped_params,
recipient: mapped_params,
categories: mapped_params,
mute_remainder: mapped_params,
2020-04-13 14:17:22 +02:00
profile_updates: mapped_params,
2020-04-29 03:47:08 +02:00
group: mapped_params,
url: mapped_params,
name: mapped_params,
slug: mapped_params,
color: mapped_params,
text_color: mapped_params,
parent_category_id: mapped_params,
2020-07-16 07:25:06 +02:00
permissions: mapped_params,
full_name: mapped_params,
bio_raw: mapped_params,
2020-07-16 09:50:09 +02:00
usernames: mapped_params,
owner_usernames: mapped_params,
2020-07-16 07:25:06 +02:00
grant_trust_level: mapped_params,
mentionable_level: mapped_params,
messageable_level: mapped_params,
visibility_level: mapped_params,
members_visibility_level: mapped_params
2020-04-13 14:17:22 +02:00
]
)
end
end