From 413db123c4e99606336fdb80593b02948a06a2c1 Mon Sep 17 00:00:00 2001 From: gaba Date: Thu, 8 Dec 2016 12:18:19 -1000 Subject: [PATCH 1/3] Type on comment. --- bin/cli-settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli-settings b/bin/cli-settings index c639a5ca5..e7ba30151 100755 --- a/bin/cli-settings +++ b/bin/cli-settings @@ -15,7 +15,7 @@ const mongoose = require('../mongoose'); const Setting = require('../models/setting'); const util = require('../util'); -// Regeister the shutdown criteria. +// Register the shutdown criteria. util.onshutdown([ () => mongoose.disconnect() ]); From a86b5f84ac2fb6196ec111cbda1c997a19ca99d9 Mon Sep 17 00:00:00 2001 From: gaba Date: Thu, 8 Dec 2016 12:18:53 -1000 Subject: [PATCH 2/3] Adds a role option when creating the user. --- bin/cli-users | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/bin/cli-users b/bin/cli-users index 2e0dc84e6..e77259301 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -34,6 +34,7 @@ function createUser(options) { email: options.email, password: options.password, displayName: options.name, + role: options.role }); } @@ -62,6 +63,11 @@ function createUser(options) { name: 'displayName', description: 'Display Name', required: true + }, + { + name: 'role', + description: 'User Role', + required: false } ], (err, result) => { if (err) { @@ -76,15 +82,24 @@ function createUser(options) { }); }) .then((result) => { - return User.createLocalUser(result.email.trim(), result.password.trim(), result.displayName.trim()); - }) - .then((user) => { - console.log(`Created user ${user.id}.`); - util.shutdown(); - }) - .catch((err) => { - console.error(err); - util.shutdown(); + return User.createLocalUser(result.email.trim(), result.password.trim(), result.displayName.trim()) + .then((user) => { + console.log(`Created user ${user.id}.`); + User + .addRoleToUser(user.id, result.role.trim()) + .then(() => { + console.log(`Added the admin ${result.role.trim()} to User ${user.id}.`); + util.shutdown(); + }) + .catch((err) => { + console.error(err); + util.shutdown(1); + }); + }) + .catch((err) => { + console.error(err); + util.shutdown(); + }); }); } @@ -330,6 +345,7 @@ program .option('--email [email]', 'Email to use') .option('--password [password]', 'Password to use') .option('--name [name]', 'Name to use') + .option('--role [role]', 'Role to add') .option('-f, --flag_mode', 'Source from flags instead of prompting') .description('create a new user') .action(createUser); From bc88cd1e9d231b85a871140626e91f29fe298fd8 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 8 Dec 2016 17:23:31 -0500 Subject: [PATCH 3/3] Adjusted promise --- bin/cli-users | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/cli-users b/bin/cli-users index e77259301..012eba9d4 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -85,15 +85,12 @@ function createUser(options) { return User.createLocalUser(result.email.trim(), result.password.trim(), result.displayName.trim()) .then((user) => { console.log(`Created user ${user.id}.`); - User + + return User .addRoleToUser(user.id, result.role.trim()) .then(() => { console.log(`Added the admin ${result.role.trim()} to User ${user.id}.`); util.shutdown(); - }) - .catch((err) => { - console.error(err); - util.shutdown(1); }); }) .catch((err) => {