Merge pull request #36534 from JonBendtsen/BUG__API_POST_contact_to_a_non-existing_socid_gives_DB_error__36407

FIX #36407 BUG: API POST contact to a non-existing socid gives DB error
This commit is contained in:
Laurent Destailleur 2025-12-04 18:09:59 +01:00 committed by GitHub
commit b4309adb23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,6 +22,7 @@ use Luracast\Restler\RestException;
//require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
//require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
/**
@ -365,6 +366,17 @@ class Contacts extends DolibarrApi
}
continue;
}
if ($field == 'socid') {
$new_socid = (int) $value;
$loopthirdpartytmp = new Societe($this->db);
$new_thirdparty_result = $loopthirdpartytmp->fetch($new_socid);
if ($new_thirdparty_result < 1) {
throw new RestException(404, 'Thirdparty with id='.$new_socid.' not found or not allowed');
}
if (!DolibarrApi::_checkAccessToResource('societe', $new_socid)) {
throw new RestException(403, 'Access to socid/thirdparty='.$new_socid.' is not allowed for login '.DolibarrApiAccess::$user->login);
}
}
$this->contact->$field = $this->_checkValForAPI($field, $value, $this->contact);
}
@ -422,6 +434,17 @@ class Contacts extends DolibarrApi
}
continue;
}
if ($field == 'socid') {
$new_socid = (int) $value;
$loopthirdpartytmp = new Societe($this->db);
$new_thirdparty_result = $loopthirdpartytmp->fetch($new_socid);
if ($new_thirdparty_result < 1) {
throw new RestException(404, 'Thirdparty with id='.$new_socid.' not found or not allowed');
}
if (!DolibarrApi::_checkAccessToResource('societe', $new_socid)) {
throw new RestException(403, 'Access to socid/thirdparty='.$new_socid.' is not allowed for login '.DolibarrApiAccess::$user->login);
}
}
$this->contact->$field = $this->_checkValForAPI($field, $value, $this->contact);
}