chg: [internal] Clean up EventsController::view code

pull/6384/head
Jakub Onderka 2020-10-04 13:16:33 +02:00
parent e379a218ea
commit 617c7ef475
1 changed files with 25 additions and 26 deletions

View File

@ -1583,32 +1583,31 @@ class EventsController extends AppController
$conditions['includeServerCorrelations'] = $this->params['named']['includeServerCorrelations']; $conditions['includeServerCorrelations'] = $this->params['named']['includeServerCorrelations'];
} }
$results = $this->Event->fetchEvent($this->Auth->user(), $conditions); $results = $this->Event->fetchEvent($this->Auth->user(), $conditions);
if (!empty($this->params['named']['includeGranularCorrelations'])) { if (empty($results)) {
foreach ($results as $k => $event) { throw new NotFoundException(__('Invalid event'));
if (!empty($event['RelatedAttribute'])) { }
foreach ($event['RelatedAttribute'] as $attribute_id => $relation) { $event = $results[0];
foreach ($event['Attribute'] as $k2 => $attribute) {
if ((int)$attribute['id'] == $attribute_id) { // Attach related attributes to proper attribute
$results[$k]['Attribute'][$k2]['RelatedAttribute'][] = $relation; if (!empty($this->params['named']['includeGranularCorrelations']) && !empty($event['RelatedAttribute'])) {
break 2; foreach ($event['RelatedAttribute'] as $attribute_id => $relation) {
} foreach ($event['Attribute'] as $k2 => $attribute) {
} if ((int)$attribute['id'] == $attribute_id) {
foreach ($event['Object'] as $k2 => $object) { $event['Attribute'][$k2]['RelatedAttribute'][] = $relation;
foreach ($object['Attribute'] as $k3 => $attribute) { break 2;
if ((int)$attribute['id'] == $attribute_id) { }
$results[$k]['Object'][$k2]['Attribute'][$k3]['RelatedAttribute'][] = $relation; }
break 3; foreach ($event['Object'] as $k2 => $object) {
} foreach ($object['Attribute'] as $k3 => $attribute) {
} if ((int)$attribute['id'] == $attribute_id) {
$event['Object'][$k2]['Attribute'][$k3]['RelatedAttribute'][] = $relation;
break 3;
} }
} }
} }
} }
} }
if (empty($results)) {
throw new NotFoundException(__('Invalid event'));
}
$event = $results[0];
$this->Event->id = $event['Event']['id']; $this->Event->id = $event['Event']['id'];
if (isset($this->params['named']['searchFor']) && $this->params['named']['searchFor'] !== '') { if (isset($this->params['named']['searchFor']) && $this->params['named']['searchFor'] !== '') {
$this->__applyQueryString($event, $this->params['named']['searchFor']); $this->__applyQueryString($event, $this->params['named']['searchFor']);
@ -1622,11 +1621,11 @@ class EventsController extends AppController
if ($this->_isRest()) { if ($this->_isRest()) {
$this->set('event', $event); $this->set('event', $event);
} } else {
$this->set('deleted', isset($deleted) ? ($deleted == 2 ? 0 : 1) : 0); $this->set('deleted', isset($deleted) ? ($deleted == 2 ? 0 : 1) : 0);
$this->set('includeRelatedTags', (!empty($this->params['named']['includeRelatedTags'])) ? 1 : 0); $this->set('includeRelatedTags', (!empty($this->params['named']['includeRelatedTags'])) ? 1 : 0);
$this->set('includeDecayScore', (!empty($this->params['named']['includeDecayScore'])) ? 1 : 0); $this->set('includeDecayScore', (!empty($this->params['named']['includeDecayScore'])) ? 1 : 0);
if (!$this->_isRest()) {
if ($this->_isSiteAdmin() && $event['Event']['orgc_id'] !== $this->Auth->user('org_id')) { if ($this->_isSiteAdmin() && $event['Event']['orgc_id'] !== $this->Auth->user('org_id')) {
$this->Flash->info(__('You are currently logged in as a site administrator and about to edit an event not belonging to your organisation. This goes against the sharing model of MISP. Use a normal user account for day to day work.')); $this->Flash->info(__('You are currently logged in as a site administrator and about to edit an event not belonging to your organisation. This goes against the sharing model of MISP. Use a normal user account for day to day work.'));
} }