From 1784b5d76fb5f8b4b73562223fb20fad34296d9d Mon Sep 17 00:00:00 2001 From: chrisr3d Date: Sat, 28 Sep 2019 02:35:22 +0200 Subject: [PATCH] fix: [stix 1/2 import] Making the publish checkbox work as expected - Publishing as exxpected when the option is checked AND the user has the right to publish --- app/Controller/EventsController.php | 16 ++++++++++++++-- app/Model/Event.php | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 628000092..9518b9e1e 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -2080,7 +2080,13 @@ class EventsController extends AppController $tempFile = new File($tmpDir . DS . $randomFileName, true, 0644); $tempFile->write($this->request->input()); $tempFile->close(); - $result = $this->Event->upload_stix($this->Auth->user(), $randomFileName, $stix_version, $original_file); + $result = $this->Event->upload_stix( + $this->Auth->user(), + $randomFileName, + $stix_version, + $original_file, + $this->data['Event']['publish'] + ); if (is_array($result)) { return $this->RestResponse->saveSuccessResponse('Events', 'upload_stix', false, $this->response->type(), 'STIX document imported, event\'s created: ' . implode(', ', $result) . '.'); } elseif (is_numeric($result)) { @@ -2098,7 +2104,13 @@ class EventsController extends AppController $randomFileName = $this->Event->generateRandomFileName(); $tmpDir = APP . "files" . DS . "scripts" . DS . "tmp"; move_uploaded_file($this->data['Event']['stix']['tmp_name'], $tmpDir . DS . $randomFileName); - $result = $this->Event->upload_stix($this->Auth->user(), $randomFileName, $stix_version, $original_file); + $result = $this->Event->upload_stix( + $this->Auth->user(), + $randomFileName, + $stix_version, + $original_file, + $this->data['Event']['publish'] + ); if (is_array($result)) { $this->Flash->success(__('STIX document imported, event\'s created: ' . implode(', ', $result) . '.')); $this->redirect(array('action' => 'index')); diff --git a/app/Model/Event.php b/app/Model/Event.php index ab366fe5e..112a21334 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -5818,7 +5818,7 @@ class Event extends AppModel return $this->save($event); } - public function upload_stix($user, $filename, $stix_version, $original_file) + public function upload_stix($user, $filename, $stix_version, $original_file, $publish) { App::uses('Folder', 'Utility'); App::uses('File', 'Utility'); @@ -5855,6 +5855,9 @@ class Event extends AppModel if ($original_file) { $this->add_original_file($tempFile, $original_file, $created_id, $stix_version); } + if ($publish && $user['Role']['perm_publish']) { + $this->publish($this->getID(), null); + } return $created_id; } return $validationIssues;