mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-11 12:01:23 +01:00
Debug api of module BOM
This commit is contained in:
@@ -234,12 +234,13 @@ if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' &&
|
|||||||
|
|
||||||
$classname = ucwords($module);
|
$classname = ucwords($module);
|
||||||
|
|
||||||
dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname);
|
dol_syslog('Search api file /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname);
|
||||||
|
|
||||||
$res = false;
|
$res = false;
|
||||||
if ($dir_part_file)
|
if ($dir_part_file)
|
||||||
$res = include_once $dir_part_file;
|
$res = include_once $dir_part_file;
|
||||||
if (! $res) {
|
if (! $res) {
|
||||||
|
dol_syslog('Failed to make include_once '.$dir_part_file, LOG_WARNING);
|
||||||
print 'API not found (failed to include API file)';
|
print 'API not found (failed to include API file)';
|
||||||
header('HTTP/1.1 501 API not found (failed to include API file)');
|
header('HTTP/1.1 501 API not found (failed to include API file)');
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
@@ -28,21 +28,13 @@ require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API class for bom bom
|
* API class for bom
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @class DolibarrApiAccess {@requires user,external}
|
* @class DolibarrApiAccess {@requires user,external}
|
||||||
*/
|
*/
|
||||||
class BOMs extends DolibarrApi
|
class Boms extends DolibarrApi
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
|
||||||
*/
|
|
||||||
static $FIELDS = array(
|
|
||||||
'label'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var BOM $bom {@type BOM}
|
* @var BOM $bom {@type BOM}
|
||||||
*/
|
*/
|
||||||
@@ -71,16 +63,16 @@ class BOMs extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
public function get($id)
|
public function get($id)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->bom->read) {
|
if (! DolibarrApiAccess::$user->rights->bom->read) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->bom->fetch($id);
|
$result = $this->bom->fetch($id);
|
||||||
if( ! $result ) {
|
if (! $result) {
|
||||||
throw new RestException(404, 'BOM not found');
|
throw new RestException(404, 'BOM not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('bom', $this->bom->id)) {
|
if (! DolibarrApi::_checkAccessToResource('bom', $this->bom->id, 'bom_bom')) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,33 +99,33 @@ class BOMs extends DolibarrApi
|
|||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
$tmpobject = new BOM($db);
|
||||||
|
|
||||||
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
|
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
|
||||||
|
|
||||||
$restictonsocid = 0; // Set to 1 if there is a field socid in table of object
|
$restrictonsocid = 0; // Set to 1 if there is a field socid in table of object
|
||||||
|
|
||||||
// If the internal user must only see his customers, force searching by him
|
// If the internal user must only see his customers, force searching by him
|
||||||
$search_sale = 0;
|
$search_sale = 0;
|
||||||
if ($restictonsocid && ! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
|
if ($restrictonsocid && ! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
|
||||||
|
|
||||||
$sql = "SELECT t.rowid";
|
$sql = "SELECT t.rowid";
|
||||||
if ($restictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
|
if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."bom_mytable as t";
|
$sql.= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." as t";
|
||||||
|
|
||||||
if ($restictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
|
if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
|
||||||
$sql.= " WHERE 1 = 1";
|
$sql.= " WHERE 1 = 1";
|
||||||
|
|
||||||
// Example of use $mode
|
// Example of use $mode
|
||||||
//if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
|
//if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
|
||||||
//if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
|
//if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
|
||||||
|
|
||||||
$tmpobject = new BOM($db);
|
|
||||||
if ($tmpobject->ismultientitymanaged) $sql.= ' AND t.entity IN ('.getEntity('bom').')';
|
if ($tmpobject->ismultientitymanaged) $sql.= ' AND t.entity IN ('.getEntity('bom').')';
|
||||||
if ($restictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
|
if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
|
||||||
if ($restictonsocid && $socid) $sql.= " AND t.fk_soc = ".$socid;
|
if ($restrictonsocid && $socid) $sql.= " AND t.fk_soc = ".$socid;
|
||||||
if ($restictonsocid && $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
if ($restrictonsocid && $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
||||||
// Insert sale filter
|
// Insert sale filter
|
||||||
if ($restictonsocid && $search_sale > 0)
|
if ($restrictonsocid && $search_sale > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND sc.fk_user = ".$search_sale;
|
$sql .= " AND sc.fk_user = ".$search_sale;
|
||||||
}
|
}
|
||||||
@@ -190,7 +182,7 @@ class BOMs extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
public function post($request_data = null)
|
public function post($request_data = null)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->bom->create) {
|
if(! DolibarrApiAccess::$user->rights->bom->write) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
// Check mandatory fields
|
// Check mandatory fields
|
||||||
@@ -215,7 +207,7 @@ class BOMs extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
public function put($id, $request_data = null)
|
public function put($id, $request_data = null)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->bom->create) {
|
if(! DolibarrApiAccess::$user->rights->bom->write) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +216,7 @@ class BOMs extends DolibarrApi
|
|||||||
throw new RestException(404, 'BOM not found');
|
throw new RestException(404, 'BOM not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('bom', $this->bom->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('bom', $this->bom->id, 'bom_bom')) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +231,7 @@ class BOMs extends DolibarrApi
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new RestException(500, $this->commande->error);
|
throw new RestException(500, $this->bom->error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +251,7 @@ class BOMs extends DolibarrApi
|
|||||||
throw new RestException(404, 'BOM not found');
|
throw new RestException(404, 'BOM not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! DolibarrApi::_checkAccessToResource('bom', $this->bom->id)) {
|
if (! DolibarrApi::_checkAccessToResource('bom', $this->bom->id, 'bom_bom')) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,12 +301,13 @@ class BOMs extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
private function _validate($data)
|
private function _validate($data)
|
||||||
{
|
{
|
||||||
$bom = array();
|
$myobject = array();
|
||||||
foreach (BOMs::$FIELDS as $field) {
|
foreach ($this->myobject->fields as $field => $propfield) {
|
||||||
|
if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) continue; // Not a mandatory field
|
||||||
if (!isset($data[$field]))
|
if (!isset($data[$field]))
|
||||||
throw new RestException(400, "$field field missing");
|
throw new RestException(400, "$field field missing");
|
||||||
$bom[$field] = $data[$field];
|
$myobject[$field] = $data[$field];
|
||||||
}
|
}
|
||||||
return $bom;
|
return $myobject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2436,6 +2436,9 @@ function getModuleDirForApiClass($module)
|
|||||||
elseif ($module == 'tickets') {
|
elseif ($module == 'tickets') {
|
||||||
$moduledirforclass = 'ticket';
|
$moduledirforclass = 'ticket';
|
||||||
}
|
}
|
||||||
|
elseif ($module == 'boms') {
|
||||||
|
$moduledirforclass = 'bom';
|
||||||
|
}
|
||||||
|
|
||||||
return $moduledirforclass;
|
return $moduledirforclass;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,16 +67,16 @@ class MyModuleApi extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
public function get($id)
|
public function get($id)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->mymodule->read) {
|
if (! DolibarrApiAccess::$user->rights->mymodule->read) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->myobject->fetch($id);
|
$result = $this->myobject->fetch($id);
|
||||||
if( ! $result ) {
|
if (! $result) {
|
||||||
throw new RestException(404, 'MyObject not found');
|
throw new RestException(404, 'MyObject not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('myobject', $this->myobject->id, 'mymodule_myobject')) {
|
if (! DolibarrApi::_checkAccessToResource('myobject', $this->myobject->id, 'mymodule_myobject')) {
|
||||||
throw new RestException(401, 'Access to instance id='.$this->myobject->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access to instance id='.$this->myobject->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user