UNPKG

@strapi/strapi

Version:

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite

63 lines (59 loc) 1.86 kB
'use strict'; var commander = require('commander'); var CLITable = require('cli-table3'); var chalk = require('chalk'); var core = require('@strapi/core'); var helpers = require('../../utils/helpers.js'); /** * List admin users */ const action = async ()=>{ const appContext = await core.compileStrapi(); const app = await core.createStrapi(appContext).load(); const list = await app.admin.services.user.findPage({ select: [ 'id', 'firstname', 'lastname', 'email', 'isActive', 'blocked' ], populate: [ 'roles' ], pageSize: 100 }); const infoTable = new CLITable({ head: [ chalk.blue('ID'), chalk.blue('Email'), chalk.blue('First Name'), chalk.blue('Last Name'), chalk.blue('Active'), chalk.blue('Blocked'), chalk.blue('Roles') ] }); list.results.forEach((user)=>{ const roles = user.roles.map((role)=>role.name).join(', '); infoTable.push([ user.id, user.email, user.firstname, user.lastname, user.isActive === true ? chalk.green('true') : chalk.red('false'), user.blocked === true ? chalk.red('true') : chalk.green('false'), roles.length > 0 ? roles : chalk.yellow('No roles assigned') ]); }); console.log(infoTable.toString()); await app.destroy(); }; /** * `$ strapi admin:list-users` */ const command = ()=>{ return commander.createCommand('admin:list-users').alias('admin:list').description('List all the admin users').action(helpers.runAction('admin:list-users', action)); }; exports.action = action; exports.command = command; //# sourceMappingURL=list-users.js.map