diff --git a/bin/cli b/bin/cli
index 002288648..5b52d96b9 100755
--- a/bin/cli
+++ b/bin/cli
@@ -4,45 +4,13 @@
* Module dependencies.
*/
-const program = require('commander');
-const pkg = require('../package.json');
-const dotenv = require('dotenv');
const util = require('../util');
-
-//==============================================================================
-// Setting up the program command line arguments.
-//==============================================================================
-
-program
- .version(pkg.version)
- .option('-c, --config [path]', 'Specify the configuration file to load')
- .option('--pid [path]', 'Specify a path to output the current PID to')
- .parse(process.argv);
-
-if (program.config) {
- let r = dotenv.config({
- path: program.config
- });
-
- if (r.error) {
- throw r.error;
- }
-}
-
-// If the `--pid` flag is used, put the current pid there.
-if (program.pid) {
- util.pid(program.pid);
-}
-
-// Perform rewrites to the runtime environment variables based on the contents
-// of the process.env.REWRITE_ENV if it exists. This is done here as it is the
-// entrypoint for the entire application.
-require('env-rewrite').rewrite();
+const program = require('./commander');
program
.command('serve', 'serve the application')
.command('assets', 'interact with assets')
- .command('settings', 'work with the application settings')
+ .command('setup', 'setup the application')
.command('jobs', 'work with the job queues')
.command('users', 'work with the application auth')
.parse(process.argv);
diff --git a/bin/cli-assets b/bin/cli-assets
index f7d6a0bbb..76ca5735b 100755
--- a/bin/cli-assets
+++ b/bin/cli-assets
@@ -4,8 +4,7 @@
* Module dependencies.
*/
-const program = require('commander');
-const pkg = require('../package.json');
+const program = require('./commander');
const parseDuration = require('parse-duration');
const Table = require('cli-table');
const AssetModel = require('../models/asset');
@@ -86,9 +85,6 @@ function refreshAssets(ageString) {
// Setting up the program command line arguments.
//==============================================================================
-program
- .version(pkg.version);
-
program
.command('list')
.description('list all the assets in the database')
diff --git a/bin/cli-jobs b/bin/cli-jobs
index 879927197..4d348fabb 100755
--- a/bin/cli-jobs
+++ b/bin/cli-jobs
@@ -4,7 +4,7 @@
* Module dependencies.
*/
-const program = require('commander');
+const program = require('./commander');
const scraper = require('../services/scraper');
const mailer = require('../services/mailer');
const util = require('../util');
diff --git a/bin/cli-serve b/bin/cli-serve
index c8cf37a47..0427dcf34 100755
--- a/bin/cli-serve
+++ b/bin/cli-serve
@@ -1,9 +1,9 @@
#!/usr/bin/env node
const app = require('../app');
+const program = require('./commander');
const debug = require('debug')('talk:server');
const http = require('http');
-const init = require('../init');
const scraper = require('../services/scraper');
const mailer = require('../services/mailer');
const kue = require('../services/kue');
@@ -86,27 +86,15 @@ function onListening() {
* Start the app.
*/
function startApp() {
- init().then(() => {
- /**
- * Listen on provided port, on all network interfaces.
- */
- server.listen(port);
- server.on('error', onError);
- server.on('listening', onListening);
- })
- .catch((err) => {
- console.error(err);
- util.shutdown(1);
- });
+ /**
+ * Listen on provided port, on all network interfaces.
+ */
+ server.listen(port);
+ server.on('error', onError);
+ server.on('listening', onListening);
}
-/**
- * Module dependencies.
- */
-
-const program = require('commander');
-
//==============================================================================
// Setting up the program command line arguments.
//==============================================================================
diff --git a/bin/cli-settings b/bin/cli-settings
deleted file mode 100755
index ba4305ce3..000000000
--- a/bin/cli-settings
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env node
-
-/**
- * Module dependencies.
- */
-
-const program = require('commander');
-const mongoose = require('../services/mongoose');
-const SettingsService = require('../services/settings');
-const util = require('../util');
-
-// Register the shutdown criteria.
-util.onshutdown([
- () => mongoose.disconnect()
-]);
-
-//==============================================================================
-// Setting up the program command line arguments.
-//==============================================================================
-
-program
- .command('init')
- .description('initilizes the talk settings')
- .action(() => {
- const defaults = {
- moderation: 'POST',
- wordlist: {
- banned: [],
- suspect: []
- }
- };
-
- SettingsService
- .init(defaults)
- .then(() => {
- console.log('Created settings object.');
- util.shutdown();
- })
- .catch((err) => {
- console.error(`failed to create the settings object ${JSON.stringify(err)}`);
- util.shutdown(1);
- });
- });
-
-program.parse(process.argv);
-
-// If there is no command listed, output help.
-if (!process.argv.slice(2).length) {
- program.outputHelp();
- util.shutdown();
-}
diff --git a/bin/cli-setup b/bin/cli-setup
new file mode 100755
index 000000000..eaa2b90b1
--- /dev/null
+++ b/bin/cli-setup
@@ -0,0 +1,88 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+const program = require('./commander');
+const inquirer = require('inquirer');
+const mongoose = require('../services/mongoose');
+const SettingModel = require('../models/setting');
+const SettingsService = require('../services/settings');
+const util = require('../util');
+
+// Register the shutdown criteria.
+util.onshutdown([
+ () => mongoose.disconnect()
+]);
+
+//==============================================================================
+// Setting up the program command line arguments.
+//==============================================================================
+
+program
+ .description('runs the setup wizard to setup the application')
+ .option('--defaults', 'apply defaults for config instead of prompting')
+ .parse(process.argv);
+
+//==============================================================================
+// Setup the application
+//==============================================================================
+
+SettingsService
+ .init()
+ .then((settings) => {
+ if (program.defaults) {
+ return settings.save();
+ }
+
+ console.log('We\'ll ask you some questions in order to setup your installation of Talk.\n');
+
+ return inquirer.prompt([
+ {
+ type: 'input',
+ name: 'organizationName',
+ message: 'Organization Name',
+ default: settings.organizationName,
+ validate: (input) => {
+ if (input && input.length > 0) {
+ return true;
+ }
+
+ return 'Organization Name is required.';
+ }
+ },
+ {
+ type: 'list',
+ choices: SettingModel.MODERATION_OPTIONS,
+ name: 'moderation',
+ default: settings.moderation,
+ message: 'Select a moderation mode'
+ },
+ {
+ type: 'confirm',
+ name: 'requireEmailConfirmation',
+ default: settings.requireEmailConfirmation,
+ message: 'Should emails always be confirmed'
+ }
+ ])
+ .then((answers) => {
+
+ // Update the settings that were changed.
+ Object.keys(answers).forEach((key) => {
+ if (answers[key] !== undefined) {
+ settings[key] = answers[key];
+ }
+ });
+
+ return settings.save();
+ });
+ })
+ .then(() => {
+ console.log('Talk is now installed!');
+ util.shutdown();
+ })
+ .catch((err) => {
+ console.error(err);
+ util.shutdown(1);
+ });
diff --git a/bin/cli-users b/bin/cli-users
index a7e9cdbda..072a143ee 100755
--- a/bin/cli-users
+++ b/bin/cli-users
@@ -4,105 +4,132 @@
* Module dependencies.
*/
-const program = require('commander');
-const pkg = require('../package.json');
-const prompt = require('prompt');
+const program = require('./commander');
+const inquirer = require('inquirer');
const UsersService = require('../services/users');
const UserModel = require('../models/user');
const mongoose = require('../services/mongoose');
const util = require('../util');
const Table = require('cli-table');
+const validateRequired = (msg = 'Field is required', len = 1) => (input) => {
+ if (input && input.length >= len) {
+ return true;
+ }
+
+ return msg;
+};
+
// Regeister the shutdown criteria.
util.onshutdown([
() => mongoose.disconnect()
]);
+function getUserCreateAnswers(options) {
+ if (options.flag_mode) {
+
+ let user = {
+ email: options.email,
+ password: options.password,
+ confirmPassword: options.password,
+ displayName: options.name,
+ roles: []
+ };
+
+ if (options.role && UserModel.USER_ROLES.indexOf(options.role) > -1) {
+ user.roles = [options.role];
+ }
+
+ return Promise.resolve(user);
+ }
+
+ return inquirer.prompt([
+ {
+ name: 'email',
+ message: 'Email',
+ format: 'email',
+ validate: validateRequired('Email is required')
+ },
+ {
+ name: 'password',
+ message: 'Password',
+ type: 'password',
+ filter: (password) => {
+ return UsersService
+ .isValidPassword(password)
+ .catch((err) => {
+ throw err.message;
+ });
+ }
+ },
+ {
+ name: 'confirmPassword',
+ message: 'Confirm Password',
+ type: 'password',
+ filter: (confirmPassword) => {
+ return UsersService
+ .isValidPassword(confirmPassword)
+ .catch((err) => {
+ throw err.message;
+ });
+ }
+ },
+ {
+ name: 'displayName',
+ message: 'Display Name',
+ filter: (displayName) => {
+ return UsersService
+ .isValidDisplayName(displayName)
+ .catch((err) => {
+ throw err.message;
+ });
+ }
+ },
+ {
+ name: 'roles',
+ message: 'User Role',
+ type: 'checkbox',
+ choices: UserModel.USER_ROLES
+ }
+ ]);
+}
+
/**
* Prompts for input and registers a user based on those.
*/
function createUser(options) {
- return new Promise((resolve, reject) => {
-
- if (options.flag_mode) {
- return resolve({
- email: options.email,
- password: options.password,
- displayName: options.name,
- role: options.role
- });
- }
-
- prompt.start();
-
- prompt.get([
- {
- name: 'email',
- description: 'Email',
- format: 'email',
- required: true
- },
- {
- name: 'password',
- description: 'Password',
- hidden: true,
- required: true
- },
- {
- name: 'confirmPassword',
- description: 'Confirm Password',
- hidden: true,
- required: true
- },
- {
- name: 'displayName',
- description: 'Display Name',
- required: true
- },
- {
- name: 'role',
- description: 'User Role',
- required: false
- }
- ], (err, result) => {
- if (err) {
- return reject(err);
+ getUserCreateAnswers(options)
+ .then((answers) => {
+ if (answers.password !== answers.confirmPassword) {
+ return Promise.reject(new Error('Passwords do not match'));
}
- if (result.password !== result.confirmPassword) {
- return reject(new Error('Passwords do not match'));
- }
+ return answers;
+ })
+ .then((answers) => {
+ return UsersService
+ .createLocalUser(answers.email.trim(), answers.password.trim(), answers.displayName.trim())
+ .then((user) => {
+ console.log(`Created user ${user.id}.`);
- resolve(result);
- });
- })
- .then((result) => {
- return UsersService.createLocalUser(result.email.trim(), result.password.trim(), result.displayName.trim())
- .then((user) => {
- console.log(`Created user ${user.id}.`);
-
- let role = result.role ? result.role.trim() : null;
-
- if (role && role.length > 0) {
- return UsersService
- .addRoleToUser(user.id, role)
- .then(() => {
- console.log(`Added the admin ${result.role.trim()} to User ${user.id}.`);
- util.shutdown();
- })
- .catch((err) => {
- console.error(err);
- util.shutdown();
- });
- } else {
- util.shutdown();
- }
+ if (answers.roles.length > 0) {
+ return Promise.all(answers.roles.map((role) => {
+ return UsersService
+ .addRoleToUser(user.id, role)
+ .then(() => {
+ console.log(`Added the role ${role} to User ${user.id}.`);
+ });
+ }));
+ }
+ });
+ })
+ .then(() => {
+ util.shutdown();
})
.catch((err) => {
console.error(err);
util.shutdown();
});
- });
}
/**
@@ -127,44 +154,34 @@ function deleteUser(userID) {
* Changes the password for a user.
*/
function passwd(userID) {
- prompt.start();
-
- prompt.get([
+ inquirer.prompt([
{
name: 'password',
- description: 'Password',
- hidden: true,
- required: true
+ message: 'Password',
+ type: 'password',
+ validate: validateRequired('Password is required')
},
{
name: 'confirmPassword',
- description: 'Confirm Password',
- hidden: true,
- required: true
+ message: 'Confirm Password',
+ type: 'password',
+ validate: validateRequired('Confirm Password is required')
}
- ], (err, result) => {
- if (err) {
- console.error(err);
- util.shutdown();
- return;
+ ])
+ .then((answers) => {
+ if (answers.password !== answers.confirmPassword) {
+ return Promise.reject(new Error('Password mismatch'));
}
- if (result.password !== result.confirmPassword) {
- console.error(new Error('Password mismatch'));
- util.shutdown(1);
- return;
- }
-
- UsersService
- .changePassword(userID, result.password)
- .then(() => {
- console.log('Password changed.');
- util.shutdown();
- })
- .catch((err) => {
- console.error(err);
- util.shutdown(1);
- });
+ return UsersService.changePassword(userID, answers.password);
+ })
+ .then(() => {
+ console.log('Password changed.');
+ util.shutdown();
+ })
+ .catch((err) => {
+ console.error(err);
+ util.shutdown(1);
});
}
@@ -273,6 +290,13 @@ function mergeUsers(dstUserID, srcUserID) {
* @param {String} role the role to add
*/
function addRole(userID, role) {
+
+ if (UserModel.USER_ROLES.indexOf(role) === -1) {
+ console.error(`Role '${role}' is not supported. Supported roles are ${UserModel.USER_ROLES.join(', ')}.`);
+ util.shutdown(1);
+ return;
+ }
+
UsersService
.addRoleToUser(userID, role)
.then(() => {
@@ -291,6 +315,13 @@ function addRole(userID, role) {
* @param {String} role the role to remove
*/
function removeRole(userID, role) {
+
+ if (UserModel.USER_ROLES.indexOf(role) === -1) {
+ console.error(`Role '${role}' is not supported. Supported roles are ${UserModel.USER_ROLES.join(', ')}.`);
+ util.shutdown(1);
+ return;
+ }
+
UsersService
.removeRoleFromUser(userID, role)
.then(() => {
@@ -375,9 +406,6 @@ function enableUser(userID) {
// Setting up the program command line arguments.
//==============================================================================
-program
- .version(pkg.version);
-
program
.command('create')
.option('--email [email]', 'Email to use')
diff --git a/bin/commander.js b/bin/commander.js
new file mode 100644
index 000000000..2a3d1e363
--- /dev/null
+++ b/bin/commander.js
@@ -0,0 +1,46 @@
+const pkg = require('../package.json');
+const dotenv = require('dotenv');
+const fs = require('fs');
+const program = require('commander');
+const util = require('../util');
+
+// Perform rewrites to the runtime environment variables based on the contents
+// of the process.env.REWRITE_ENV if it exists. This is done here as it is the
+// entrypoint for the entire application.
+require('env-rewrite').rewrite();
+
+//==============================================================================
+// Setting up the program command line arguments.
+//==============================================================================
+
+const parseArgs = require('minimist')(process.argv.slice(2), {
+ alias: {
+ 'c': 'config'
+ },
+ string: [
+ 'config',
+ 'pid'
+ ],
+ default: {
+ 'config': null,
+ 'pid': null
+ }
+});
+
+if (parseArgs.config) {
+ let envConfig = dotenv.parse(fs.readFileSync(parseArgs.config, {encoding: 'utf8'}));
+
+ Object.keys(envConfig).forEach((k) => {
+ process.env[k] = envConfig[k];
+ });
+}
+
+// If the `--pid` flag is used, put the current pid there.
+if (parseArgs.pid) {
+ util.pid(parseArgs.pid);
+}
+
+module.exports = program
+ .version(pkg.version)
+ .option('-c, --config [path]', 'Specify the configuration file to load')
+ .option('--pid [path]', 'Specify a path to output the current PID to');
diff --git a/circle.yml b/circle.yml
index c511715a5..99b7d852b 100644
--- a/circle.yml
+++ b/circle.yml
@@ -14,7 +14,7 @@ database:
post:
# Initialize the settings in the database, this will create indicies for the
# database.
- - ./bin/cli settings init
+ - ./bin/cli setup --defaults
- sleep 2
test:
diff --git a/client/coral-admin/src/containers/Configure/CommentSettings.js b/client/coral-admin/src/containers/Configure/CommentSettings.js
index 0ccb5f820..1051bb0ba 100644
--- a/client/coral-admin/src/containers/Configure/CommentSettings.js
+++ b/client/coral-admin/src/containers/Configure/CommentSettings.js
@@ -32,6 +32,10 @@ const updateModeration = (updateSettings, mod) => () => {
updateSettings({moderation});
};
+const updateEmailConfirmation = (updateSettings, verify) => () => {
+ updateSettings({requireEmailConfirmation: !verify});
+};
+
const updateInfoBoxEnable = (updateSettings, infoBox) => () => {
const infoBoxEnable = !infoBox;
updateSettings({infoBoxEnable});
@@ -67,106 +71,123 @@ const CommentSettings = ({fetchingSettings, title, updateSettings, settingsError
return
{lang.t('configure.enable-pre-moderation-text')}
- {lang.t('configure.comment-count-text-pre')}
-
- {lang.t('configure.comment-count-text-post')}
- {
- errors.charCount &&
-
-
-
- {lang.t('configure.include-comment-stream-desc')} -
-+ {lang.t('configure.require-email-verification-text')} +
+
+ {lang.t('configure.comment-count-text-pre')}
+
+ {lang.t('configure.comment-count-text-post')}
+ {
+ errors.charCount &&
+
+
+
+ {lang.t('configure.include-comment-stream-desc')} +
+