mirror of https://github.com/MISP/MISP
new: [cli] added org list to the shell commands
- and some fixes to the rolespull/9613/head
parent
31d20f094f
commit
3aa1ddbe03
|
@ -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.');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue