Skip to content

Commit

Permalink
Merge branch 'develop' into issue/1336
Browse files Browse the repository at this point in the history
* develop:
  Require modules before plugins
  Change to ensureDirSync
  Fixes #1906
  Allow MongoDB authentication in install script
  Fix modules define
  Fix globalData
  Save isVisible and isHidden on blocks and components
  Fix context menu for page
  Remove config-sample.json
  Allow upgrade if missing frameworkRepository or authoringToolRepository
  Catch errors and return
  Fix route error logging
  fixed indenting
  update mailer to support custom connection url
  prompt user if custom connection url is used and dynamically build prompt also fixes issue with config options not added to config.json
  update config sample to include new config options
  Add instruction to component schema

# Conflicts:
#	frontend/src/core/app.js
  • Loading branch information
taylortom committed Mar 14, 2018
2 parents 073d0dc + 57df6ad commit f455c1f
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 104 deletions.
10 changes: 4 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,21 @@ module.exports = function(grunt) {

// Compiles frontend plugins
grunt.registerMultiTask('requireBundle', 'Generates a .js file with a bunch of imports for the path files', function() {
var requirePaths = '';
var modulePaths = '';
// Go through each subfolder in the plugins directory
var foldersArray = grunt.file.expand({ filter: "isDirectory" }, this.data.src);
// Check if any plugins are available
if (foldersArray.length === 0) {
requirePaths += "'";
modulePaths += "'";
}
foldersArray.forEach(function(path, index, folders) {
// Strip off front of path to make relative path to config file
var relativePath = path.replace(grunt.config.get('requirejs').dev.options.baseUrl, '').slice(1);
var splitter = "','";
if (index === folders.length - 1) splitter = "'";
requirePaths += relativePath + '/index' + splitter;
modulePaths += relativePath + '/index' + splitter;
});

var defineStatement = "define('" + this.target + "',['" + requirePaths +"]);";
grunt.file.write(this.data.dest, defineStatement);
grunt.file.write(this.data.dest, "define(['" + modulePaths +"], function() {});");
});

grunt.registerMultiTask('less', 'Compile Less files to CSS', function() {
Expand Down
22 changes: 0 additions & 22 deletions conf/config-sample.json

This file was deleted.

51 changes: 17 additions & 34 deletions frontend/src/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,30 @@
});
}

