Unverified Commit 08c77444 authored by Jerome Boucher's avatar Jerome Boucher
Browse files

add validation for external referentiel

parent a4914e44
Pipeline #10116 failed with stages
in 52 seconds
......@@ -92,10 +92,8 @@ trait archiveValidationTrait
$archivalProfileFields[$archiveDescription->fieldName] = $archiveDescription;
}
foreach ($object as $name => $value) {
if (!isset($archivalProfileFields[$name]) && !$archivalProfile->acceptUserIndex) {
throw new \core\Exception\BadRequestException('Metadata %1$s is not allowed', 400, null, [$name]);
}
......@@ -150,6 +148,10 @@ trait archiveValidationTrait
if (!empty($descriptionField->enumeration) && !in_array($value, $descriptionField->enumeration) && $value != '') {
throw new \core\Exception\BadRequestException('Forbidden value for metadata %1$s', 400, null, [$descriptionField->name]);
}
if (!empty($descriptionField->ref) && $descriptionField->ref) {
$this->validateRef($descriptionField->name, $value);
}
}
protected function validateText($value, $descriptionField)
......@@ -228,7 +230,6 @@ trait archiveValidationTrait
} else {
$descriptionField = $descriptionField->itemType;
}
foreach ($array as $name => $value) {
$this->validateDescriptionField($value, $descriptionField);
}
......@@ -429,4 +430,29 @@ trait archiveValidationTrait
}
unlink($filename);
}
protected function validateRef($referentielName, $value)
{
$isValid = false;
$conf = \laabs::Configuration()['recordsManagement'];
if (isset($conf['refDirectory']) || is_dir($conf['refDirectory'])) {
$refDirectory = $conf['refDirectory'];
if (is_file($conf['refDirectory'].'/'.$referentielName.'.csv')) {
$handler = fopen($conf['refDirectory'].'/'.$referentielName.'.csv', 'r');
while ($line = fgetcsv($handler)) {
if ($line[0] == $value) {
$isValid = true;
break;
}
}
fclose($handler);
}
}
if (!$isValid) {
throw new \core\Exception\BadRequestException("Invalid value %s supplied for referentiel %s", 404, null, [$value, $referentielName]);
}
return true;
}
}
......@@ -446,6 +446,9 @@ msgstr "L'identifiant d'archive %s n'existe pas."
msgid "Invalid format attachments for %s"
msgstr "Format invalide pour '%s'"
msgid "Invalid value %s supplied for referentiel %s"
msgstr "Valeur %s non valide pour référentiel %s"
msgid "The archive %1$s is not from the folder %2$s."
msgstr "L'archive %1$s n'est pas dans le dossier %2$s."
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment