FIX: Fix supplier invoice security check

This commit is contained in:
Aloïs Micard 2024-01-18 14:55:45 +01:00
parent 13b9a65a9e
commit bc14550ded

View file

@ -380,15 +380,15 @@ class SupplierInvoices extends DolibarrApi
throw new RestException(400, 'Invoice ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->invoice->fetch($id);
if (!$result) {
throw new RestException(404, 'Invoice not found');
}
if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->invoice->getListOfPayments();
if ($result < 0) {
throw new RestException(405, $this->invoice->error);
@ -429,6 +429,11 @@ class SupplierInvoices extends DolibarrApi
throw new RestException(400, 'Invoice ID is mandatory');
}
$result = $this->invoice->fetch($id);
if (!$result) {
throw new RestException(404, 'Invoice not found');
}
if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
@ -443,12 +448,6 @@ class SupplierInvoices extends DolibarrApi
throw new RestException(400, 'Payment mode ID is mandatory');
}
$result = $this->invoice->fetch($id);
if (!$result) {
throw new RestException(404, 'Invoice not found');
}
// Calculate amount to pay
$totalpaid = $this->invoice->getSommePaiement();
$totaldeposits = $this->invoice->getSumDepositsUsed();