mirror of https://github.com/MISP/MISP
chg: [analyst-data:UI] Added support of relation for object + refactoring + fixes
parent
ccb784268a
commit
4f33648290
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ if (!$ajax) {
|
|||
|
||||
function displayRelatedObject(data) {
|
||||
if (Object.keys(data).length == 0) {
|
||||
$('#related-object-container').html('<span class="text-muted"><?= __('Could not fetch remote object') ?></span>')
|
||||
$('#related-object-container').html('<span class="text-muted"><?= __('Could not fetch remote object or fetching not supported yet.') ?></span>')
|
||||
} 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) {
|
||||
|
|
|
@ -32,14 +32,34 @@ $objectId = intval($object['id']);
|
|||
<td class="short context hidden"><?= $objectId ?></td>
|
||||
<td class="short context hidden uuid">
|
||||
<span class="quickSelect"><?php echo h($object['uuid']); ?></span>
|
||||
<?php echo $this->element('genericElements/Analyst_notes/notes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Attribute']); ?>
|
||||
<?php
|
||||
$notes = !empty($object['Note']) ? $object['Note'] : [];
|
||||
$opinions = !empty($object['Opinion']) ? $object['Opinion'] : [];
|
||||
$relationships = !empty($object['Relationship']) ? $object['Relationship'] : [];
|
||||
echo $this->element('genericElements/Analyst_data/generic', [
|
||||
'analyst_data' => ['notes' => $notes, 'opinions' => $opinions, 'relationships' => $relationships],
|
||||
'object_uuid' => $object['uuid'],
|
||||
'object_type' => 'Attribute'
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
<td class="short context hidden">
|
||||
<?php echo $this->element('/Events/View/seen_field', array('object' => $object)); ?>
|
||||
</td>
|
||||
<td class="short timestamp <?= $isNew ? 'bold red' : '' ?>" <?= $isNew ? 'title="' . __('Element or modification to an existing element has not been published yet.') . '"' : '' ?>><?= $this->Time->date($object['timestamp']) . ($isNew ? '*' : '') ?></td>
|
||||
<td class="short context">
|
||||
<?php echo $this->element('/genericElements/shortUuidWithNotes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Object']); ?>
|
||||
<?php
|
||||
$notes = !empty($object['Note']) ? $object['Note'] : [];
|
||||
$opinions = !empty($object['Opinion']) ? $object['Opinion'] : [];
|
||||
$relationships = !empty($object['Relationship']) ? $object['Relationship'] : [];
|
||||
echo $this->element('genericElements/shortUuidWithNotes', [
|
||||
'uuid' => $object['uuid'],
|
||||
'object_type' => 'Attribute',
|
||||
'notes' => $notes,
|
||||
'opinions' => $opinions,
|
||||
'relationships' => $relationships,
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
<?php
|
||||
if ($extended):
|
||||
|
|
|
@ -47,7 +47,16 @@
|
|||
</td>
|
||||
<td class="short context hidden uuid">
|
||||
<span class="quickSelect"><?php echo h($object['uuid']); ?></span>
|
||||
<?php echo $this->element('genericElements/Analyst_notes/notes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Attribute']); ?>
|
||||
<?php
|
||||
$notes = !empty($object['Note']) ? $object['Note'] : [];
|
||||
$opinions = !empty($object['Opinion']) ? $object['Opinion'] : [];
|
||||
$relationships = !empty($object['Relationship']) ? $object['Relationship'] : [];
|
||||
echo $this->element('genericElements/Analyst_data/generic', [
|
||||
'analyst_data' => ['notes' => $notes, 'opinions' => $opinions, 'relationships' => $relationships],
|
||||
'object_uuid' => $object['uuid'],
|
||||
'object_type' => 'Attribute'
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
<td class="short context hidden">
|
||||
<?php echo $this->element('/Events/View/seen_field', array('object' => $object)); ?>
|
||||
|
@ -59,7 +68,18 @@
|
|||
?>
|
||||
</td>
|
||||
<td class="short context">
|
||||
<?php echo $this->element('/genericElements/shortUuidWithNotes', ['uuid' => $object['uuid'], 'notes' => !empty($object['notes']) ? $object['notes'] : [], 'object_type' => 'Proposals']); ?>
|
||||
<?php
|
||||
$notes = !empty($object['Note']) ? $object['Note'] : [];
|
||||
$opinions = !empty($object['Opinion']) ? $object['Opinion'] : [];
|
||||
$relationships = !empty($object['Relationship']) ? $object['Relationship'] : [];
|
||||
echo $this->element('genericElements/shortUuidWithNotes', [
|
||||
'uuid' => $object['uuid'],
|
||||
'object_type' => 'Attribute',
|
||||
'notes' => $notes,
|
||||
'opinions' => $opinions,
|
||||
'relationships' => $relationships,
|
||||
]);
|
||||
?>
|
||||
</td>
|
||||
<?php
|
||||
if ($extended):
|
||||
|
|
|
@ -251,7 +251,9 @@ $related_objects = [
|
|||
'SharingGroup' => [],
|
||||
];
|
||||
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) {
|
|||
<span class="ellipsis-overflow" style="max-width: 12em;">{{=it.related_object_uuid}}</span> \
|
||||
</span> \
|
||||
')
|
||||
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('\
|
||||
<span class="misp-element-wrapper attribute" title="<?= __('Event') ?>"> \
|
||||
<span class="bold"> \
|
||||
<span class="attr-type"><span><i class="<?= $this->FontAwesome->getClass('envelope') ?>"></i></span></span> \
|
||||
<span class=""><span class="attr-value"> \
|
||||
<span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.url}}">{{=it.event.info}}</a></span> \
|
||||
<span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.urlEvent}}" target="_blank">{{=it.content}}</a></span> \
|
||||
</span></span> \
|
||||
</span> \
|
||||
</span> \
|
||||
')
|
||||
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 + ' \
|
||||
<b>↦</b> \
|
||||
<span class="misp-element-wrapper object"> \
|
||||
<span class="bold"> \
|
||||
<span class="obj-type"> \
|
||||
<span class="object-name" title="<?= __('Object') ?>">{{=it.attribute.object_name}}</span> \
|
||||
<span class="object-name" title="<?= __('Object') ?>">{{=it.attribute.Object.name}}</span> \
|
||||
↦ <span class="object-attribute-type" title="<?= __('Object Relation') ?>">{{=it.attribute.object_relation}}</span> \
|
||||
</span> \
|
||||
<span class="obj-value"><span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.url}}">{{=it.attribute.value}}</a></span></span> \
|
||||
<span class="obj-value"><span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.url}}" target="_blank">{{=it.attribute.value}}</a></span></span> \
|
||||
</span> \
|
||||
')
|
||||
} 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 + ' \
|
||||
<b>↦</b> \
|
||||
<span class="misp-element-wrapper attribute"> \
|
||||
<span class="bold"> \
|
||||
<span class="attr-type"><span title="<?= __('Attribute') ?>">{{=it.attribute.type}}</span></span> \
|
||||
<span class="blue"><span class="attr-value"><span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.url}}">{{=it.attribute.value}}</a></span></span></span> \
|
||||
<span class="blue"><span class="attr-value"><span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.url}}" target="_blank">{{=it.attribute.value}}</a></span></span></span> \
|
||||
</span> \
|
||||
</span> \
|
||||
')
|
||||
}
|
||||
} 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('\
|
||||
<i class="<?= $this->FontAwesome->getClass('cubes') ?>" title="<?= __('Object') ?>"></i> \
|
||||
' + event + ' \
|
||||
<b>↦</b> \
|
||||
<span class="misp-element-wrapper object"> \
|
||||
<span class="bold"> \
|
||||
<span class="obj-type"><span>{{=it.object.type}}</span></span> \
|
||||
<span class="blue"><span class="obj-value"><span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.url}}">{{=it.object.value}}</a></span></span></span> \
|
||||
<span class="obj-type"> \
|
||||
<i class="<?= $this->FontAwesome->getClass('cubes') ?>" title="<?= __('Object') ?>" style="margin: 0 0 0 0.25rem;"></i> \
|
||||
<span>{{=it.object.name}}</span> \
|
||||
</span> \
|
||||
<span class="blue"><span class="obj-value"><span class="ellipsis-overflow" style="max-width: 12em;"><a href="{{=it.url}}" target="_blank">{{=it.object.id}}</a></span></span></span> \
|
||||
</span> \
|
||||
</span> \
|
||||
')
|
||||
|
|
Loading…
Reference in New Issue