mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-29 14:06:09 +02:00
Suggestion: option to trigger List of pending users. #272
This commit is contained in:
parent
67ac86ac05
commit
f56e30442a
2 changed files with 82 additions and 9 deletions
|
@ -59,6 +59,15 @@ Actions:
|
||||||
|
|
||||||
group USERNAME [+|-]GROUP Adds (+) or removes (-) user from a group
|
group USERNAME [+|-]GROUP Adds (+) or removes (-) user from a group
|
||||||
|
|
||||||
|
list [FILTER] List users with optional FILTER.
|
||||||
|
|
||||||
|
Valid filters:
|
||||||
|
all : All users (default).
|
||||||
|
disabled : Disabled users.
|
||||||
|
inactive : Inactive users.
|
||||||
|
active : Active (regular) users.
|
||||||
|
locked : Locked users.
|
||||||
|
|
||||||
info arguments:
|
info arguments:
|
||||||
--security Include security information in output
|
--security Include security information in output
|
||||||
|
|
||||||
|
|
|
@ -460,6 +460,64 @@ function twoFactorAuthOTP(user) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function listUsers() {
|
||||||
|
// oputil user list [disabled|inactive|active|locked|all]
|
||||||
|
// :TODO: --after TIMESTAMP (new users)
|
||||||
|
// :TODO: --sort name|id
|
||||||
|
let listWhat;
|
||||||
|
if (argv._.length > 2) {
|
||||||
|
listWhat = argv._[argv._.length - 1];
|
||||||
|
} else {
|
||||||
|
listWhat = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
const User = require('../../core/user');
|
||||||
|
if (![ 'all' ].concat(Object.keys(User.AccountStatus)).includes(listWhat)) {
|
||||||
|
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
(callback) => {
|
||||||
|
const UserProps = require('../../core/user_property');
|
||||||
|
|
||||||
|
const userListOpts = {
|
||||||
|
properties : [
|
||||||
|
UserProps.AccountStatus,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
User.getUserList(userListOpts, (err, userList) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('all' === listWhat) {
|
||||||
|
return callback(null, userList);
|
||||||
|
}
|
||||||
|
|
||||||
|
const accountStatusFilter = User.AccountStatus[listWhat].toString();
|
||||||
|
|
||||||
|
return callback(null, userList.filter(user => {
|
||||||
|
return user[UserProps.AccountStatus] === accountStatusFilter;
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(userList, callback) => {
|
||||||
|
userList.forEach(user => {
|
||||||
|
|
||||||
|
console.info(`${user.userId}: ${user.userName}`);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
if(err) {
|
||||||
|
return console.error(err.reason ? err.reason : err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function handleUserCommand() {
|
function handleUserCommand() {
|
||||||
function errUsage() {
|
function errUsage() {
|
||||||
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
return printUsageAndSetExitCode(getHelpFor('User'), ExitCodes.ERROR);
|
||||||
|
@ -470,20 +528,25 @@ function handleUserCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const action = argv._[1];
|
const action = argv._[1];
|
||||||
const usernameIdx = [
|
const userRequired = ![ 'list' ].includes(action);
|
||||||
'pw', 'pass', 'passwd', 'password',
|
|
||||||
'group',
|
|
||||||
'mv', 'rename',
|
|
||||||
'2fa-otp', 'otp'
|
|
||||||
].includes(action) ? argv._.length - 2 : argv._.length - 1;
|
|
||||||
const userName = argv._[usernameIdx];
|
|
||||||
|
|
||||||
if(!userName) {
|
let userName;
|
||||||
|
if (userRequired) {
|
||||||
|
const usernameIdx = [
|
||||||
|
'pw', 'pass', 'passwd', 'password',
|
||||||
|
'group',
|
||||||
|
'mv', 'rename',
|
||||||
|
'2fa-otp', 'otp'
|
||||||
|
].includes(action) ? argv._.length - 2 : argv._.length - 1;
|
||||||
|
userName = argv._[usernameIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!userName && userRequired) {
|
||||||
return errUsage();
|
return errUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
initAndGetUser(userName, (err, user) => {
|
initAndGetUser(userName, (err, user) => {
|
||||||
if(err) {
|
if(userName && err) {
|
||||||
process.exitCode = ExitCodes.ERROR;
|
process.exitCode = ExitCodes.ERROR;
|
||||||
return console.error(err.message);
|
return console.error(err.message);
|
||||||
}
|
}
|
||||||
|
@ -512,6 +575,7 @@ function handleUserCommand() {
|
||||||
|
|
||||||
'2fa-otp' : twoFactorAuthOTP,
|
'2fa-otp' : twoFactorAuthOTP,
|
||||||
otp : twoFactorAuthOTP,
|
otp : twoFactorAuthOTP,
|
||||||
|
list : listUsers,
|
||||||
}[action] || errUsage)(user, action);
|
}[action] || errUsage)(user, action);
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue