From 5deca0ad4fd8bb4512d7e8109c404e7944908487 Mon Sep 17 00:00:00 2001 From: lesion Date: Fri, 30 Jun 2023 23:50:01 +0200 Subject: [PATCH] minor --- server/cli.js | 4 +- server/cli/accounts.js | 92 ------------------------------------------ 2 files changed, 2 insertions(+), 94 deletions(-) delete mode 100644 server/cli/accounts.js diff --git a/server/cli.js b/server/cli.js index bec0cf8a..7f0d3b3e 100755 --- a/server/cli.js +++ b/server/cli.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const pkg = require('../package.json') const path = require('path') -const accountsCLI = require('./cli/accounts') +const usersCLI = require('./cli/users') process.env.cwd = process.env.GANCIO_DATA || path.resolve('./') @@ -29,7 +29,7 @@ require('yargs') return absolute_config_path }}) .command(['start', 'run', '$0'], 'Start gancio', {}, start) - .command(['accounts'], 'Manage accounts', accountsCLI) + .command(['users'], 'Manage users', usersCLI) .help('h') .alias('h', 'help') .epilog('Made with ❤ by underscore hacklab - https://gancio.org') diff --git a/server/cli/accounts.js b/server/cli/accounts.js deleted file mode 100644 index c248eee6..00000000 --- a/server/cli/accounts.js +++ /dev/null @@ -1,92 +0,0 @@ -let db -function _initializeDB () { - const config = require('../config') - config.log_level = 'error' - db = require('../api/models/index') - return db.initialize() -} - -async function modify (args) { - await _initializeDB() - const helpers = require('../helpers') - const { User } = require('../api/models/models') - const user = await User.findOne({ where: { email: args.account } }) - console.log() - if (!user) { - console.error(`User ${args.account} not found`) - return - } - - if (args['reset-password']) { - const password = helpers.randomString() - user.password = password - await user.save() - console.log(`New password for user ${user.email} is '${password}'`) - } - - if (args.admin) { - user.is_admin = true - await user.save() - } - await db.close() -} - -async function create (args) { - await _initializeDB() - const { User } = require('../api/models/models') - const user = await User.create({ - email: args.email, - is_active: true, - is_admin: args.admin || false - }).catch(e => console.error(String(e))) - console.error(JSON.stringify(user, null, 2)) - await db.close() -} - - -async function remove (args) { - await _initializeDB() - const { User } = require('../api/models/models') - const user = await User.findOne({ - where: { email: args.email } - }) - if (user) { - await user.destroy() - } - await db.close() -} - -async function list () { - await _initializeDB() - const { User } = require('../api/models/models') - const users = await User.findAll() - console.log() - users.forEach(u => console.log(`${u.id}\tadmin: ${u.is_admin}\tenabled: ${u.is_active}\temail: ${u.email}`)) - console.log() - await db.close() -} - -const accountsCLI = yargs => yargs - .command('list', 'List all accounts', list) - .command('modify', 'Modify', { - account: { - describe: 'Account to modify', - type: 'string', - demandOption: true - }, - 'reset-password': { - describe: 'Resets the password of the given account ', - type: 'boolean' - }, - admin: { describe: 'Define this account as administrator', type: 'boolean' } - }, modify) - .command('create [admin]', 'Create an account', { - admin: { describe: 'Define this account as administrator', type: 'boolean' } - }, create) - .command('remove ', 'Remove an account', {}, remove) - .positional('email', { describe: 'account email or username', type: 'string', demandOption: true }) - .recommendCommands() - .demandCommand(1, '') - .argv - -module.exports = accountsCLI \ No newline at end of file