new: [cli] added org list to the shell commands

- and some fixes to the roles
pull/9613/head
iglocska 2024-03-07 14:49:24 +01:00
parent 31d20f094f
commit 3aa1ddbe03
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,64 @@
<?php
/**
* @property User $User
* @property Log $Log
* @property UserLoginProfile $UserLoginProfile
*/
class OrganisationShell extends AppShell
{
public $uses = ['Organisation'];
public function getOptionParser()
{
$parser = parent::getOptionParser();
$parser->addSubcommand('list', [
'help' => __('Get list of organisations.'),
'parser' => [
'arguments' => [
'filter' => ['help' => __('Filter the list by name.'), 'required' => false],
'local' => ['help' => __('Filter the list by local/known organisations.'), 'required' => false],
],
'options' => [
'json' => ['help' => __('Output as JSON.'), 'boolean' => true],
],
]
]);
return $parser;
}
public function list()
{
$filter = $this->args[0] ?? null;
$local = isset($this->args[1]) ? $this->args[1] : null;
$conditions = [];
if ($filter) {
$conditions = ['OR' => [
'Organisation.name LIKE' => "%$filter%",
'Organisation.uuid LIKE' => "%$filter%"
]];
}
if ($local !== null) {
$conditions['OR'][] = [
'Organisation.local' => $local
];
}
$organisations = $this->Organisation->find('all', [
'recursive' => -1,
'conditions' => $conditions
]);
if ($this->params['json']) {
$this->out($this->json($organisations));
} else {
foreach ($organisations as $organisation) {
$this->out(sprintf(
'%d. [%s] %s',
$organisation['Organisation']['id'],
$organisation['Organisation']['uuid'],
$organisation['Organisation']['name']
));
}
$this->out(count($organisations) . ' hits.');
}
}
}

View File

@ -31,7 +31,7 @@ class RoleShell extends AppShell
$filter = $this->args[0] ?? null;
if ($filter) {
$conditions = ['OR' => [
'Role.name LIKE' => "%$userId%"
'Role.name LIKE' => "%$filter%"
]];
} else {
$conditions = [];
@ -51,5 +51,6 @@ class RoleShell extends AppShell
));
}
}
$this->out(count($roles) . ' hits.');
}
}