|
@@ -1,16 +1,14 @@
|
|
|
module.exports = function(crowi) {
|
|
module.exports = function(crowi) {
|
|
|
- const mongoose = require('mongoose')
|
|
|
|
|
- , debug = require('debug')('growi:models:config')
|
|
|
|
|
- , uglifycss = require('uglifycss')
|
|
|
|
|
- , recommendedXssWhiteList = require('@commons/service/xss/recommendedXssWhiteList')
|
|
|
|
|
|
|
+ const mongoose = require('mongoose');
|
|
|
|
|
+ const debug = require('debug')('growi:models:config');
|
|
|
|
|
+ const uglifycss = require('uglifycss');
|
|
|
|
|
+ const recommendedXssWhiteList = require('@commons/service/xss/recommendedXssWhiteList');
|
|
|
|
|
|
|
|
- , SECURITY_RESTRICT_GUEST_MODE_DENY = 'Deny'
|
|
|
|
|
- , SECURITY_RESTRICT_GUEST_MODE_READONLY = 'Readonly'
|
|
|
|
|
-
|
|
|
|
|
- , SECURITY_REGISTRATION_MODE_OPEN = 'Open'
|
|
|
|
|
- , SECURITY_REGISTRATION_MODE_RESTRICTED = 'Resricted'
|
|
|
|
|
- , SECURITY_REGISTRATION_MODE_CLOSED = 'Closed'
|
|
|
|
|
- ;
|
|
|
|
|
|
|
+ const SECURITY_RESTRICT_GUEST_MODE_DENY = 'Deny';
|
|
|
|
|
+ const SECURITY_RESTRICT_GUEST_MODE_READONLY = 'Readonly';
|
|
|
|
|
+ const SECURITY_REGISTRATION_MODE_OPEN = 'Open';
|
|
|
|
|
+ const SECURITY_REGISTRATION_MODE_RESTRICTED = 'Resricted';
|
|
|
|
|
+ const SECURITY_REGISTRATION_MODE_CLOSED = 'Closed';
|
|
|
|
|
|
|
|
let configSchema;
|
|
let configSchema;
|
|
|
let Config;
|
|
let Config;
|
|
@@ -18,7 +16,7 @@ module.exports = function(crowi) {
|
|
|
configSchema = new mongoose.Schema({
|
|
configSchema = new mongoose.Schema({
|
|
|
ns: { type: String, required: true, index: true },
|
|
ns: { type: String, required: true, index: true },
|
|
|
key: { type: String, required: true, index: true },
|
|
key: { type: String, required: true, index: true },
|
|
|
- value: { type: String, required: true }
|
|
|
|
|
|
|
+ value: { type: String, required: true },
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
function validateCrowi() {
|
|
function validateCrowi() {
|
|
@@ -31,7 +29,7 @@ module.exports = function(crowi) {
|
|
|
* default values when GROWI is cleanly installed
|
|
* default values when GROWI is cleanly installed
|
|
|
*/
|
|
*/
|
|
|
function getArrayForInstalling() {
|
|
function getArrayForInstalling() {
|
|
|
- let config = getDefaultCrowiConfigs();
|
|
|
|
|
|
|
+ const config = getDefaultCrowiConfigs();
|
|
|
|
|
|
|
|
// overwrite
|
|
// overwrite
|
|
|
config['app:fileUpload'] = true;
|
|
config['app:fileUpload'] = true;
|
|
@@ -49,7 +47,7 @@ module.exports = function(crowi) {
|
|
|
function getDefaultCrowiConfigs() {
|
|
function getDefaultCrowiConfigs() {
|
|
|
/* eslint-disable key-spacing */
|
|
/* eslint-disable key-spacing */
|
|
|
return {
|
|
return {
|
|
|
- //'app:installed' : "0.0.0",
|
|
|
|
|
|
|
+ // 'app:installed' : "0.0.0",
|
|
|
'app:confidential' : '',
|
|
'app:confidential' : '',
|
|
|
|
|
|
|
|
'app:fileUpload' : false,
|
|
'app:fileUpload' : false,
|
|
@@ -167,18 +165,18 @@ module.exports = function(crowi) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.getRestrictGuestModeLabels = function() {
|
|
configSchema.statics.getRestrictGuestModeLabels = function() {
|
|
|
- var labels = {};
|
|
|
|
|
- labels[SECURITY_RESTRICT_GUEST_MODE_DENY] = 'security_setting.guest_mode.deny';
|
|
|
|
|
|
|
+ const labels = {};
|
|
|
|
|
+ labels[SECURITY_RESTRICT_GUEST_MODE_DENY] = 'security_setting.guest_mode.deny';
|
|
|
labels[SECURITY_RESTRICT_GUEST_MODE_READONLY] = 'security_setting.guest_mode.readonly';
|
|
labels[SECURITY_RESTRICT_GUEST_MODE_READONLY] = 'security_setting.guest_mode.readonly';
|
|
|
|
|
|
|
|
return labels;
|
|
return labels;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.getRegistrationModeLabels = function() {
|
|
configSchema.statics.getRegistrationModeLabels = function() {
|
|
|
- var labels = {};
|
|
|
|
|
- labels[SECURITY_REGISTRATION_MODE_OPEN] = 'security_setting.registration_mode.open';
|
|
|
|
|
|
|
+ const labels = {};
|
|
|
|
|
+ labels[SECURITY_REGISTRATION_MODE_OPEN] = 'security_setting.registration_mode.open';
|
|
|
labels[SECURITY_REGISTRATION_MODE_RESTRICTED] = 'security_setting.registration_mode.restricted';
|
|
labels[SECURITY_REGISTRATION_MODE_RESTRICTED] = 'security_setting.registration_mode.restricted';
|
|
|
- labels[SECURITY_REGISTRATION_MODE_CLOSED] = 'security_setting.registration_mode.closed';
|
|
|
|
|
|
|
+ labels[SECURITY_REGISTRATION_MODE_CLOSED] = 'security_setting.registration_mode.closed';
|
|
|
|
|
|
|
|
return labels;
|
|
return labels;
|
|
|
};
|
|
};
|
|
@@ -188,7 +186,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
const originalConfig = crowi.getConfig();
|
|
const originalConfig = crowi.getConfig();
|
|
|
const newNSConfig = originalConfig[ns] || {};
|
|
const newNSConfig = originalConfig[ns] || {};
|
|
|
- Object.keys(config).forEach(function(key) {
|
|
|
|
|
|
|
+ Object.keys(config).forEach((key) => {
|
|
|
if (config[key] || config[key] === '' || config[key] === false) {
|
|
if (config[key] || config[key] === '' || config[key] === false) {
|
|
|
newNSConfig[key] = config[key];
|
|
newNSConfig[key] = config[key];
|
|
|
}
|
|
}
|
|
@@ -204,13 +202,12 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
// Execute only once for installing application
|
|
// Execute only once for installing application
|
|
|
configSchema.statics.applicationInstall = function(callback) {
|
|
configSchema.statics.applicationInstall = function(callback) {
|
|
|
- var Config = this;
|
|
|
|
|
- Config.count({ ns: 'crowi' }, function(err, count) {
|
|
|
|
|
|
|
+ const Config = this;
|
|
|
|
|
+ Config.count({ ns: 'crowi' }, (err, count) => {
|
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
|
return callback(new Error('Application already installed'), null);
|
|
return callback(new Error('Application already installed'), null);
|
|
|
}
|
|
}
|
|
|
- Config.updateNamespaceByArray('crowi', getArrayForInstalling(), function(err, configs) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ Config.updateNamespaceByArray('crowi', getArrayForInstalling(), (err, configs) => {
|
|
|
Config.updateConfigCache('crowi', configs);
|
|
Config.updateConfigCache('crowi', configs);
|
|
|
return callback(err, configs);
|
|
return callback(err, configs);
|
|
|
});
|
|
});
|
|
@@ -218,7 +215,7 @@ module.exports = function(crowi) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.setupConfigFormData = function(ns, config) {
|
|
configSchema.statics.setupConfigFormData = function(ns, config) {
|
|
|
- var defaultConfig = {};
|
|
|
|
|
|
|
+ let defaultConfig = {};
|
|
|
|
|
|
|
|
// set Default Settings
|
|
// set Default Settings
|
|
|
if (ns === 'crowi') {
|
|
if (ns === 'crowi') {
|
|
@@ -231,7 +228,7 @@ module.exports = function(crowi) {
|
|
|
if (!defaultConfig[ns]) {
|
|
if (!defaultConfig[ns]) {
|
|
|
defaultConfig[ns] = {};
|
|
defaultConfig[ns] = {};
|
|
|
}
|
|
}
|
|
|
- Object.keys(config[ns] || {}).forEach(function(key) {
|
|
|
|
|
|
|
+ Object.keys(config[ns] || {}).forEach((key) => {
|
|
|
if (config[ns][key] !== undefined) {
|
|
if (config[ns][key] !== undefined) {
|
|
|
defaultConfig[key] = config[ns][key];
|
|
defaultConfig[key] = config[ns][key];
|
|
|
}
|
|
}
|
|
@@ -241,21 +238,22 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
|
|
|
|
|
configSchema.statics.updateNamespaceByArray = function(ns, configs, callback) {
|
|
configSchema.statics.updateNamespaceByArray = function(ns, configs, callback) {
|
|
|
- var Config = this;
|
|
|
|
|
|
|
+ const Config = this;
|
|
|
if (configs.length < 0) {
|
|
if (configs.length < 0) {
|
|
|
return callback(new Error('Argument #1 is not array.'), null);
|
|
return callback(new Error('Argument #1 is not array.'), null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Object.keys(configs).forEach(function(key) {
|
|
|
|
|
- var value = configs[key];
|
|
|
|
|
|
|
+ Object.keys(configs).forEach((key) => {
|
|
|
|
|
+ const value = configs[key];
|
|
|
|
|
|
|
|
Config.findOneAndUpdate(
|
|
Config.findOneAndUpdate(
|
|
|
- { ns: ns, key: key },
|
|
|
|
|
- { ns: ns, key: key, value: JSON.stringify(value) },
|
|
|
|
|
- { upsert: true, },
|
|
|
|
|
- function(err, config) {
|
|
|
|
|
|
|
+ { ns, key },
|
|
|
|
|
+ { ns, key, value: JSON.stringify(value) },
|
|
|
|
|
+ { upsert: true },
|
|
|
|
|
+ (err, config) => {
|
|
|
debug('Config.findAndUpdate', err, config);
|
|
debug('Config.findAndUpdate', err, config);
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return callback(null, configs);
|
|
return callback(null, configs);
|
|
@@ -263,24 +261,26 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
configSchema.statics.findOneAndUpdateByNsAndKey = async function(ns, key, value) {
|
|
configSchema.statics.findOneAndUpdateByNsAndKey = async function(ns, key, value) {
|
|
|
return this.findOneAndUpdate(
|
|
return this.findOneAndUpdate(
|
|
|
- { ns: ns, key: key },
|
|
|
|
|
- { ns: ns, key: key, value: JSON.stringify(value) },
|
|
|
|
|
- { upsert: true, });
|
|
|
|
|
|
|
+ { ns, key },
|
|
|
|
|
+ { ns, key, value: JSON.stringify(value) },
|
|
|
|
|
+ { upsert: true },
|
|
|
|
|
+ );
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.getConfig = function(callback) {
|
|
configSchema.statics.getConfig = function(callback) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.loadAllConfig = function(callback) {
|
|
configSchema.statics.loadAllConfig = function(callback) {
|
|
|
- var Config = this
|
|
|
|
|
- , config = {};
|
|
|
|
|
|
|
+ const Config = this;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const config = {};
|
|
|
config.crowi = {}; // crowi namespace
|
|
config.crowi = {}; // crowi namespace
|
|
|
|
|
|
|
|
Config.find()
|
|
Config.find()
|
|
|
- .sort({ns: 1, key: 1})
|
|
|
|
|
- .exec(function(err, doc) {
|
|
|
|
|
-
|
|
|
|
|
- doc.forEach(function(el) {
|
|
|
|
|
|
|
+ .sort({ ns: 1, key: 1 })
|
|
|
|
|
+ .exec((err, doc) => {
|
|
|
|
|
+ doc.forEach((el) => {
|
|
|
if (!config[el.ns]) {
|
|
if (!config[el.ns]) {
|
|
|
config[el.ns] = {};
|
|
config[el.ns] = {};
|
|
|
}
|
|
}
|
|
@@ -341,10 +341,10 @@ module.exports = function(crowi) {
|
|
|
const method = process.env.FILE_UPLOAD || 'aws';
|
|
const method = process.env.FILE_UPLOAD || 'aws';
|
|
|
|
|
|
|
|
if (method == 'aws' && (
|
|
if (method == 'aws' && (
|
|
|
- !config.crowi['aws:accessKeyId'] ||
|
|
|
|
|
- !config.crowi['aws:secretAccessKey'] ||
|
|
|
|
|
- !config.crowi['aws:region'] ||
|
|
|
|
|
- !config.crowi['aws:bucket'])) {
|
|
|
|
|
|
|
+ !config.crowi['aws:accessKeyId']
|
|
|
|
|
+ || !config.crowi['aws:secretAccessKey']
|
|
|
|
|
+ || !config.crowi['aws:region']
|
|
|
|
|
+ || !config.crowi['aws:bucket'])) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -391,7 +391,7 @@ module.exports = function(crowi) {
|
|
|
};
|
|
};
|
|
|
configSchema.statics.isPublicWikiOnly = function(config) {
|
|
configSchema.statics.isPublicWikiOnly = function(config) {
|
|
|
const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
|
|
const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
|
|
|
- if ( publicWikiOnly === 'true' || publicWikiOnly == 1) {
|
|
|
|
|
|
|
+ if (publicWikiOnly === 'true' || publicWikiOnly == 1) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
@@ -438,7 +438,6 @@ module.exports = function(crowi) {
|
|
|
else {
|
|
else {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.attrWhiteList = function(config) {
|
|
configSchema.statics.attrWhiteList = function(config) {
|
|
@@ -579,14 +578,14 @@ module.exports = function(crowi) {
|
|
|
if (!config.notification) {
|
|
if (!config.notification) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- return (config.notification['slack:incomingWebhookUrl'] ? true : false);
|
|
|
|
|
|
|
+ return (!!config.notification['slack:incomingWebhookUrl']);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.isIncomingWebhookPrioritized = function(config) {
|
|
configSchema.statics.isIncomingWebhookPrioritized = function(config) {
|
|
|
if (!config.notification) {
|
|
if (!config.notification) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- return (config.notification['slack:isIncomingWebhookPrioritized'] ? true : false);
|
|
|
|
|
|
|
+ return (!!config.notification['slack:isIncomingWebhookPrioritized']);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.hasSlackToken = function(config) {
|
|
configSchema.statics.hasSlackToken = function(config) {
|
|
@@ -594,7 +593,7 @@ module.exports = function(crowi) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return (config.notification['slack:token'] ? true : false);
|
|
|
|
|
|
|
+ return (!!config.notification['slack:token']);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
configSchema.statics.getLocalconfig = function(config) {
|
|
configSchema.statics.getLocalconfig = function(config) {
|
|
@@ -663,9 +662,9 @@ module.exports = function(crowi) {
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
Config = mongoose.model('Config', configSchema);
|
|
Config = mongoose.model('Config', configSchema);
|
|
|
- Config.SECURITY_REGISTRATION_MODE_OPEN = SECURITY_REGISTRATION_MODE_OPEN;
|
|
|
|
|
|
|
+ Config.SECURITY_REGISTRATION_MODE_OPEN = SECURITY_REGISTRATION_MODE_OPEN;
|
|
|
Config.SECURITY_REGISTRATION_MODE_RESTRICTED = SECURITY_REGISTRATION_MODE_RESTRICTED;
|
|
Config.SECURITY_REGISTRATION_MODE_RESTRICTED = SECURITY_REGISTRATION_MODE_RESTRICTED;
|
|
|
- Config.SECURITY_REGISTRATION_MODE_CLOSED = SECURITY_REGISTRATION_MODE_CLOSED;
|
|
|
|
|
|
|
+ Config.SECURITY_REGISTRATION_MODE_CLOSED = SECURITY_REGISTRATION_MODE_CLOSED;
|
|
|
|
|
|
|
|
|
|
|
|
|
return Config;
|
|
return Config;
|