From 05cf0563e15b050b95c456d7f4b5acd63d3ae1b0 Mon Sep 17 00:00:00 2001 From: iglocska Date: Mon, 7 May 2018 10:43:21 +0200 Subject: [PATCH] new: First implementation of the Noticelist system ready --- app/Controller/AttributesController.php | 6 +++++ app/Controller/Component/ACLComponent.php | 9 +++++++ app/Model/AppModel.php | 2 +- app/Model/Noticelist.php | 33 +++++++++++++++++++++++ app/View/Attributes/add.ctp | 14 +++++++++- app/View/Elements/global_menu.ctp | 3 ++- app/webroot/js/misp.js | 27 +++++++++++++++++++ 7 files changed, 91 insertions(+), 3 deletions(-) diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index dbd06799b..595cf0f37 100644 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -368,6 +368,9 @@ class AttributesController extends AppController { foreach ($distributionLevels as $key => $value) { $info['distribution'][$key] = array('key' => $value, 'desc' => $this->Attribute->distributionDescriptions[$key]['formdesc']); } + $this->loadModel('Noticelist'); + $notice_list_triggers = $this->Noticelist->getTriggerData(); + $this->set('notice_list_triggers', json_encode($notice_list_triggers, true)); $this->set('info', $info); $this->set('typeDefinitions', $this->Attribute->typeDefinitions); $this->set('categoryDefinitions', $this->Attribute->categoryDefinitions); @@ -937,6 +940,9 @@ class AttributesController extends AppController { $this->set('categoryDefinitions', $categoryDefinitions); $this->set('compositeTypes', $this->Attribute->getCompositeTypes()); $this->set('action', $this->action); + $this->loadModel('Noticelist'); + $notice_list_triggers = $this->Noticelist->getTriggerData(); + $this->set('notice_list_triggers', json_encode($notice_list_triggers, true)); $this->render('add'); } diff --git a/app/Controller/Component/ACLComponent.php b/app/Controller/Component/ACLComponent.php index fdb268cf9..17dc9bd3b 100644 --- a/app/Controller/Component/ACLComponent.php +++ b/app/Controller/Component/ACLComponent.php @@ -213,6 +213,15 @@ class ACLComponent extends Component { 'delete' => array(), 'index' => array('*'), ), + 'noticelists' => array( + 'delete' => array(), + 'enableNoticelist' => array(), + 'getToggleField' => array(), + 'index' => array('*'), + 'toggleEnable' => array(), + 'update' => array(), + 'view' => array('*') + ), 'objects' => array( 'add' => array('perm_add'), 'addValueField' => array('perm_add'), diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index beef1c9d5..23666916d 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -955,7 +955,7 @@ class AppModel extends Model { 'email' => 'SYSTEM', 'action' => 'update_database', 'user_id' => 0, - 'title' => 'Successfuly executed the SQL query for ' . $command, + 'title' => 'Successfuly executed the SQL query for ' . $command, 'change' => 'The executed SQL query was: ' . $sql )); } catch (Exception $e) { diff --git a/app/Model/Noticelist.php b/app/Model/Noticelist.php index a3b41702f..6509fa66a 100644 --- a/app/Model/Noticelist.php +++ b/app/Model/Noticelist.php @@ -90,4 +90,37 @@ class Noticelist extends AppModel{ return $this->validationErrors; } } + + public function getTriggerData($scope = 'attribute') { + $noticelists = $this->find('all', array( + 'conditions' => array('enabled' => 1), + 'recursive' => -1, + 'contain' => 'NoticelistEntry' + )); + $noticelist_triggers = array(); + $validTriggers = array( + 'attribute' => array( + 'category', + 'type' + ) + ); + foreach ($noticelists as $noticelist) { + foreach ($noticelist['NoticelistEntry'] as $entry) { + if (in_array('attribute', $entry['data']['scope'])) { + foreach ($entry['data']['field'] as $data_field) { + if (in_array($data_field, $validTriggers[$scope])) { + foreach ($entry['data']['value'] as $value) { + $noticelist_triggers[$data_field][$value][] = array( + 'message' => $entry['data']['message'], + 'list_id' => $noticelist['Noticelist']['id'], + 'list_name' => $noticelist['Noticelist']['name'] + ); + } + } + } + } + } + } + return $noticelist_triggers; + } } diff --git a/app/View/Attributes/add.ctp b/app/View/Attributes/add.ctp index df39de3c9..2ada4dc45 100644 --- a/app/View/Attributes/add.ctp +++ b/app/View/Attributes/add.ctp @@ -81,7 +81,7 @@ ?> - +

@@ -104,6 +104,7 @@ } ?>