Fix recruitment API candidature creation validation (#37331)

Signed-off-by: Ahmed Galadima <ahmed.galadima@hotmail.com>
Co-authored-by: Ahmed Galadima <ahmed.galadima@hotmail.com>
This commit is contained in:
Ahmed Galadima 2026-02-24 17:32:46 +01:00 committed by GitHub
parent 36b07475dc
commit bb8285cb4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -375,7 +375,7 @@ class Recruitments extends DolibarrApi
}
// Check mandatory fields
$result = $this->_validate($request_data);
$result = $this->_validate($request_data, $this->jobposition);
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
@ -415,16 +415,16 @@ class Recruitments extends DolibarrApi
}
// Check mandatory fields
$result = $this->_validate($request_data);
$result = $this->_validate($request_data, $this->candidature);
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$this->jobposition->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
$this->candidature->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition);
$this->candidature->$field = $this->_checkValForAPI($field, $value, $this->candidature);
}
// Clean data
@ -686,25 +686,26 @@ class Recruitments extends DolibarrApi
* Validate fields before create or update object
*
* @param ?array<string,mixed> $data Array of data to validate
* @param CommonObject $object Object to validate against
* @return array<string,mixed>
*
* @throws RestException
*/
private function _validate($data)
private function _validate($data, $object)
{
if ($data === null) {
$data = array();
}
$jobposition = array();
foreach ($this->jobposition->fields as $field => $propfield) {
if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || empty($propfield['notnull']) || $propfield['notnull'] != 1) {
continue; // Not a mandatory field
$result = array();
foreach ($object->fields as $field => $propfield) {
if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'ref')) || empty($propfield['notnull']) || $propfield['notnull'] != 1 || !empty($propfield['noteditable']) || isset($propfield['default'])) {
continue; // Not a mandatory field or auto-generated field or has default value
}
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
}
$jobposition[$field] = $data[$field];
$result[$field] = $data[$field];
}
return $jobposition;
return $result;
}
}