mirror of https://github.com/MISP/MISP
Enhancements to the reportValidationIssuesAttributes action
- now also shows issues not related to the value field - takes an optional parameter to validate a single event's attributespull/639/head
parent
9f8e5049a6
commit
43c2290097
|
@ -1 +1 @@
|
|||
{"major":2, "minor":3, "hotfix":122}
|
||||
{"major":2, "minor":3, "hotfix":123}
|
|
@ -1830,11 +1830,11 @@ class AttributesController extends AppController {
|
|||
$this->set('rpzSettings', $rpzSettings);
|
||||
}
|
||||
|
||||
public function reportValidationIssuesAttributes() {
|
||||
public function reportValidationIssuesAttributes($eventId = false) {
|
||||
// TODO improve performance of this function by eliminating the additional SQL query per attribute
|
||||
// search for validation problems in the attributes
|
||||
if (!self::_isSiteAdmin()) throw new NotFoundException();
|
||||
$this->set('result', $this->Attribute->reportValidationIssuesAttributes());
|
||||
$this->set('result', $this->Attribute->reportValidationIssuesAttributes($eventId));
|
||||
}
|
||||
|
||||
public function generateCorrelation() {
|
||||
|
|
|
@ -1412,12 +1412,14 @@ class Attribute extends AppModel {
|
|||
return $k;
|
||||
}
|
||||
|
||||
public function reportValidationIssuesAttributes() {
|
||||
public function reportValidationIssuesAttributes($eventId) {
|
||||
$conditions = array();
|
||||
if ($eventId && is_numeric($eventId)) $conditions = array('event_id' => $eventId);
|
||||
// for efficiency reasons remove the unique requirement
|
||||
$this->validator()->remove('value', 'unique');
|
||||
|
||||
// get all attributes..
|
||||
$attributes = $this->find('all', array('recursive' => -1, 'fields' => array('id')));
|
||||
$attributes = $this->find('all', array('recursive' => -1, 'fields' => array('id'), 'conditions' => $conditions));
|
||||
|
||||
// for all attributes..
|
||||
$result = array();
|
||||
|
@ -1431,7 +1433,10 @@ class Attribute extends AppModel {
|
|||
$errors = $this->validationErrors;
|
||||
$result[$i]['id'] = $attribute['Attribute']['id'];
|
||||
// print_r
|
||||
$result[$i]['error'] = $errors['value'][0];
|
||||
$result[$i]['error'] = array();
|
||||
foreach ($errors as $field => $error) {
|
||||
$result[$i]['error'][$field] = array('value' => $attribute['Attribute'][$field], 'error' => $error[0]);
|
||||
}
|
||||
$result[$i]['details'] = 'Event ID: [' . $attribute['Attribute']['event_id'] . "] - Category: [" . $attribute['Attribute']['category'] . "] - Type: [" . $attribute['Attribute']['type'] . "] - Value: [" . $attribute['Attribute']['value'] . ']';
|
||||
$i++;
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
foreach ($result as $r) {
|
||||
?>
|
||||
<h3>Validation errors for attribute: <?php echo h($r['id']); ?></h3>
|
||||
<?php print_r($r['error']); ?><br />
|
||||
Attribute details:<br />
|
||||
<?php echo h($r['details']); ?>
|
||||
<br/>
|
||||
<?php
|
||||
foreach ($r['error'] as $field => $error) {
|
||||
echo '<b>[' . h($field) . ']</b>: Value found: ' . h($error['value']) . ' - Error: ' . h($error['error']) . '<br />';
|
||||
}
|
||||
?>
|
||||
<b>[Attribute details]</b>: <?php echo h($r['details']); ?><br/>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue