FIX 17.0 API endpoints "PUT": prevent overwriting all extrafields if only some are supplied in the request cf. PR #29237

+ security for Tickets API: disable updating rowid
This commit is contained in:
atm-florian 2025-01-16 10:37:29 +01:00
parent c2c3879032
commit ba4e97f07b
29 changed files with 177 additions and 0 deletions

View File

@ -348,6 +348,12 @@ class Members extends DolibarrApi
}
}
} else {
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$member->array_options[$index] = $this->_checkValForAPI($field, $val, $member);
}
continue;
}
$member->$field = $value;
}
}

View File

@ -193,6 +193,12 @@ class MembersTypes extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$membertype->array_options[$index] = $this->_checkValForAPI($field, $val, $membertype);
}
continue;
}
// Process the status separately because it must be updated using
// the validate(), resiliate() and exclude() methods of the class AdherentType.
$membertype->$field = $value;

View File

@ -186,6 +186,12 @@ class Subscriptions extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$subscription->array_options[$index] = $this->_checkValForAPI($field, $val, $subscription);
}
continue;
}
$subscription->$field = $value;
}

View File

@ -237,6 +237,12 @@ class Boms extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->bom->array_options[$index] = $this->_checkValForAPI($field, $val, $this->bom);
}
continue;
}
$this->bom->$field = $value;
}

View File

@ -237,6 +237,12 @@ class Categories extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->category->array_options[$index] = $this->_checkValForAPI($field, $val, $this->category);
}
continue;
}
$this->category->$field = $value;
}

View File

@ -270,6 +270,12 @@ class AgendaEvents extends DolibarrApi
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->actioncomm->array_options[$index] = $this->_checkValForAPI($field, $val, $this->actioncomm);
}
continue;
}
$this->actioncomm->$field = $this->_checkValForAPI($field, $value, $this->actioncomm);
}

View File

@ -696,6 +696,12 @@ class Proposals extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->propal->array_options[$index] = $this->_checkValForAPI($field, $val, $this->propal);
}
continue;
}
$this->propal->$field = $value;
}

View File

@ -652,6 +652,12 @@ class Orders extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->commande->array_options[$index] = $this->_checkValForAPI($field, $val, $this->commande);
}
continue;
}
$this->commande->$field = $value;
}

View File

@ -332,6 +332,12 @@ class BankAccounts extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$account->array_options[$index] = $this->_checkValForAPI($field, $val, $account);
}
continue;
}
$account->$field = $this->_checkValForAPI($field, $value, $account);
}

View File

@ -627,6 +627,12 @@ class Invoices extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->invoice->array_options[$index] = $this->_checkValForAPI($field, $val, $this->invoice);
}
continue;
}
$this->invoice->$field = $value;
}

View File

@ -510,6 +510,12 @@ class Contracts extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->contract->array_options[$index] = $this->_checkValForAPI($field, $val, $this->contract);
}
continue;
}
$this->contract->$field = $value;
}

View File

@ -231,6 +231,12 @@ class Donations extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->don->array_options[$index] = $this->_checkValForAPI($field, $val, $this->don);
}
continue;
}
$this->don->$field = $value;
}

View File

@ -447,6 +447,12 @@ class Shipments extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->shipment->array_options[$index] = $this->_checkValForAPI($field, $val, $this->shipment);
}
continue;
}
$this->shipment->$field = $value;
}

View File

@ -420,6 +420,12 @@ class ExpenseReports extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->expensereport->array_options[$index] = $this->_checkValForAPI($field, $val, $this->expensereport);
}
continue;
}
$this->expensereport->$field = $value;
}

View File

@ -263,6 +263,12 @@ class SupplierInvoices extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->invoice->array_options[$index] = $this->_checkValForAPI($field, $val, $this->invoice);
}
continue;
}
$this->invoice->$field = $value;
}

View File

@ -277,6 +277,12 @@ class SupplierOrders extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->order->array_options[$index] = $this->_checkValForAPI($field, $val, $this->order);
}
continue;
}
$this->order->$field = $value;
}

View File

@ -298,6 +298,12 @@ class KnowledgeManagement extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->knowledgerecord->array_options[$index] = $this->_checkValForAPI($field, $val, $this->knowledgerecord);
}
continue;
}
$this->knowledgerecord->$field = $this->_checkValForAPI($field, $value, $this->knowledgerecord);
}

View File

@ -255,6 +255,12 @@ class MyModuleApi extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->myobject->array_options[$index] = $this->_checkValForAPI($field, $val, $this->myobject);
}
continue;
}
$this->myobject->$field = $this->_checkValForAPI($field, $value, $this->myobject);
}

View File

@ -238,6 +238,12 @@ class Mos extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->mo->array_options[$index] = $this->_checkValForAPI($field, $val, $this->mo);
}
continue;
}
$this->mo->$field = $value;
}

View File

@ -255,6 +255,12 @@ class PartnershipApi extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->partnership->array_options[$index] = $this->_checkValForAPI($field, $val, $this->partnership);
}
continue;
}
$this->partnership->$field = $this->_checkValForAPI($field, $value, $this->partnership);
}

View File

@ -361,6 +361,12 @@ class Products extends DolibarrApi
if ($field == 'stock_reel') {
throw new RestException(400, 'Stock reel cannot be updated here. Use the /stockmovements endpoint instead');
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->product->array_options[$index] = $this->_checkValForAPI($field, $val, $this->product);
}
continue;
}
$this->product->$field = $value;
}

View File

@ -206,6 +206,12 @@ class Warehouses extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->warehouse->array_options[$index] = $this->_checkValForAPI($field, $val, $this->warehouse);
}
continue;
}
$this->warehouse->$field = $value;
}

View File

@ -462,6 +462,12 @@ class Projects extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->project->array_options[$index] = $this->_checkValForAPI($field, $val, $this->project);
}
continue;
}
$this->project->$field = $value;
}

View File

@ -460,6 +460,12 @@ class Tasks extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->task->array_options[$index] = $this->_checkValForAPI($field, $val, $this->task);
}
continue;
}
$this->task->$field = $value;
}

View File

@ -447,6 +447,12 @@ class Receptions extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->reception->array_options[$index] = $this->_checkValForAPI($field, $val, $this->reception);
}
continue;
}
$this->reception->$field = $value;
}

View File

@ -330,6 +330,12 @@ class Contacts extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->contact->array_options[$index] = $this->_checkValForAPI($field, $val, $this->contact);
}
continue;
}
$this->contact->$field = $value;
}

View File

@ -301,6 +301,12 @@ class Thirdparties extends DolibarrApi
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->company->array_options[$index] = $this->_checkValForAPI($field, $val, $this->company);
}
continue;
}
$this->company->$field = $value;
}

View File

@ -381,6 +381,15 @@ class Tickets extends DolibarrApi
}
foreach ($request_data as $field => $value) {
if ($field == 'id') {
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->ticket->array_options[$index] = $this->_checkValForAPI($field, $val, $this->ticket);
}
continue;
}
$this->ticket->$field = $value;
}

View File

@ -406,6 +406,12 @@ class Users extends DolibarrApi
throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error);
}
} else {
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->useraccount->array_options[$index] = $this->_checkValForAPI($field, $val, $this->useraccount);
}
continue;
}
$this->useraccount->$field = $value;
}
}