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:
commit
b4309adb23
1 changed files with 23 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue