mirror of https://github.com/MISP/MISP
chg: [object:fromAttributes] Better Attribute filtering - WiP
parent
5798a73462
commit
ca01897857
|
@ -993,10 +993,10 @@ class ObjectsController extends AppController
|
|||
$this->set('unmapped', $unmappedAttributes);
|
||||
}
|
||||
|
||||
function proposeObjectsFromAttributes($event_id, $selected='[]')
|
||||
function proposeObjectsFromAttributes($event_id, $selected_attributes='[]')
|
||||
{
|
||||
$selected = json_decode($selected, true);
|
||||
$potential_templates = $this->MispObject->validObjectsFromAttributeTypes($this->Auth->user(), $event_id, $selected);
|
||||
$selected_attributes = json_decode($selected_attributes, true);
|
||||
$potential_templates = $this->MispObject->validObjectsFromAttributeTypes($this->Auth->user(), $event_id, $selected_attributes);
|
||||
usort($potential_templates, function($a, $b) {
|
||||
if ($a['ObjectTemplate']['id'] == $b['ObjectTemplate']['id']) {
|
||||
return 0;
|
||||
|
@ -1034,16 +1034,31 @@ class ObjectsController extends AppController
|
|||
throw new NotFoundException(__('Invalid template.'));
|
||||
}
|
||||
} else {
|
||||
// TODO: validate
|
||||
$selected_attribute_ids = json_decode($selected_attribute_ids, true);
|
||||
$selected_attributes = $this->MispObject->Attribute->fetchAttributes($this->Auth->user(), array('conditions' => array(
|
||||
'Attribute.id' => $selected_attribute_ids,
|
||||
'Attribute.event_id' => $event_id,
|
||||
'Attribute.object_id' => 0
|
||||
)));
|
||||
if (empty($selected_attributes)) {
|
||||
throw new MethodNotAllowedException(__('No Attribute selected.'));
|
||||
}
|
||||
$template = $this->MispObject->ObjectTemplate->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('ObjectTemplate.id' => $selected_template, 'ObjectTemplate.active' => true),
|
||||
'contain' => array('ObjectTemplateElement' => array('fields' => array('ObjectTemplateElement.object_relation', 'ObjectTemplateElement.type')))
|
||||
'contain' => 'ObjectTemplateElement'
|
||||
));
|
||||
if (empty($template)) {
|
||||
throw new NotFoundException(__('Invalid template.'));
|
||||
}
|
||||
$conformity_result = $this->MispObject->ObjectTemplate->checkTemplateConformityBasedOnTypes($template, $selected_attributes);
|
||||
$skipped_attributes = 0;
|
||||
foreach ($selected_attributes as $i => $attribute) {
|
||||
if (in_array($attribute['Attribute']['type'], $conformity_result['invalidTypes'])) {
|
||||
unset($selected_attributes[$i]);
|
||||
$skipped_attributes++;
|
||||
}
|
||||
}
|
||||
$object_relations = array();
|
||||
foreach ($template['ObjectTemplateElement'] as $template_element) {
|
||||
$object_relations[$template_element['type']][] = $template_element['object_relation'];
|
||||
|
@ -1053,11 +1068,10 @@ class ObjectsController extends AppController
|
|||
$this->set('distributionLevels', $this->MispObject->Attribute->distributionLevels);
|
||||
$this->set('selectedTemplateTd', $selected_template);
|
||||
$this->set('selectedAttributeIds', $selected_attribute_ids);
|
||||
$selected_attributes = $this->MispObject->Attribute->fetchAttributes($this->Auth->user(), array('conditions' => array('Attribute.id' => $selected_attribute_ids)));
|
||||
$this->set('template', $template);
|
||||
$this->set('object_relations', $object_relations);
|
||||
$this->set('attributes', $selected_attributes);
|
||||
|
||||
$this->set('skipped_attributes', $skipped_attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -726,12 +726,12 @@ class MispObject extends AppModel
|
|||
return count($orphans);
|
||||
}
|
||||
|
||||
public function validObjectsFromAttributeTypes($user, $event_id, $selected)
|
||||
public function validObjectsFromAttributeTypes($user, $event_id, $selected_attribute_ids)
|
||||
{
|
||||
$attributes = $this->Attribute->fetchAttributesSimple($user,
|
||||
array(
|
||||
'conditions' => array(
|
||||
'id' => $selected,
|
||||
'id' => $selected_attribute_ids,
|
||||
'event_id' => $event_id,
|
||||
'object_id' => 0
|
||||
),
|
||||
|
|
|
@ -79,8 +79,15 @@ echo $this->Form->create('Object');
|
|||
</table>
|
||||
</div>
|
||||
|
||||
<?php if ($skipped_attributes > 0): ?>
|
||||
<div class="alert" style="margin-top: 15px;">
|
||||
<strong><?php echo __('Skipped'); ?></strong> <?php echo h($skipped_attributes) . __(' Attribute(s)') ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<div style="margin-top: 15px; text-align: center;">
|
||||
<button class="btn btn-primary">Merge Selected Attribute into an Object</button>
|
||||
<button class="btn btn-primary"><?php echo __('Merge above Attributes into an Object'); ?></button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</td>
|
||||
<?php if ($potential_template['ObjectTemplate']['compatibility'] === true): ?>
|
||||
<td>
|
||||
<i class="fa fa-check"></i>
|
||||
<i class="fa fa-check" style="font-size: medium;" title="<?php echo __('This Object is compatible for the merge'); ?>"></i>
|
||||
<?php if (!empty($potential_template['ObjectTemplate']['invalidTypes'])): ?>
|
||||
<?php foreach ($potential_template['ObjectTemplate']['invalidTypes'] as $type): ?>
|
||||
<span class="label label-warning" title="<?php echo __('This Attribute type cannot be part of this Object template. If you merge the selected Attributes into this object, all Attribute having this type will be ignored.'); ?>"><?php echo h($type); ?></span>
|
||||
|
|
Loading…
Reference in New Issue