mirror of https://github.com/MISP/MISP
Merge pull request #8653 from JakubOnderka/workflow-fixes
fix: [workflow] Basic cleanuppull/8682/head
commit
aae65c42c6
|
@ -53,6 +53,7 @@ class AuditLogsController extends AppController
|
|||
'News',
|
||||
'Warninglist',
|
||||
'Workflow',
|
||||
'WorkflowBlueprint',
|
||||
];
|
||||
|
||||
public $paginate = [
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
App::uses('AppController', 'Controller');
|
||||
|
||||
/**
|
||||
* @property WorkflowBlueprint $WorkflowBlueprint
|
||||
*/
|
||||
class WorkflowBlueprintsController extends AppController
|
||||
{
|
||||
public $components = array(
|
||||
|
@ -14,10 +17,9 @@ class WorkflowBlueprintsController extends AppController
|
|||
$message = __('Default workflow blueprints updated');
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->saveSuccessResponse('WorkflowBlueprint', 'update', false, $this->response->type(), $message);
|
||||
} else {
|
||||
$this->Flash->success($message);
|
||||
$this->redirect(array('controller' => 'workflowBlueprints', 'action' => 'index'));
|
||||
}
|
||||
$this->Flash->success($message);
|
||||
$this->redirect(array('controller' => 'workflowBlueprints', 'action' => 'index'));
|
||||
}
|
||||
|
||||
public function index()
|
||||
|
@ -69,9 +71,7 @@ class WorkflowBlueprintsController extends AppController
|
|||
|
||||
public function delete($id)
|
||||
{
|
||||
$params = [
|
||||
];
|
||||
$this->CRUD->delete($id, $params);
|
||||
$this->CRUD->delete($id);
|
||||
if ($this->IndexFilter->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
|
@ -82,16 +82,15 @@ class WorkflowBlueprintsController extends AppController
|
|||
{
|
||||
$filters = $this->IndexFilter->harvestParameters(['format']);
|
||||
if (!empty($filters['format'])) {
|
||||
if ($filters['format'] == 'dot') {
|
||||
if ($filters['format'] === 'dot') {
|
||||
$dot = $this->WorkflowBlueprint->getDotNotation($id);
|
||||
return $this->RestResponse->viewData($dot, $this->response->type());
|
||||
} else if ($filters['format'] == 'mermaid') {
|
||||
} else if ($filters['format'] === 'mermaid') {
|
||||
$mermaid = $this->WorkflowBlueprint->getMermaid($id);
|
||||
return $this->RestResponse->viewData($mermaid, $this->response->type());
|
||||
}
|
||||
}
|
||||
$this->CRUD->view($id, [
|
||||
]);
|
||||
$this->CRUD->view($id);
|
||||
if ($this->IndexFilter->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
|
@ -102,11 +101,8 @@ class WorkflowBlueprintsController extends AppController
|
|||
public function import()
|
||||
{
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
$workflowBlueprintData = JsonTool::decode($this->request->data['WorkflowBlueprint']['data']);
|
||||
if ($workflowBlueprintData === null) {
|
||||
throw new MethodNotAllowedException(__('Error while decoding JSON'));
|
||||
}
|
||||
$this->request->data['WorkflowBlueprint']['data'] = JsonTool::encode($workflowBlueprintData);
|
||||
$workflowBlueprintData = $this->_jsonDecode($this->request->data['WorkflowBlueprint']['json']);
|
||||
$this->request->data = $workflowBlueprintData;
|
||||
$this->add();
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +114,11 @@ class WorkflowBlueprintsController extends AppController
|
|||
'id' => $id,
|
||||
]
|
||||
]);
|
||||
$content = JsonTool::encode($workflowBlueprint, JSON_PRETTY_PRINT);
|
||||
if (empty($workflowBlueprint)) {
|
||||
throw new NotFoundException(__('Invalid workflow blueprint'));
|
||||
}
|
||||
|
||||
$content = JsonTool::encode($workflowBlueprint, true);
|
||||
$this->response->body($content);
|
||||
$this->response->type('json');
|
||||
$this->response->download(sprintf('blueprint_%s_%s.json', str_replace(' ', '-', strtolower($workflowBlueprint['WorkflowBlueprint']['name'])), time()));
|
||||
|
|
|
@ -3735,7 +3735,7 @@ class AppModel extends Model
|
|||
* @param array $logging If the execution failure should be logged
|
||||
* @return boolean If the execution for the blocking path was a success
|
||||
*/
|
||||
public function executeTrigger($trigger_id, array $data=[], array &$blockingErrors=[], array $logging=[]): bool
|
||||
protected function executeTrigger($trigger_id, array $data=[], array &$blockingErrors=[], array $logging=[]): bool
|
||||
{
|
||||
if ($this->isTriggerCallable($trigger_id)) {
|
||||
$success = $this->Workflow->executeWorkflowForTriggerRouter($trigger_id, $data, $blockingErrors, $logging);
|
||||
|
@ -3749,8 +3749,17 @@ class AppModel extends Model
|
|||
return true;
|
||||
}
|
||||
|
||||
public function isTriggerCallable($trigger_id): bool
|
||||
protected function isTriggerCallable($trigger_id): bool
|
||||
{
|
||||
static $workflowEnabled;
|
||||
if ($workflowEnabled === null) {
|
||||
$workflowEnabled = (bool)Configure::read('Plugin.Workflow_enable');
|
||||
}
|
||||
|
||||
if (!$workflowEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->Workflow === null) {
|
||||
$this->Workflow = ClassRegistry::init('Workflow');
|
||||
}
|
||||
|
|
|
@ -515,14 +515,16 @@ class Attribute extends AppModel
|
|||
$kafkaPubTool = $this->getKafkaPubTool();
|
||||
$kafkaPubTool->publishJson($kafkaTopic, $attributeForPublish, $action);
|
||||
}
|
||||
$workflowErrors = [];
|
||||
$logging = [
|
||||
if ($isTriggerCallable) {
|
||||
$workflowErrors = [];
|
||||
$logging = [
|
||||
'model' => 'Attribute',
|
||||
'action' => $action,
|
||||
'id' => $attributeForPublish['Attribute']['id'],
|
||||
];
|
||||
$triggerData = $attributeForPublish;
|
||||
$this->executeTrigger('attribute-after-save', $triggerData, $workflowErrors, $logging);
|
||||
$triggerData = $attributeForPublish;
|
||||
$this->executeTrigger('attribute-after-save', $triggerData, $workflowErrors, $logging);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($created && isset($attribute['event_id']) && empty($attribute['skip_auto_increment'])) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('Folder', 'Utility');
|
||||
App::uses('File', 'Utility');
|
||||
|
||||
class WorkflowBlueprint extends AppModel
|
||||
{
|
||||
|
@ -18,10 +17,9 @@ class WorkflowBlueprint extends AppModel
|
|||
],
|
||||
];
|
||||
|
||||
public $belongsTo = [
|
||||
];
|
||||
|
||||
public $validate = [
|
||||
'name' => 'stringNotEmpty',
|
||||
'value' => [
|
||||
'stringNotEmpty' => [
|
||||
'rule' => ['stringNotEmpty']
|
||||
|
@ -92,11 +90,11 @@ class WorkflowBlueprint extends AppModel
|
|||
return $blueprint;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* __readBlueprintsFromRepo Reads blueprints from the misp-workflow-blueprints repository
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function __readBlueprintsFromRepo(): array
|
||||
{
|
||||
|
@ -114,6 +112,7 @@ class WorkflowBlueprint extends AppModel
|
|||
*
|
||||
* @param boolean $force
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($force=false)
|
||||
{
|
||||
|
@ -133,7 +132,6 @@ class WorkflowBlueprint extends AppModel
|
|||
if ($force || $blueprint_from_repo['timestamp'] > $existing_blueprint['timestamp']) {
|
||||
$blueprint_from_repo['id'] = $existing_blueprint['id'];
|
||||
$this->save($blueprint_from_repo);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$this->create();
|
||||
|
|
|
@ -1664,13 +1664,13 @@ $divider = $this->element('/genericElements/SideMenu/side_menu_divider');
|
|||
if ($isSiteAdmin) {
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'element_id' => 'edit',
|
||||
'url' => '/workflows/edit/' . h($id),
|
||||
'url' => '/workflowBlueprints/edit/' . h($id),
|
||||
'text' => __('Edit Workflow Blueprint')
|
||||
));
|
||||
}
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'url' => '/admin/audit_logs/index/model:WorkflowBlueprints/model_id:' . h($id),
|
||||
'text' => __('View worflow blueprint history'),
|
||||
'url' => '/admin/audit_logs/index/model:WorkflowBlueprint/model_id:' . h($id),
|
||||
'text' => __('View workflow blueprint history'),
|
||||
'requirement' => Configure::read('MISP.log_new_audit') && $canAccess('auditLogs', 'admin_index'),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ echo $this->element('genericElements/Form/genericForm', [
|
|||
'enctype' => 'multipart/form-data',
|
||||
],
|
||||
'data' => [
|
||||
'model' => 'Workflow',
|
||||
'model' => 'WorkflowBlueprint',
|
||||
'title' => __('Import Workflow Blueprint'),
|
||||
'description' => __('Paste a JSON of a Workflow blueprint to import it or provide a JSON file below.'),
|
||||
'fields' => [
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
'name' => __('Timestamp'),
|
||||
'sort' => 'WorkflowBlueprint.timestamp',
|
||||
'data_path' => 'WorkflowBlueprint.timestamp',
|
||||
'element' => 'datetime',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
echo $this->element('genericElements/IndexTable/scaffold', [
|
||||
'scaffold_data' => [
|
||||
'data' => [
|
||||
|
@ -73,11 +73,13 @@
|
|||
'url_params_data_paths' => ['WorkflowBlueprint.id'],
|
||||
'icon' => 'eye',
|
||||
'dbclickAction' => true,
|
||||
'title' => __('View'),
|
||||
],
|
||||
[
|
||||
'url' => $baseurl . '/workflowBlueprints/edit',
|
||||
'url_params_data_paths' => ['WorkflowBlueprint.id'],
|
||||
'icon' => 'edit',
|
||||
'title' => __('Edit'),
|
||||
],
|
||||
[
|
||||
'url' => $baseurl . '/workflowBlueprints/export',
|
||||
|
@ -86,13 +88,11 @@
|
|||
'icon' => 'download',
|
||||
],
|
||||
[
|
||||
|
||||
'onclick' => sprintf(
|
||||
'openGenericModal(\'%s/workflowBlueprints/delete/[onclick_params_data_path]\');',
|
||||
$baseurl
|
||||
),
|
||||
'onclick_params_data_path' => 'WorkflowBlueprint.id',
|
||||
'icon' => 'trash'
|
||||
'class' => 'modal-open',
|
||||
'url' => $baseurl . '/workflowBlueprints/delete/',
|
||||
'url_params_data_paths' => 'WorkflowBlueprint.id',
|
||||
'icon' => 'trash',
|
||||
'title' => __('Delete'),
|
||||
]
|
||||
]
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue