2021-04-12 07:10:02 +02:00
|
|
|
import { get, set } from "@ember/object";
|
2021-05-05 08:05:53 +02:00
|
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const wizard = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
|
|
|
name: null,
|
|
|
|
background: null,
|
|
|
|
save_submissions: true,
|
|
|
|
multiple_submissions: null,
|
|
|
|
after_signup: null,
|
|
|
|
after_time: null,
|
|
|
|
after_time_scheduled: null,
|
|
|
|
required: null,
|
|
|
|
prompt_completion: null,
|
|
|
|
restart_on_revisit: null,
|
|
|
|
theme_id: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
permitted: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
mapped: ["permitted"],
|
|
|
|
required: ["id"],
|
2020-04-16 04:04:27 +02:00
|
|
|
dependent: {
|
2021-03-28 11:06:49 +02:00
|
|
|
after_time: "after_time_scheduled",
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
objectArrays: {
|
|
|
|
step: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "steps",
|
|
|
|
required: false,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
action: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "actions",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const step = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
index: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
title: null,
|
|
|
|
banner: null,
|
|
|
|
raw_description: null,
|
|
|
|
required_data: null,
|
|
|
|
required_data_message: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
permitted_params: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: null,
|
|
|
|
force_final: false,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2021-04-20 19:58:19 +02:00
|
|
|
mapped: ["required_data", "permitted_params", "condition", "index"],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id"],
|
|
|
|
dependent: {},
|
2020-04-16 04:04:27 +02:00
|
|
|
objectArrays: {
|
|
|
|
field: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "fields",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const field = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
index: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
label: null,
|
|
|
|
image: null,
|
|
|
|
description: null,
|
2021-09-03 10:46:32 +02:00
|
|
|
property: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
required: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
type: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
types: {},
|
2021-04-20 19:58:19 +02:00
|
|
|
mapped: ["prefill", "content", "condition", "index"],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id", "type"],
|
|
|
|
dependent: {},
|
|
|
|
objectArrays: {},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const action = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
run_after: "wizard_completion",
|
|
|
|
type: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
types: {
|
|
|
|
create_topic: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
|
|
|
category: null,
|
|
|
|
tags: null,
|
2020-07-20 06:26:11 +02:00
|
|
|
visible: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
custom_fields: null,
|
2020-10-20 02:42:10 +02:00
|
|
|
skip_redirect: null,
|
|
|
|
suppress_notifications: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
send_message: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
|
|
|
skip_redirect: null,
|
|
|
|
custom_fields: null,
|
|
|
|
required: null,
|
2020-10-20 02:42:10 +02:00
|
|
|
recipient: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
suppress_notifications: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
open_composer: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
|
|
|
category: null,
|
|
|
|
tags: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
update_profile: {
|
|
|
|
profile_updates: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2020-05-23 00:42:26 +02:00
|
|
|
watch_categories: {
|
2020-05-24 09:56:27 +02:00
|
|
|
categories: null,
|
2020-05-25 15:59:31 +02:00
|
|
|
notification_level: null,
|
2020-07-20 05:06:36 +02:00
|
|
|
mute_remainder: null,
|
|
|
|
wizard_user: true,
|
2021-03-28 11:06:49 +02:00
|
|
|
usernames: null,
|
2020-05-23 00:42:26 +02:00
|
|
|
},
|
2020-05-30 21:26:14 +02:00
|
|
|
send_to_api: {
|
|
|
|
api: null,
|
|
|
|
api_endpoint: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
api_body: null,
|
2020-05-30 21:26:14 +02:00
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
add_to_group: {
|
2021-03-28 11:06:49 +02:00
|
|
|
group: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
route_to: {
|
|
|
|
url: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
code: null,
|
2020-07-09 04:19:36 +02:00
|
|
|
},
|
|
|
|
create_category: {
|
|
|
|
name: null,
|
|
|
|
slug: null,
|
|
|
|
color: null,
|
|
|
|
text_color: "FFFFFF",
|
|
|
|
parent_category_id: null,
|
2020-07-17 04:10:59 +02:00
|
|
|
permissions: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-07-16 07:25:06 +02:00
|
|
|
},
|
|
|
|
create_group: {
|
|
|
|
name: null,
|
|
|
|
full_name: null,
|
|
|
|
title: null,
|
|
|
|
bio_raw: null,
|
2020-07-16 09:50:09 +02:00
|
|
|
owner_usernames: null,
|
|
|
|
usernames: null,
|
2020-07-16 07:25:06 +02:00
|
|
|
grant_trust_level: null,
|
|
|
|
mentionable_level: null,
|
|
|
|
messageable_level: null,
|
|
|
|
visibility_level: null,
|
2020-07-17 04:10:59 +02:00
|
|
|
members_visibility_level: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
mapped: [
|
2021-03-28 11:06:49 +02:00
|
|
|
"title",
|
|
|
|
"category",
|
|
|
|
"tags",
|
|
|
|
"visible",
|
|
|
|
"custom_fields",
|
|
|
|
"required",
|
|
|
|
"recipient",
|
|
|
|
"profile_updates",
|
|
|
|
"group",
|
|
|
|
"url",
|
|
|
|
"categories",
|
|
|
|
"mute_remainder",
|
|
|
|
"name",
|
|
|
|
"slug",
|
|
|
|
"color",
|
|
|
|
"text_color",
|
|
|
|
"parent_category_id",
|
|
|
|
"permissions",
|
|
|
|
"full_name",
|
|
|
|
"bio_raw",
|
|
|
|
"owner_usernames",
|
|
|
|
"usernames",
|
|
|
|
"grant_trust_level",
|
|
|
|
"mentionable_level",
|
|
|
|
"messageable_level",
|
|
|
|
"visibility_level",
|
|
|
|
"members_visibility_level",
|
2020-04-16 04:04:27 +02:00
|
|
|
],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id", "type"],
|
|
|
|
dependent: {},
|
|
|
|
objectArrays: {},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
2021-10-23 14:06:12 +02:00
|
|
|
const custom_field = {
|
|
|
|
klasses: ["topic", "post", "group", "category"],
|
|
|
|
types: ["string", "boolean", "integer", "json"],
|
|
|
|
}
|
|
|
|
|
2021-10-25 16:31:44 +02:00
|
|
|
const subscription_levels = {
|
|
|
|
standard: {
|
|
|
|
actions: ["send_message", "add_to_group", "watch_categories"],
|
|
|
|
custom_fields: {
|
|
|
|
klasses: [],
|
|
|
|
types: ["json"]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
business: {
|
|
|
|
actions: ["create_category", "create_group", "send_to_api"],
|
|
|
|
custom_fields: {
|
|
|
|
klasses: ["group", "category"],
|
|
|
|
types: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 04:04:27 +02:00
|
|
|
const wizardSchema = {
|
|
|
|
wizard,
|
|
|
|
step,
|
|
|
|
field,
|
2021-10-23 14:06:12 +02:00
|
|
|
custom_field,
|
2021-03-28 11:06:49 +02:00
|
|
|
action,
|
2021-10-25 16:31:44 +02:00
|
|
|
subscription_levels
|
|
|
|
}
|
|
|
|
|
|
|
|
export function requiringAdditionalSubscription(
|
2021-10-25 19:55:28 +02:00
|
|
|
currentSubscription, category, subCategory
|
2021-10-25 16:31:44 +02:00
|
|
|
) {
|
2021-10-25 19:55:28 +02:00
|
|
|
switch (category) {
|
|
|
|
case "actions":
|
|
|
|
switch (currentSubscription) {
|
|
|
|
case "business":
|
|
|
|
return [];
|
|
|
|
case "standard":
|
|
|
|
return subscription_levels["business"].[category];
|
|
|
|
default:
|
|
|
|
return subscription_levels["standard"].[category].concat(
|
|
|
|
subscription_levels["business"].[category]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "custom_fields":
|
|
|
|
switch (currentSubscription) {
|
|
|
|
case "business":
|
|
|
|
return [];
|
|
|
|
case "standard":
|
|
|
|
return subscription_levels["business"].[category].[subCategory];
|
|
|
|
default:
|
|
|
|
return subscription_levels["standard"].[category].[subCategory].concat(
|
|
|
|
subscription_levels["business"].[category].[subCategory]
|
|
|
|
);
|
|
|
|
}
|
2021-10-25 16:31:44 +02:00
|
|
|
default:
|
2021-10-25 19:55:28 +02:00
|
|
|
return [];
|
2021-10-25 16:31:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-25 19:55:28 +02:00
|
|
|
export function subscriptionLevel(type, category, subCategory) {
|
2021-10-25 16:31:44 +02:00
|
|
|
switch (category) {
|
|
|
|
case "actions":
|
|
|
|
if (subscription_levels.["business"].actions.includes(type)) {
|
|
|
|
return "business"
|
|
|
|
} else {
|
|
|
|
if (subscription_levels.["standard"].actions.includes(type)) {
|
|
|
|
return "standard"
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "custom_fields":
|
|
|
|
if (subscription_levels.["business"].custom_fields[subCategory].includes(type)) {
|
|
|
|
return "business"
|
|
|
|
} else {
|
|
|
|
if (subscription_levels.["standard"].custom_fields[subCategory].includes(type)) {
|
|
|
|
return "standard"
|
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
export function buildFieldTypes(types) {
|
|
|
|
wizardSchema.field.types = types;
|
|
|
|
}
|
|
|
|
|
2021-01-27 06:08:26 +01:00
|
|
|
export function buildFieldValidations(validations) {
|
|
|
|
wizardSchema.field.validations = validations;
|
|
|
|
}
|
|
|
|
|
2021-05-05 08:05:53 +02:00
|
|
|
const siteSettings = getOwner(this).lookup("site-settings:main");
|
|
|
|
if (siteSettings.wizard_apis_enabled) {
|
2020-04-16 04:04:27 +02:00
|
|
|
wizardSchema.action.types.send_to_api = {
|
|
|
|
api: null,
|
|
|
|
api_endpoint: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
api_body: null,
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 07:44:47 +02:00
|
|
|
export function setWizardDefaults(obj, itemType) {
|
2020-04-20 11:41:13 +02:00
|
|
|
const objSchema = wizardSchema[itemType];
|
|
|
|
const basicDefaults = objSchema.basic;
|
2021-03-28 11:06:49 +02:00
|
|
|
|
|
|
|
Object.keys(basicDefaults).forEach((property) => {
|
2020-04-20 11:41:13 +02:00
|
|
|
let defaultValue = get(basicDefaults, property);
|
|
|
|
if (defaultValue) {
|
|
|
|
set(obj, property, defaultValue);
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 23:21:44 +02:00
|
|
|
if (objSchema.types) {
|
|
|
|
const typeDefaults = objSchema.types[obj.type];
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 23:21:44 +02:00
|
|
|
if (typeDefaults) {
|
2021-03-28 11:06:49 +02:00
|
|
|
Object.keys(typeDefaults).forEach((property) => {
|
2020-04-20 23:21:44 +02:00
|
|
|
if (typeDefaults.hasOwnProperty(property)) {
|
|
|
|
set(obj, property, get(typeDefaults, property));
|
2021-03-28 11:06:49 +02:00
|
|
|
}
|
2020-04-20 23:21:44 +02:00
|
|
|
});
|
|
|
|
}
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 11:41:13 +02:00
|
|
|
return obj;
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
export default wizardSchema;
|