From 6da7ba5b7ad236d251664ae2e53ab0a4d3010585 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Mon, 10 Oct 2022 22:26:08 +0200 Subject: [PATCH] fix: [workflow] Importing blueprints --- app/Controller/WorkflowBlueprintsController.php | 11 ++++++----- app/Model/WorkflowBlueprint.php | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Controller/WorkflowBlueprintsController.php b/app/Controller/WorkflowBlueprintsController.php index 172157d18..09dafa520 100644 --- a/app/Controller/WorkflowBlueprintsController.php +++ b/app/Controller/WorkflowBlueprintsController.php @@ -101,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']['json']); - 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(); } } @@ -117,6 +114,10 @@ class WorkflowBlueprintsController extends AppController 'id' => $id, ] ]); + if (empty($workflowBlueprint)) { + throw new NotFoundException(__('Invalid workflow blueprint')); + } + $content = JsonTool::encode($workflowBlueprint, true); $this->response->body($content); $this->response->type('json'); diff --git a/app/Model/WorkflowBlueprint.php b/app/Model/WorkflowBlueprint.php index 18ee714c3..b82d5b4b5 100644 --- a/app/Model/WorkflowBlueprint.php +++ b/app/Model/WorkflowBlueprint.php @@ -19,6 +19,7 @@ class WorkflowBlueprint extends AppModel public $validate = [ + 'name' => 'stringNotEmpty', 'value' => [ 'stringNotEmpty' => [ 'rule' => ['stringNotEmpty'] @@ -111,6 +112,7 @@ class WorkflowBlueprint extends AppModel * * @param boolean $force * @return void + * @throws Exception */ public function update($force=false) {