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:
parent
36b07475dc
commit
bb8285cb4d
1 changed files with 12 additions and 11 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue