From 4f336482907ffd52a5618781b66f51f256e57562 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 26 Jan 2024 16:05:35 +0100 Subject: [PATCH] chg: [analyst-data:UI] Added support of relation for object + refactoring + fixes --- app/Model/MispObject.php | 9 ++++- app/Model/Relationship.php | 12 ++++--- app/View/AnalystData/add.ctp | 3 +- app/View/Elements/Events/View/row_object.ctp | 24 +++++++++++-- .../Elements/Events/View/row_proposal.ctp | 24 +++++++++++-- .../genericElements/Analyst_data/generic.ctp | 36 +++++++++++++------ 6 files changed, 85 insertions(+), 23 deletions(-) diff --git a/app/Model/MispObject.php b/app/Model/MispObject.php index 6f9600aec..d4a34decd 100644 --- a/app/Model/MispObject.php +++ b/app/Model/MispObject.php @@ -569,11 +569,18 @@ class MispObject extends AppModel if (isset($options['fields'])) { $params['fields'] = $options['fields']; } + $contain = []; + if (isset($options['contain'])) { + $contain = $options['contain']; + } + if (empty($contain['Event'])) { + $contain = ['Event' => ['distribution', 'id', 'user_id', 'orgc_id', 'org_id']]; + } $results = $this->find('all', array( 'conditions' => $params['conditions'], 'recursive' => -1, 'fields' => $params['fields'], - 'contain' => array('Event' => array('distribution', 'id', 'user_id', 'orgc_id', 'org_id')), + 'contain' => $contain, 'sort' => false )); return $results; diff --git a/app/Model/Relationship.php b/app/Model/Relationship.php index ca864c86d..7236df676 100644 --- a/app/Model/Relationship.php +++ b/app/Model/Relationship.php @@ -64,24 +64,23 @@ class Relationship extends AnalystData 'conditions' => [ ['Attribute.uuid' => $uuid], ], - 'contain' => ['Event' => 'Orgc',] + 'contain' => ['Event' => 'Orgc', 'Object',] ]; $data = $this->Attribute->fetchAttributeSimple($user, $params); $data = $this->rearrangeData($data, 'Attribute'); - $data['Attribute']['Organisation'] = $data['Attribute']['Event']['Orgc']; - $data['Attribute']['orgc_uuid'] = $data['Attribute']['Event']['Orgc']['uuid']; - unset($data['Attribute']['Event']['Orgc']); } else if ($type == 'Object') { $this->Object = ClassRegistry::init('MispObject'); $params = [ 'conditions' => [ ['Object.uuid' => $uuid], - ] + ], + 'contain' => ['Event' => 'Orgc',] ]; $data = $this->Object->fetchObjectSimple($user, $params); if (!empty($data)) { $data = $data[0]; } + $data = $this->rearrangeData($data, 'Object'); } else if ($type == 'Note') { $this->Note = ClassRegistry::init('Note'); $params = [ @@ -118,6 +117,9 @@ class Relationship extends AnalystData } } } + $data[$objectType]['Organisation'] = $data[$objectType]['Event']['Orgc']; + $data[$objectType]['orgc_uuid'] = $data[$objectType]['Event']['Orgc']['uuid']; + unset($data[$objectType]['Event']['Orgc']); return $data; } } diff --git a/app/View/AnalystData/add.ctp b/app/View/AnalystData/add.ctp index b471c9923..4ec514ca7 100644 --- a/app/View/AnalystData/add.ctp +++ b/app/View/AnalystData/add.ctp @@ -137,7 +137,7 @@ if (!$ajax) { function displayRelatedObject(data) { if (Object.keys(data).length == 0) { - $('#related-object-container').html('') + $('#related-object-container').html('') } else { var parsed = syntaxHighlightJson(data) $('#related-object-container').html(parsed) @@ -151,7 +151,6 @@ if (!$ajax) { url: url, headers: { Accept: "application/json" }, success: function (data) { - console.log(data); displayRelatedObject(data) }, error: function (data, textStatus, errorThrown) { diff --git a/app/View/Elements/Events/View/row_object.ctp b/app/View/Elements/Events/View/row_object.ctp index 37808c432..2ef558f0a 100644 --- a/app/View/Elements/Events/View/row_object.ctp +++ b/app/View/Elements/Events/View/row_object.ctp @@ -32,14 +32,34 @@ $objectId = intval($object['id']); - element('genericElements/Analyst_notes/notes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Attribute']); ?> + element('genericElements/Analyst_data/generic', [ + 'analyst_data' => ['notes' => $notes, 'opinions' => $opinions, 'relationships' => $relationships], + 'object_uuid' => $object['uuid'], + 'object_type' => 'Attribute' + ]); + ?> element('/Events/View/seen_field', array('object' => $object)); ?> >Time->date($object['timestamp']) . ($isNew ? '*' : '') ?> - element('/genericElements/shortUuidWithNotes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Object']); ?> + element('genericElements/shortUuidWithNotes', [ + 'uuid' => $object['uuid'], + 'object_type' => 'Attribute', + 'notes' => $notes, + 'opinions' => $opinions, + 'relationships' => $relationships, + ]); + ?> - element('genericElements/Analyst_notes/notes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Attribute']); ?> + element('genericElements/Analyst_data/generic', [ + 'analyst_data' => ['notes' => $notes, 'opinions' => $opinions, 'relationships' => $relationships], + 'object_uuid' => $object['uuid'], + 'object_type' => 'Attribute' + ]); + ?> element('/Events/View/seen_field', array('object' => $object)); ?> @@ -59,7 +68,18 @@ ?> - element('/genericElements/shortUuidWithNotes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Proposals']); ?> + element('genericElements/shortUuidWithNotes', [ + 'uuid' => $object['uuid'], + 'object_type' => 'Attribute', + 'notes' => $notes, + 'opinions' => $opinions, + 'relationships' => $relationships, + ]); + ?> [], ]; foreach ($relationships as $relationship) { - $related_objects[$relationship['related_object_type']][$relationship['related_object_uuid']] = $relationship['related_object'][$relationship['related_object_type']]; + if (!empty($relationship['related_object'][$relationship['related_object_type']])) { + $related_objects[$relationship['related_object_type']][$relationship['related_object_uuid']] = $relationship['related_object'][$relationship['related_object_type']]; + } } $notesOpinions = array_merge($notes, $opinions); @@ -349,49 +351,61 @@ function renderRelationshipEntryFromType(note, relationship_related_object) { {{=it.related_object_uuid}} \ \ ') - if (note.related_object_type == 'Event' && relationship_related_object.Event[note.related_object_uuid]) { - note.event = relationship_related_object.Event[note.related_object_uuid] - template = doT.template('\ + var templateEvent = doT.template('\ \ \ \ \ - {{=it.event.info}} \ + {{=it.content}} \ \ \ \ ') + if (note.related_object_type == 'Event' && relationship_related_object.Event[note.related_object_uuid]) { + note.event = relationship_related_object.Event[note.related_object_uuid] + template = doT.template(templateEvent({content: '{{=it.event.info}}', urlEvent: '{{=it.url}}'})) } else if (note.related_object_type == 'Attribute' && relationship_related_object.Attribute[note.related_object_uuid]) { + var event = templateEvent({content: '{{=it.attribute.Event.info}}', urlEvent: baseurl + '/events/view/{{=it.attribute.event_id}}'}) note.attribute = relationship_related_object.Attribute[note.related_object_uuid] if (note.attribute.object_relation !== undefined && note.attribute.object_relation !== null) { template = doT.template('\ + ' + event + ' \ + \ \ \ \ - {{=it.attribute.object_name}} \ + {{=it.attribute.Object.name}} \ ↦ {{=it.attribute.object_relation}} \ \ - {{=it.attribute.value}} \ + {{=it.attribute.value}} \ \ ') } else if (relationship_related_object.Attribute[note.related_object_uuid]) { + var event = templateEvent({content: '{{=it.attribute.Event.info}}', urlEvent: baseurl + '/events/view/{{=it.attribute.event_id}}'}) template = doT.template('\ + ' + event + ' \ + \ \ \ {{=it.attribute.type}} \ - {{=it.attribute.value}} \ + {{=it.attribute.value}} \ \ \ ') } } else if (note.related_object_type == 'Object') { + var event = templateEvent({content: '{{=it.object.Event.info}}', urlEvent: baseurl + '/events/view/{{=it.object.event_id}}'}) note.object = relationship_related_object.Object[note.related_object_uuid] template = doT.template('\ - \ + ' + event + ' \ + \ \ \ - {{=it.object.type}} \ - {{=it.object.value}} \ + \ + \ + {{=it.object.name}} \ + \ + {{=it.object.id}} \ \ \ ')