2017-07-06 10:02:00 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-07-11 11:41:00 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2017-07-06 10:02:00 +02:00
|
|
|
module.exports = {
|
2017-07-10 11:40:41 +02:00
|
|
|
menu: {
|
|
|
|
sections: [
|
|
|
|
{
|
2017-07-10 12:19:06 +02:00
|
|
|
name: 'menu.section.global-settings',
|
2017-07-10 11:40:41 +02:00
|
|
|
items: [
|
|
|
|
{
|
|
|
|
slug: 'general',
|
2017-07-10 12:19:06 +02:00
|
|
|
name: 'menu.item.general',
|
2017-07-10 11:40:41 +02:00
|
|
|
icon: 'globe'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
slug: 'languages',
|
2017-07-10 12:19:06 +02:00
|
|
|
name: 'menu.item.languages',
|
2017-07-10 11:40:41 +02:00
|
|
|
icon: 'language'
|
|
|
|
},
|
|
|
|
{
|
2017-07-12 16:37:07 +02:00
|
|
|
slug: 'advanced',
|
|
|
|
name: 'menu.item.advanced',
|
2017-07-10 11:40:41 +02:00
|
|
|
icon: 'cogs'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2017-07-10 12:19:06 +02:00
|
|
|
name: 'menu.section.environments',
|
2017-07-10 11:40:41 +02:00
|
|
|
items: [
|
|
|
|
{
|
|
|
|
slug: 'databases',
|
2017-07-10 12:19:06 +02:00
|
|
|
name: 'menu.item.databases',
|
2017-07-18 12:39:03 +02:00
|
|
|
icon: 'database'
|
2017-07-10 11:40:41 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
slug: 'security',
|
2017-07-10 12:19:06 +02:00
|
|
|
name: 'menu.item.security',
|
2017-07-10 11:40:41 +02:00
|
|
|
icon: 'shield'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
slug: 'server',
|
2017-07-10 12:19:06 +02:00
|
|
|
name: 'menu.item.server',
|
2017-07-10 11:40:41 +02:00
|
|
|
icon: 'server'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
2017-07-19 18:35:59 +02:00
|
|
|
general: () => ({
|
2017-07-13 12:32:17 +02:00
|
|
|
name: 'form.general.name',
|
2017-07-12 16:37:07 +02:00
|
|
|
description: 'form.general.description',
|
2017-07-10 11:40:41 +02:00
|
|
|
sections: [
|
|
|
|
{
|
2017-07-10 12:19:06 +02:00
|
|
|
name: '',
|
2017-07-10 11:40:41 +02:00
|
|
|
items: [
|
|
|
|
{
|
2017-07-13 12:32:17 +02:00
|
|
|
name: 'form.general.item.name',
|
2017-07-10 11:40:41 +02:00
|
|
|
target: 'package.name',
|
|
|
|
type: 'string',
|
2017-07-12 16:04:36 +02:00
|
|
|
value: _.get(strapi.config, 'name', null),
|
2017-07-10 11:40:41 +02:00
|
|
|
validations : {
|
|
|
|
maxLength: 255,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-07-13 12:32:17 +02:00
|
|
|
name: 'form.general.item.description',
|
2017-07-10 18:00:50 +02:00
|
|
|
target: 'package.description',
|
2017-07-10 11:40:41 +02:00
|
|
|
type: 'string',
|
2017-07-12 16:04:36 +02:00
|
|
|
value: _.get(strapi.config, 'description', null),
|
2017-07-10 11:40:41 +02:00
|
|
|
validations : {
|
|
|
|
maxLength: 255,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-07-13 12:32:17 +02:00
|
|
|
name: 'form.general.item.version',
|
2017-07-10 18:00:50 +02:00
|
|
|
target: 'package.version',
|
2017-07-10 11:40:41 +02:00
|
|
|
type: 'string',
|
2017-07-12 16:04:36 +02:00
|
|
|
value: _.get(strapi.config, 'version', null),
|
2017-07-10 11:40:41 +02:00
|
|
|
validations : {
|
2017-07-12 16:04:36 +02:00
|
|
|
regex: '^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$',
|
2017-07-10 11:40:41 +02:00
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-07-19 18:35:59 +02:00
|
|
|
}),
|
2017-07-10 11:40:41 +02:00
|
|
|
|
2017-07-19 18:35:59 +02:00
|
|
|
advanced: () => ({
|
2017-07-13 12:32:17 +02:00
|
|
|
name: 'form.advanced.name',
|
2017-07-13 11:59:56 +02:00
|
|
|
description: 'form.advanced.description',
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
name: '',
|
|
|
|
items: [
|
|
|
|
{
|
2017-07-13 12:32:17 +02:00
|
|
|
name: 'form.advanced.item.admin',
|
2017-07-13 11:59:56 +02:00
|
|
|
target: 'general.admin',
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, 'general.admin', null),
|
|
|
|
validations : {
|
|
|
|
maxLength: 255,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-07-13 12:32:17 +02:00
|
|
|
name: 'form.advanced.item.prefix',
|
2017-07-13 11:59:56 +02:00
|
|
|
target: 'general.prefix',
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, 'general.prefix', null),
|
|
|
|
validations : {
|
|
|
|
maxLength: 255
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-07-19 18:35:59 +02:00
|
|
|
}),
|
2017-07-13 11:59:56 +02:00
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
security: env => ({
|
|
|
|
name: 'form.security.name',
|
|
|
|
description: 'form.security.description',
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
name: 'form.security.item.session',
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 'form.security.item.session.key',
|
|
|
|
target: 'security.session.key',
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.security.session.key`, null),
|
|
|
|
validations: {
|
|
|
|
required: true
|
2017-07-10 11:40:41 +02:00
|
|
|
}
|
2017-07-13 17:09:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.security.item.session.maxAge',
|
|
|
|
target: 'security.session.maxAge',
|
|
|
|
type: 'number',
|
2017-07-19 15:12:27 +02:00
|
|
|
value: _.get(strapi.config, `environments.${env}.security.session.maxAge`, null),
|
2017-07-20 15:08:03 +02:00
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
2017-07-13 17:09:44 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '',
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 'form.security.item.xframe',
|
|
|
|
target: 'security.xframe',
|
|
|
|
type: 'enum',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.security.xframe`, null),
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 'form.security.item.xframe.deny',
|
|
|
|
value: 'DENY',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.security.item.xframe.sameorigin',
|
|
|
|
value: 'SAMEORIGIN',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.security.item.xframe.allow-from',
|
|
|
|
value: 'ALLOW-FROM',
|
2017-07-20 15:08:03 +02:00
|
|
|
items: [{
|
2017-07-26 11:28:12 +02:00
|
|
|
name: '',
|
2017-07-20 15:08:03 +02:00
|
|
|
type: 'string',
|
2017-07-26 11:28:12 +02:00
|
|
|
value: '',
|
2017-07-20 15:08:03 +02:00
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}]
|
2017-07-19 13:35:43 +02:00
|
|
|
}
|
|
|
|
],
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
2017-07-13 17:09:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.security.item.xssProtection',
|
|
|
|
target: 'security.xssProtection',
|
|
|
|
type: 'boolean',
|
2017-07-19 13:35:43 +02:00
|
|
|
value: _.get(strapi.config, `environments.${env}.security.xssProtection`, null),
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
2017-07-13 17:09:44 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.security.item.cors',
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 'form.security.item.cors.origin',
|
|
|
|
target: 'security.cors.origin',
|
|
|
|
type: 'string',
|
2017-07-19 15:12:27 +02:00
|
|
|
value: _.get(strapi.config, `environments.${env}.security.cors.origin`, null),
|
2017-07-20 15:08:03 +02:00
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
2017-07-13 17:09:44 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
2017-07-06 10:02:00 +02:00
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
server: env => ({
|
|
|
|
name: 'form.server.name',
|
|
|
|
description: 'form.server.description',
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
name: '',
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 'form.server.item.host',
|
|
|
|
target: 'server.host',
|
|
|
|
type: 'string',
|
2017-07-19 15:12:27 +02:00
|
|
|
value: _.get(strapi.config, `environments.${env}.server.host`, null),
|
|
|
|
validations: {}
|
2017-07-13 17:09:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.server.item.port',
|
|
|
|
target: 'server.port',
|
|
|
|
type: 'number',
|
2017-07-19 15:12:27 +02:00
|
|
|
value: _.get(strapi.config, `environments.${env}.server.port`, null),
|
|
|
|
validations: {}
|
2017-07-13 17:09:44 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
2017-07-10 18:00:50 +02:00
|
|
|
|
2017-07-19 18:35:59 +02:00
|
|
|
i18n: env => ({
|
2017-07-20 15:27:05 +02:00
|
|
|
name: 'form.i18n.name',
|
|
|
|
description: 'form.i18n.description',
|
2017-07-19 14:42:45 +02:00
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
name: '',
|
|
|
|
items: [
|
|
|
|
{
|
2017-07-20 17:09:15 +02:00
|
|
|
name: 'form.i18n.choose',
|
2017-07-19 14:42:45 +02:00
|
|
|
target: 'i18n.i18n.defaultLocale',
|
2017-07-19 18:35:59 +02:00
|
|
|
type: 'select',
|
|
|
|
items: strapi.plugins['settings-manager'].services.languages
|
2017-07-19 14:42:45 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-07-19 18:35:59 +02:00
|
|
|
}),
|
2017-07-19 14:42:45 +02:00
|
|
|
|
2017-07-25 16:37:50 +02:00
|
|
|
database: (name, env) => ({
|
|
|
|
name: 'form.databases.name',
|
|
|
|
description: 'form.databases.description',
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
name: '',
|
|
|
|
items: [
|
2017-07-26 12:43:46 +02:00
|
|
|
{
|
|
|
|
name: 'form.databases.item.name',
|
|
|
|
target: `databases.connections.${name}.name`,
|
|
|
|
type: 'string',
|
|
|
|
value: name,
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
2017-07-25 16:37:50 +02:00
|
|
|
{
|
|
|
|
name: 'form.databases.item.provider',
|
|
|
|
target: `databases.connections.${name}.connector`,
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.databases.connections.${name}.connector`, null),
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.databases.item.host',
|
|
|
|
target: `databases.connections.${name}.settings.host`,
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.databases.connections.${name}.settings.host`, null),
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.databases.item.username',
|
|
|
|
target: `databases.connections.${name}.settings.username`,
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.databases.connections.${name}.settings.username`, null),
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.databases.item.password',
|
|
|
|
target: `databases.connections.${name}.settings.password`,
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.databases.connections.${name}.settings.password`, null),
|
|
|
|
validations: {}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'form.databases.item.database',
|
|
|
|
target: `databases.connections.${name}.settings.database`,
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.databases.connections.${name}.settings.database`, null),
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '',
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
name: 'form.databases.item.default',
|
|
|
|
target: `databases.defaultConnection`,
|
|
|
|
type: 'string',
|
|
|
|
value: _.get(strapi.config, `environments.${env}.databases.defaultConnection`, null),
|
|
|
|
validations: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
|
2017-07-11 14:56:52 +02:00
|
|
|
getEnvironments: () => {
|
|
|
|
return _.map(_.keys(strapi.config.environments), environment => {
|
|
|
|
return {
|
|
|
|
name: environment,
|
|
|
|
active: (strapi.config.environment === environment)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-19 14:31:17 +02:00
|
|
|
getLanguages: () => {
|
|
|
|
return _.map(strapi.config.i18n.locales, language => {
|
|
|
|
return {
|
|
|
|
name: language,
|
|
|
|
active: (strapi.config.i18n.defaultLocale === language)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-25 15:11:11 +02:00
|
|
|
getDatabases: env => {
|
|
|
|
const databases = [];
|
|
|
|
|
|
|
|
_.forEach(strapi.config.environments[env].databases.connections, (connection, name) => {
|
|
|
|
databases.push({
|
|
|
|
provider: connection.connector,
|
|
|
|
name,
|
|
|
|
host: connection.settings.host,
|
|
|
|
database: connection.settings.database,
|
|
|
|
active: (strapi.config.environments[env].databases.defaultConnection = name)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return databases;
|
|
|
|
},
|
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
getItems: model => _.flatten(_.map(model.sections, section => section.items)),
|
2017-07-10 18:00:50 +02:00
|
|
|
|
|
|
|
cleanParams: (params, items) => {
|
|
|
|
const cleanParams = {};
|
|
|
|
|
|
|
|
_.forEach(items, ({ target }) => _.has(params, target) ? _.set(cleanParams, target, _.get(params, target)) : '');
|
|
|
|
|
|
|
|
return cleanParams;
|
|
|
|
},
|
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
formatErrors: errors => _.map(_.groupBy(errors, 'target'), (errs, target) => {
|
|
|
|
return {
|
|
|
|
target,
|
|
|
|
messages: _.map(errs, err => {
|
|
|
|
return {
|
|
|
|
id: err.message,
|
|
|
|
params: _.get(err, 'params', undefined)
|
2017-07-19 09:52:29 +02:00
|
|
|
};
|
2017-07-13 17:09:44 +02:00
|
|
|
})
|
2017-07-19 09:52:29 +02:00
|
|
|
};
|
2017-07-13 17:09:44 +02:00
|
|
|
}),
|
|
|
|
|
2017-07-10 18:00:50 +02:00
|
|
|
paramsValidation: (params, items) => {
|
|
|
|
let errors = [];
|
|
|
|
|
2017-07-20 15:08:03 +02:00
|
|
|
const reformat = (value, format) => {
|
|
|
|
if (format === 'number') try { return parseFloat(number) } catch (e) { return null };
|
|
|
|
if (format === 'boolean') return value === 'true';
|
|
|
|
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
2017-07-19 18:41:33 +02:00
|
|
|
const checkType = (input, { type, target, items }) => {
|
2017-07-20 15:08:03 +02:00
|
|
|
if ((type === 'string' || type === 'text') && !_.isString(input)) return errors.push({
|
2017-07-10 18:00:50 +02:00
|
|
|
target: target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.type.string'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
|
|
|
|
2017-07-20 15:08:03 +02:00
|
|
|
if (type === 'number' && !_.isNumber(input)) return errors.push({
|
2017-07-10 18:00:50 +02:00
|
|
|
target: target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.type.number'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
|
|
|
|
2017-07-20 15:08:03 +02:00
|
|
|
if (type === 'boolean' && !_.isBoolean(input)) return errors.push({
|
2017-07-10 18:00:50 +02:00
|
|
|
target: target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.type.boolean'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
2017-07-19 18:41:33 +02:00
|
|
|
|
2017-07-20 15:08:03 +02:00
|
|
|
if (type === 'select' && !_.find(items, { value: input })) return errors.push({
|
2017-07-19 18:41:33 +02:00
|
|
|
target: target,
|
|
|
|
message: 'request.error.type.select'
|
|
|
|
});
|
2017-07-20 15:08:03 +02:00
|
|
|
|
|
|
|
if (type === 'enum') {
|
|
|
|
if (!_.find(items, { value: input })) {
|
|
|
|
const key = input.split('.')[0];
|
|
|
|
input = _.drop(input.split('.')).join('.');
|
|
|
|
|
|
|
|
const item = _.find(items, { value: key });
|
|
|
|
|
|
|
|
if (!item) return errors.push({
|
|
|
|
target: target,
|
|
|
|
message: 'request.error.type.enum'
|
|
|
|
});
|
|
|
|
|
|
|
|
input = reformat(input, item.type);
|
|
|
|
params[target] = input;
|
|
|
|
|
|
|
|
_.forEach(item.items, subItem => {
|
|
|
|
subItem.target = target;
|
|
|
|
if (_.has(params, subItem.target)) {
|
|
|
|
const input = _.get(params, subItem.target, null);
|
|
|
|
|
|
|
|
checkType(input, subItem);
|
|
|
|
checkValidations(input, subItem);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-07-10 18:00:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const checkValidations = (input, item) => {
|
|
|
|
_.forEach(item.validations, (value, key) => {
|
2017-07-24 11:41:44 +02:00
|
|
|
if (key === 'required' && (_.isNull(input) || (_.isString(input) && _.isEmpty(input)) || _.isUndefined(input))) errors.push({
|
2017-07-10 18:00:50 +02:00
|
|
|
target: item.target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.validation.required'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
|
|
|
|
2017-07-12 16:04:36 +02:00
|
|
|
if (key === 'regex' && !new RegExp(value).test(input)) errors.push({
|
|
|
|
target: item.target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.validation.regex'
|
2017-07-12 16:04:36 +02:00
|
|
|
});
|
|
|
|
|
2017-07-10 18:00:50 +02:00
|
|
|
if (key === 'max' && parseInt(input) > value) errors.push({
|
|
|
|
target: item.target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.validation.max'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (key === 'min' && parseInt(input) < value) errors.push({
|
|
|
|
target: item.target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.validation.min'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (key === 'maxLength' && input.length > value) errors.push({
|
|
|
|
target: item.target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.validation.maxLength'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (key === 'minLength' && input.length < value) errors.push({
|
|
|
|
target: item.target,
|
2017-07-13 12:32:17 +02:00
|
|
|
message: 'request.error.validation.minLength'
|
2017-07-10 18:00:50 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
_.forEach(items, item => {
|
|
|
|
if (_.has(params, item.target)) {
|
|
|
|
const input = _.get(params, item.target, null);
|
|
|
|
|
2017-07-19 09:52:29 +02:00
|
|
|
checkType(input, item);
|
|
|
|
checkValidations(input, item);
|
2017-07-10 18:00:50 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-20 15:08:03 +02:00
|
|
|
return [params, errors];
|
2017-07-11 11:41:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
updateSettings: (params, items, env = '') => {
|
2017-07-13 17:09:44 +02:00
|
|
|
const appPath = strapi.config.appPath;
|
|
|
|
const errors = [];
|
2017-07-11 11:41:00 +02:00
|
|
|
|
|
|
|
_.forEach(items, ({ target }) => {
|
|
|
|
if (_.has(params, target)) {
|
|
|
|
const input = _.get(params, target, null);
|
|
|
|
const [file, ...objPath] = target.split('.');
|
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
const filePath = (file === 'package') ? path.join(appPath, 'package.json') : path.join(appPath, 'config', `${env ? `environments/${env}` : ''}`, `${_.replace(file, '.', '/')}.json`);
|
2017-07-11 11:41:00 +02:00
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
try {
|
2017-07-17 14:09:38 +02:00
|
|
|
const fileContent = require(filePath);
|
2017-07-11 11:41:00 +02:00
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
_.set(fileContent, objPath, input);
|
2017-07-11 11:41:00 +02:00
|
|
|
|
2017-07-13 17:09:44 +02:00
|
|
|
fs.writeFileSync(filePath, JSON.stringify(fileContent, null, 2), 'utf8');
|
|
|
|
} catch (e) {
|
|
|
|
errors.push({
|
|
|
|
target,
|
2017-07-17 14:09:38 +02:00
|
|
|
message: 'request.error.config',
|
2017-07-13 17:09:44 +02:00
|
|
|
params: {
|
|
|
|
filePath: filePath
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-07-11 11:41:00 +02:00
|
|
|
}
|
|
|
|
});
|
2017-07-13 17:09:44 +02:00
|
|
|
|
|
|
|
return errors;
|
2017-07-10 11:40:41 +02:00
|
|
|
}
|
2017-07-06 10:02:00 +02:00
|
|
|
};
|