mirror of https://github.com/MISP/MISP
new: [workflow:organisation_if] New module
parent
79eff086cb
commit
cbec4a4894
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
include_once APP . 'Model/WorkflowModules/WorkflowBaseModule.php';
|
||||
|
||||
class Module_organisation_if extends WorkflowBaseLogicModule
|
||||
{
|
||||
public $id = 'organisation-if';
|
||||
public $name = 'IF :: Organisation';
|
||||
public $description = 'Organisation IF / ELSE condition block. The `then` output will be used if the encoded conditions is satisfied, otherwise the `else` output will be used.';
|
||||
public $icon = 'code-branch';
|
||||
public $inputs = 1;
|
||||
public $outputs = 2;
|
||||
public $html_template = 'if';
|
||||
public $params = [];
|
||||
|
||||
private $Organisation;
|
||||
private $operators = [
|
||||
'equals' => 'Is',
|
||||
'not_equals' => 'Is not',
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->Organisation = ClassRegistry::init('Organisation');
|
||||
$orgs = $this->Organisation->find('list', [
|
||||
'fields' => ['id', 'name'],
|
||||
'order' => 'LOWER(name)'
|
||||
]);
|
||||
$this->params = [
|
||||
[
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'org' => __('Owner Organisation'),
|
||||
'orgc' => __('Creator Organisation'),
|
||||
],
|
||||
'default' => 'orgc',
|
||||
'label' => 'Organisation Type',
|
||||
],
|
||||
[
|
||||
'type' => 'select',
|
||||
'label' => 'Condition',
|
||||
'default' => 'equals',
|
||||
'options' => $this->operators,
|
||||
],
|
||||
[
|
||||
'type' => 'picker',
|
||||
'multiple' => false,
|
||||
'label' => 'Organisation',
|
||||
'options' => $orgs,
|
||||
'default' => 1,
|
||||
'placeholder' => __('Pick an organisation'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function exec(array $node, WorkflowRoamingData $roamingData, array &$errors=[]): bool
|
||||
{
|
||||
parent::exec($node, $roamingData, $errors);
|
||||
$params = $this->getParamsWithValues($node);
|
||||
|
||||
$org_type = $params['Organisation Type']['value'];
|
||||
$operator = $params['Condition']['value'];
|
||||
$org_id = $params['Organisation']['value'];
|
||||
$data = $roamingData->getData();
|
||||
$path = 'Event.org_id';
|
||||
if ($org_type == 'orgc') {
|
||||
$path = 'Event.orgc_id';
|
||||
}
|
||||
$extracted_org = intval(Hash::get($data, $path)) ?? -1;
|
||||
$eval = $this->evaluateCondition($extracted_org, $operator, $org_id);
|
||||
return !empty($eval);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue