fixes to cli

This commit is contained in:
Wyatt Johnson
2017-11-20 13:29:40 -07:00
parent 2706e47f85
commit 45e27fd6ad
3 changed files with 5 additions and 32 deletions
-7
View File
@@ -289,13 +289,6 @@ function mergeUsers(dstUserID, srcUserID) {
* @param {String} role the role to add
*/
function addRole(userID, role) {
if (USER_ROLES.indexOf(role) === -1) {
console.error(`Role '${role}' is not supported. Supported roles are ${USER_ROLES.join(', ')}.`);
util.shutdown(1);
return;
}
UsersService
.addRoleToUser(userID, role)
.then(() => {
+2 -1
View File
@@ -91,7 +91,8 @@ const UserSchema = new Schema({
// user.
roles: [{
type: String,
enum: USER_ROLES
enum: USER_ROLES,
required: true
}],
// Status stores the user status information regarding permissions,
+3 -24
View File
@@ -552,43 +552,22 @@ class UsersService {
* Adds a role to a user.
* @param {String} id id of a user
* @param {String} role role to add
* @param {Function} done callback after the operation is complete
*/
static async addRoleToUser(id, role) {
const roles = [];
// Check to see if the user role is in the allowable set of roles.
if (role && USER_ROLES.indexOf(role) === -1) {
// User role is not supported! Error out here.
throw new Error(`role ${role} is not supported`);
} else if(role) {
roles.push(role);
}
return UserModel.update({id}, {$set: {roles}});
static addRoleToUser(id, role) {
return UserModel.update({id}, {$addToSet: {roles: role}}, {runValidators: true});
}
/**
* Removes a role from a user.
* @param {String} id id of a user
* @param {String} role role to remove
* @param {Function} done callback after the operation is complete
*/
static async removeRoleFromUser(id, role) {
// Check to see if the user role is in the allowable set of roles.
if (USER_ROLES.indexOf(role) === -1) {
// User role is not supported! Error out here.
throw new Error(`role ${role} is not supported`);
}
return UserModel.update({id}, {
$pull: {
roles: role
}
});
}, {runValidators: true});
}
/**