OCC or OCS to list only enabled users

Nextcloud version (eg, 12.0.2): 16.0.4
Operating system and version (eg, Ubuntu 17.04): Ubuntu 18.04
Apache or nginx version (eg, Apache 2.4.25): Nginx
PHP version (eg, 7.1): 7.2

How to list only the enabled users. Would also like to fetch the list of disabled users if possible. It doesn’t look possible using the OCC (command line) or OCS (API). Is there a way?

Thanks

I think it would be better to use OCC, there’s already a user:list command. Trying to find a way to make it happen, I see this function:

lib/private/User/Manager.php
I could add a parameter to fetch only enabled user?

/**
 * search by user id
 *
 * @param string $pattern
 * @param int $limit
 * @param int $offset
 * @return \OC\User\User[]
 */
public function search($pattern, $limit = null, $offset = null) {
	$users = array();
	foreach ($this->backends as $backend) {
		$backendUsers = $backend->getUsers($pattern, $limit, $offset);
		if (is_array($backendUsers)) {
			foreach ($backendUsers as $uid) {
				$users[$uid] = $this->getUserObject($uid, $backend);
			}
		}
	}

	uasort($users, function ($a, $b) {
		/**
		 * @var \OC\User\User $a
		 * @var \OC\User\User $b
		 */
		return strcasecmp($a->getUID(), $b->getUID());
	});
	return $users;
}

Or maybe I should modify directly core/Command/User/ListCommand.php

protected function execute(InputInterface $input, OutputInterface $output) {
	$users = $this->userManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset'));
	$this->writeArrayInOutputFormat($input, $output, $this->formatUsers($users));
}

Adding something like this

// Search in all users
		foreach ($usersTmp as $user) {
			if ($user->isEnabled()) { // Don't keep deactivated users
				...
			}
		}

Would like feedback from someone before trying it.
Thanks

Second option sounds good, of course, only being used if a certain flag is in the command. Do you want to open a PR?

A third option would be to use the database directly (in my case I could). I am not seeing any enabled flag in oc_users or oc_accounts. Where to find this information in the database?

@gary-kim do you know?

@eeight
It is stored in the oc_preferences table. You’ll find something like this in the table:

userid appid configkey configvalue
admin core enabled true
user1 core enabled false

I would still prefer not making a direct database call for this but maybe others will think differently.