mirror of https://github.com/MISP/MISP
chg: [workflows] Added enabled state
parent
d38b951569
commit
62107f14b9
|
@ -100,6 +100,32 @@ class WorkflowsController extends AppController
|
|||
$this->set('execution_path', $execution_path);
|
||||
}
|
||||
|
||||
public function enable($id)
|
||||
{
|
||||
$errors = $this->Workflow->toggleWorkflow($this->Auth->user(), $id, true);
|
||||
$redirectTarget = ['action' => 'index'];
|
||||
if (!empty($errors)) {
|
||||
return $this->__getFailResponseBasedOnContext($errors, null, 'edit', $this->Workflow->id, $redirectTarget);
|
||||
} else {
|
||||
$successMessage = __('Workflow enabled.');
|
||||
$savedWorkflow = $this->Workflow->fetchWorkflow($this->Auth->user(), $id);
|
||||
return $this->__getSuccessResponseBasedOnContext($successMessage, $savedWorkflow, 'edit', false, $redirectTarget);
|
||||
}
|
||||
}
|
||||
|
||||
public function disable($id)
|
||||
{
|
||||
$errors = $this->Workflow->toggleWorkflow($this->Auth->user(), $id, false);
|
||||
$redirectTarget = ['action' => 'index'];
|
||||
if (!empty($errors)) {
|
||||
return $this->__getFailResponseBasedOnContext($errors, null, 'edit', $this->Workflow->id, $redirectTarget);
|
||||
} else {
|
||||
$successMessage = __('Workflow disabled.');
|
||||
$savedWorkflow = $this->Workflow->fetchWorkflow($this->Auth->user(), $id);
|
||||
return $this->__getSuccessResponseBasedOnContext($successMessage, $savedWorkflow, 'edit', false, $redirectTarget);
|
||||
}
|
||||
}
|
||||
|
||||
public function editor($id = false)
|
||||
{
|
||||
$modules = $this->Workflow->getModules();
|
||||
|
|
|
@ -1697,6 +1697,7 @@ class AppModel extends Model
|
|||
`timestamp` int(11) NOT NULL DEFAULT 0,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`org_id` int(11) NOT NULL,
|
||||
`enabled` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`data` text,
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX `uuid` (`uuid`),
|
||||
|
|
|
@ -476,6 +476,24 @@ class Workflow extends AppModel
|
|||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* fetchWorkflow ACL-aware method. Basically find with ACL
|
||||
*
|
||||
* @param array $user
|
||||
* @param int|string $id
|
||||
* @param bool $enable
|
||||
* @param bool $throwErrors
|
||||
* @return array
|
||||
*/
|
||||
public function toggleWorkflow(array $user, $id, $enable=true, bool $throwErrors=true)
|
||||
{
|
||||
$errors = array();
|
||||
$workflow = $this->fetchWorkflow($user, $id, $throwErrors);
|
||||
$workflow['Workflow']['enabled'] = $enable;
|
||||
$errors = $this->saveAndReturnErrors($workflow, ['fieldList' => ['enabled']], $errors);
|
||||
return $errors;
|
||||
}
|
||||
|
||||
private function saveAndReturnErrors($data, $saveOptions = [], $errors = [])
|
||||
{
|
||||
$saveSuccess = $this->save($data, $saveOptions);
|
||||
|
@ -486,4 +504,5 @@ class Workflow extends AppModel
|
|||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,13 @@
|
|||
'sort' => 'Workflow.description',
|
||||
'data_path' => 'Workflow.description'
|
||||
],
|
||||
[
|
||||
'name' => __('Enabled'),
|
||||
'element' => 'boolean',
|
||||
'sort' => 'enabled',
|
||||
'class' => 'short',
|
||||
'data_path' => 'Workflow.enabled',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
|
@ -61,6 +68,42 @@
|
|||
'title' => __('Workflows'),
|
||||
'description' => __('You can create workflows relying on pipeline hooks to that can listen to triggers and then perform actions depending on some conditions'),
|
||||
'actions' => [
|
||||
[
|
||||
'title' => __('Enable'),
|
||||
'icon' => 'play',
|
||||
'postLink' => true,
|
||||
'url' => $baseurl . '/workflows/enable',
|
||||
'url_params_data_paths' => ['Workflow.id'],
|
||||
'postLinkConfirm' => __('Are you sure you want to enable this workflow?'),
|
||||
'complex_requirement' => array(
|
||||
'function' => function ($row, $options) use ($isSiteAdmin) {
|
||||
return $isSiteAdmin && !$options['datapath']['enabled'];
|
||||
},
|
||||
'options' => array(
|
||||
'datapath' => array(
|
||||
'enabled' => 'Workflow.enabled'
|
||||
)
|
||||
)
|
||||
),
|
||||
],
|
||||
[
|
||||
'title' => __('Disable'),
|
||||
'icon' => 'stop',
|
||||
'postLink' => true,
|
||||
'url' => $baseurl . '/workflows/disable',
|
||||
'url_params_data_paths' => ['Workflow.id'],
|
||||
'postLinkConfirm' => __('Are you sure you want to disable this workflow?'),
|
||||
'complex_requirement' => array(
|
||||
'function' => function ($row, $options) use ($isSiteAdmin) {
|
||||
return $isSiteAdmin && $options['datapath']['enabled'];
|
||||
},
|
||||
'options' => array(
|
||||
'datapath' => array(
|
||||
'enabled' => 'Workflow.enabled'
|
||||
)
|
||||
)
|
||||
),
|
||||
],
|
||||
[
|
||||
'url' => $baseurl . '/workflows/view',
|
||||
'url_params_data_paths' => ['Workflow.id'],
|
||||
|
|
Loading…
Reference in New Issue