2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2020-04-13 14:17:22 +02:00
|
|
|
class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
|
|
|
before_action :find_wizard, only: [:show, :remove]
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def index
|
|
|
|
render_json_dump(
|
|
|
|
wizard_list: ActiveModel::ArraySerializer.new(
|
2020-11-03 01:24:20 +01:00
|
|
|
CustomWizard::Wizard.list(current_user),
|
2020-04-13 14:17:22 +02:00
|
|
|
each_serializer: CustomWizard::BasicWizardSerializer
|
|
|
|
),
|
2020-10-20 07:40:23 +02:00
|
|
|
field_types: CustomWizard::Field.types,
|
2021-01-27 06:08:26 +01:00
|
|
|
realtime_validations: CustomWizard::RealtimeValidation.types,
|
2020-10-20 07:40:23 +02:00
|
|
|
custom_fields: custom_field_list
|
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
|
|
|
def show
|
|
|
|
params.require(:wizard_id)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-10-31 08:05:50 +01:00
|
|
|
if data = CustomWizard::Template.find(params[:wizard_id].underscore)
|
2020-04-13 14:17:22 +02:00
|
|
|
render json: data.as_json
|
|
|
|
else
|
|
|
|
render json: { none: true }
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def remove
|
2020-10-31 08:05:50 +01:00
|
|
|
if CustomWizard::Template.remove(@wizard.id)
|
|
|
|
render json: success_json
|
|
|
|
else
|
|
|
|
render json: failed_json
|
|
|
|
end
|
2020-04-13 14:17:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2020-11-03 01:24:20 +01:00
|
|
|
template = CustomWizard::Template.new(save_wizard_params.to_h)
|
|
|
|
wizard_id = template.save(create: params[:create])
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
if template.errors.any?
|
|
|
|
render json: failed_json.merge(errors: result.errors.full_messages)
|
2021-03-11 07:30:15 +01:00
|
|
|
else
|
2020-11-03 01:24:20 +01:00
|
|
|
render json: success_json.merge(wizard_id: wizard_id)
|
2020-04-13 14:17:22 +02:00
|
|
|
end
|
|
|
|
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 mapped_params
|
|
|
|
[
|
|
|
|
:type,
|
|
|
|
:connector,
|
|
|
|
:output,
|
|
|
|
:output_type,
|
|
|
|
:output_connector,
|
|
|
|
pairs: [
|
|
|
|
:index,
|
|
|
|
:key,
|
|
|
|
:key_type,
|
|
|
|
:value,
|
|
|
|
:value_type,
|
|
|
|
:connector,
|
|
|
|
value: [],
|
|
|
|
key: [],
|
|
|
|
],
|
|
|
|
output: [],
|
|
|
|
]
|
|
|
|
end
|
2021-03-29 08:17:57 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
# type: step
|
|
|
|
# number: 3
|
|
|
|
# title: Add a permitted parameter
|
|
|
|
# description: The custom wizard server admin will only accept permitted
|
|
|
|
# attributes...
|
|
|
|
##
|
2021-01-30 18:46:04 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
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,
|
2020-12-08 08:14:37 +01:00
|
|
|
:max_length,
|
2021-01-12 11:46:24 +01:00
|
|
|
:char_counter,
|
2020-04-13 14:17:22 +02:00
|
|
|
:file_types,
|
2020-07-16 05:26:56 +02:00
|
|
|
:format,
|
2020-04-13 14:17:22 +02:00
|
|
|
:limit,
|
|
|
|
:property,
|
|
|
|
prefill: mapped_params,
|
2021-01-30 18:46:04 +01:00
|
|
|
content: mapped_params,
|
|
|
|
validations: {},
|
2020-04-13 14:17:22 +02:00
|
|
|
]
|
|
|
|
],
|
|
|
|
actions: [
|
|
|
|
:id,
|
|
|
|
:run_after,
|
|
|
|
:type,
|
|
|
|
:code,
|
|
|
|
:skip_redirect,
|
2020-10-20 02:42:10 +02:00
|
|
|
:suppress_notifications,
|
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,
|
2020-05-25 15:59:31 +02:00
|
|
|
: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,
|
2020-05-24 12:20:15 +02:00
|
|
|
categories: mapped_params,
|
2020-05-23 00:42:26 +02:00
|
|
|
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,
|
2020-07-09 04:19:36 +02:00
|
|
|
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
|