function loadAddOns(callback) {
/*
* FIXME we want to just be able to require these
* (this doesn't work in production mode)
*/
// ['modules/modules','plugins/plugins']
function loadModules(callback) {
require([
// modules
'modules/actions/index',
'modules/assetManagement/index',
'modules/browserStorage/index',
'modules/contentPane/index',
'modules/contextMenu/index',
'modules/editor/index',
'modules/filters/index',
'modules/globalMenu/index',
'modules/help/index',
'modules/location/index',
'modules/modal/index',
'modules/navigation/index',
'modules/notify/index',
'modules/options/index',
'modules/pluginManagement/index',
'modules/projects/index',
'modules/scaffold/index',
'modules/sidebar/index',
'modules/user/index',
'modules/userManagement/index',
'modules/modules'
], callback);
}

function loadPlugins(callback) {
require([
'plugins/plugins'
], callback);
}

/**
* Start app load
*/
* Start app load
*/
loadLibraries(function() {
loadCore(function() {
loadAddOns(function() {
// start session
// FIXME required here to avoid errors
require(['modules/user/models/sessionModel'], function(SessionModel) {
origin.startSession(new SessionModel());
loadModules(function() {
loadPlugins(function() {
// start session
// FIXME required here to avoid errors
require(['modules/user/models/sessionModel'], function(SessionModel) {
origin.startSession(new SessionModel());
});
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/core/models/blockModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ define(function(require) {
'title',
'_extensions',
'themeSettings',
'_onScreen'
'_onScreen',
'_isVisible',
'_isHidden'
]
});

Expand Down
5 changes: 4 additions & 1 deletion frontend/src/core/models/componentModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ define(function(require) {
'title',
'version',
'themeSettings',
'_onScreen'
'_onScreen',
'_isVisible',
'_isHidden',
'instruction'
]
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ define(function(require){
// TODO fragile HACK, refactor context menu code to allow what I want to do later...
openContextMenu: function(event) {
if(!event) return console.log('Error: needs a current target to attach the menu to...');
event.preventDefault() && event.stopPropagation();
event.preventDefault();
event.stopPropagation();

var fakeModel = new Backbone.Model({ _id: this.model.get('_id'), _type: 'page-min' });
var fakeView = new Backbone.View({ model: fakeModel });
Expand Down
83 changes: 66 additions & 17 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ installHelpers.getLatestFrameworkVersion(function(error, latestFrameworkTag) {
pattern: installHelpers.inputHelpers.numberValidator,
default: 27017
},
{
name: 'dbUser',
type: 'string',
description: 'Database server user',
pattern: installHelpers.inputHelpers.alphanumValidator,
default: ''
},
{
name: 'dbPass',
type: 'string',
description: 'Database server password',
pattern: installHelpers.inputHelpers.alphanumValidator,
default: ''
},
{
name: 'dbAuthSource',
type: 'string',
description: 'Database server authentication database',
pattern: installHelpers.inputHelpers.alphanumValidator,
default: 'admin'
},
{
name: 'dataRoot',
type: 'string',
Expand Down Expand Up @@ -128,7 +149,28 @@ installHelpers.getLatestFrameworkVersion(function(error, latestFrameworkTag) {
before: installHelpers.inputHelpers.toBoolean,
default: 'N'
},
confirmConnectionUrl: {
name: 'useSmtpConnectionUrl',
type: 'string',
description: "Will you use a URL to connect to your smtp Server y/N",
before: installHelpers.inputHelpers.toBoolean,
default: 'N'
},
configure: [
{
name: 'fromAddress',
type: 'string',
description: "Sender email address",
default: '',
},
{
name: 'rootUrl',
type: 'string',
description: "The url this install will be accessible from",
default: '' // set using default server options
}
],
configureService: [
{
name: 'smtpService',
type: 'string',
Expand All @@ -149,18 +191,14 @@ installHelpers.getLatestFrameworkVersion(function(error, latestFrameworkTag) {
replace: installHelpers.inputHelpers.passwordReplace,
default: '',
before: installHelpers.inputHelpers.passwordBefore
},
{
name: 'fromAddress',
type: 'string',
description: "Sender email address",
default: '',
},
}
],
configureConnectionUrl: [
{
name: 'rootUrl',
name: 'smtpConnectionUrl',
type: 'string',
description: "The url this install will be accessible from",
default: '' // set using default server options
description: "Custom connection URL: smtps://user%40gmail.com:[email protected]/?pool=true",
default: 'none',
}
]
}
Expand Down Expand Up @@ -218,6 +256,7 @@ installHelpers.getLatestFrameworkVersion(function(error, latestFrameworkTag) {
}
console.log('');
if(!fs.existsSync('conf/config.json')) {
fs.ensureDirSync('conf');
return start();
}
console.log('Found an existing config.json file. Do you want to use the values in this file during install?');
Expand Down Expand Up @@ -300,14 +339,24 @@ function configureFeatures(callback) {
if(!result.useSmtp || USE_CONFIG && configResults.useSmtp !== 'y') {
return cb();
}
for(var i = 0, count = inputData.features.smtp.configure.length; i < count; i++) {
if(inputData.features.smtp.configure[i].name === 'rootUrl') {
inputData.features.smtp.configure[i].default = `http://${configResults.serverName}:${configResults.serverPort}`;
}
}
installHelpers.getInput(inputData.features.smtp.configure, function(result) {
// prompt user if custom connection url or well-known-service should be used
installHelpers.getInput(inputData.features.smtp.confirmConnectionUrl, function(result) {
addConfig(result);
cb();
var smtpConfig;
if (result.useSmtpConnectionUrl === true) {
smtpConfig = inputData.features.smtp.configure.concat(inputData.features.smtp.configureConnectionUrl);
} else {
smtpConfig = inputData.features.smtp.configure.concat(inputData.features.smtp.configureService);
}
for(var i = 0, count = smtpConfig.length; i < count; i++) {
if(smtpConfig[i].name === 'rootUrl') {
smtpConfig[i].default = `http://${configResults.serverName}:${configResults.serverPort}`;
}
}
installHelpers.getInput(smtpConfig, function(result) {
addConfig(result);
cb();
});
});
});
}
Expand Down
8 changes: 5 additions & 3 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ Database.prototype.addModel = function (modelName, schema, next) {
if (err) {
return next(err);
}

// all models use lowercase
self.addSchema(modelName, importedSchema);
try {
self.addSchema(modelName, importedSchema);
} catch(e) {
return next(e);
}
next(null, importedSchema);
});
};
Expand Down
50 changes: 34 additions & 16 deletions lib/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,52 @@ var configuration = require('./configuration'),
var Mailer = function () {
// Read the mail settings from the config.json
this.isEnabled = configuration.getConfig('useSmtp');
this.useSmtpConnectionUrl = configuration.getConfig('useSmtpConnectionUrl');

this.service = configuration.getConfig('smtpService');
this.user = configuration.getConfig('smtpUsername');
this.pass = configuration.getConfig('smtpPassword');
this.from = configuration.getConfig('fromAddress');
this.connectionUrl = configuration.getConfig('smtpConnectionUrl');

// check that required settings exist
this.validateSettings = function() {
var errors = [];

if(this.service === '') errors.push('smtpService');
if(this.user === '') errors.push('smtpUsername');
if(this.pass === '') errors.push('smtpPassword');
if(this.from === '') errors.push('fromAddress');
// validate based on selected connection
if (this.useSmtpConnectionUrl === true) {
if (this.connectionUrl === '') errors.push('smtpConnectionUrl');
} else {
if (this.service === '') errors.push('smtpService');
if (this.user === '') errors.push('smtpUsername');
if (this.pass === '') errors.push('smtpPassword');
}

// generic configuration options
if (this.from === '') errors.push('fromAddress');

if(errors.length > 0) {
if (errors.length > 0) {
throw new Error('Mailer requires the following settings to function: ' + errors.toString());
}
};

// Configure the credentials for the specified sevice
// See http://www.nodemailer.com/ for options
this.transporter = nodemailer.createTransport({
service: this.service,
auth: {
user: this.user,
pass: this.pass
}
});

var smtpConfig;

if (this.useSmtpConnectionUrl) {
smtpConfig = this.connectionUrl;
} else {
smtpConfig = {
service: this.service,
auth: {
user: this.user,
pass: this.pass
}
};
}
this.transporter = nodemailer.createTransport(smtpConfig);
};

Mailer.prototype.send = function (toAddress, subject, text, templateData, callback) {
Expand All @@ -62,7 +80,7 @@ Mailer.prototype.send = function (toAddress, subject, text, templateData, callba
return callback(e);
}
configure(mailOptions, _.bind(function(error, options) {
if(error) {
if (error) {
return callback(error);
}
// Send mail with defined transport object
Expand All @@ -82,13 +100,13 @@ Mailer.prototype.send = function (toAddress, subject, text, templateData, callba

var configure = function (options, callback) {
// TODO localise these errors
if(!helpers.isValidEmail(options.to)) {
if (!helpers.isValidEmail(options.to)) {
return callback(new Error("Can't send email, '" + options.to + "' is not a valid email address"));
}
if(!helpers.isValidEmail(options.from)) {
if (!helpers.isValidEmail(options.from)) {
return callback(new Error("Can't send email, '" + options.from + "' is not a valid email address"));
}
if(options.templateData !== null) {
if (options.templateData !== null) {
var template = new EmailTemplate(path.join(__dirname, 'templates', options.templateData.name));
template.render(options, function (error, results) {
if (error) {
Expand Down
5 changes: 3 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ Router.prototype.init = function (app) {
var route = require(itemPath);
server.use(route);
} catch(e) {
var detail = (e.code === 'MODULE_NOT_FOUND') ? ', no index.js found' : ` (${e})`;
logger.log('error', `Cannot load routes/${item}${detail}`);
// if the top-level module can't be loaded, it's the index.js
var detail = (e.message.indexOf(`'${itemPath}'`) === -1) ? e.message : 'no index.js found';
logger.log('error', `Cannot load routes/${item}, ${detail}`);
}
});
});
Expand Down
Loading

0 comments on commit f455c1f

Please sign in to comment.