mirror of https://github.com/MISP/MISP
chg: [attribute:type] Datetime value is forced to be a valid ISO format
- It is converted into UTC in the server - /attribute/add Form includes javascript validation partpull/5564/head
parent
eb9b60032e
commit
b03d86221b
|
@ -1594,6 +1594,13 @@ class Attribute extends AppModel
|
||||||
}
|
}
|
||||||
$value = ($value) ? '1' : '0';
|
$value = ($value) ? '1' : '0';
|
||||||
break;
|
break;
|
||||||
|
case 'datetime':
|
||||||
|
try {
|
||||||
|
$value = (new DateTime($value))->setTimezone(new DateTimeZone('GMT'))->format('Y-m-d\TH:i:s.uO'); // ISO8601 formating with microseconds
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// silently skip. Rejection will be done in runValidation()
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,31 @@
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
checkSharingGroup('Attribute');
|
checkSharingGroup('Attribute');
|
||||||
|
|
||||||
|
var $form = $('#AttributeType').closest('form').submit(function( event ) {
|
||||||
|
if ($('#AttributeType').val() === 'datetime') {
|
||||||
|
// add timezone of the browser if not set
|
||||||
|
var allowLocalTZ = true;
|
||||||
|
var $valueInput = $('#AttributeValue')
|
||||||
|
var dateValue = moment($valueInput.val())
|
||||||
|
if (dateValue.isValid()) {
|
||||||
|
if (dateValue.creationData().format !== "YYYY-MM-DDTHH:mm:ssZ" && dateValue.creationData().format !== "YYYY-MM-DDTHH:mm:ss.SSSSZ") {
|
||||||
|
// Missing timezone data
|
||||||
|
var confirm_message = '<?php echo __('As no timezone has been entered, it has been auto-detected as: ') ?>' + dateValue.format('Z')
|
||||||
|
confirm_message += '<?php echo '\r\n' . __('This value will be submited instead: '); ?>' + dateValue.toISOString(allowLocalTZ)
|
||||||
|
if (confirm(confirm_message)) {
|
||||||
|
$valueInput.val(dateValue.toISOString(allowLocalTZ));
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
textStatus = '<?php echo __('Value is not a valid datetime. Excpected format YYYY-MM-DDTHH:mm:ssZ') ?>'
|
||||||
|
showMessage('fail', + ": " + '???');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php echo $this->element('form_seen_input'); ?>
|
<?php echo $this->element('form_seen_input'); ?>
|
||||||
|
|
Loading…
Reference in New Issue