mirror of
https://github.com/wassname/talk.git
synced 2026-07-02 01:56:20 +08:00
fixes to cli
This commit is contained in:
@@ -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
@@ -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
@@ -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});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user