Add all types everywhere

This commit is contained in:
Cédric 2019-11-15 23:08:25 +01:00 committed by GitHub
parent cc6d8f159b
commit 4332834ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -296,7 +296,13 @@ class Categories extends DolibarrApi
*/ */
public function getListForObject($id, $type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) public function getListForObject($id, $type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
{ {
if (!in_array($type, ['product', 'member', 'customer', 'supplier', 'contact'])) { if (!in_array($type, [
Categorie::TYPE_PRODUCT,
Categorie::TYPE_CONTACT,
Categorie::TYPE_CUSTOMER,
Categorie::TYPE_SUPPLIER,
Categorie::TYPE_MEMBER
])) {
throw new RestException(401); throw new RestException(401);
} }
@ -350,12 +356,31 @@ class Categories extends DolibarrApi
throw new RestException(404, 'category not found'); throw new RestException(404, 'category not found');
} }
// TODO Add all types if ($type === Categorie::TYPE_PRODUCT) {
if ($type === "product") {
if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) {
throw new RestException(401); throw new RestException(401);
} }
$object = new Product($this->db); $object = new Product($this->db);
} elseif ($type === Categorie::TYPE_CUSTOMER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_SUPPLIER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_CONTACT) {
if(! DolibarrApiAccess::$user->rights->societe->contact->creer) {
throw new RestException(401);
}
$object = new Contact($this->db);
} elseif ($type === Categorie::TYPE_MEMBER) {
if(! DolibarrApiAccess::$user->rights->adherent->creer) {
throw new RestException(401);
}
$object = new Adherent($this->db);
} else { } else {
throw new RestException(401, "this type is not recognized yet."); throw new RestException(401, "this type is not recognized yet.");
} }
@ -411,12 +436,31 @@ class Categories extends DolibarrApi
throw new RestException(404, 'category not found'); throw new RestException(404, 'category not found');
} }
// TODO Add all types if ($type === Categorie::TYPE_PRODUCT) {
if ($type === "product") {
if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) {
throw new RestException(401); throw new RestException(401);
} }
$object = new Product($this->db); $object = new Product($this->db);
} elseif ($type === Categorie::TYPE_CUSTOMER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_SUPPLIER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_CONTACT) {
if(! DolibarrApiAccess::$user->rights->societe->contact->creer) {
throw new RestException(401);
}
$object = new Contact($this->db);
} elseif ($type === Categorie::TYPE_MEMBER) {
if(! DolibarrApiAccess::$user->rights->adherent->creer) {
throw new RestException(401);
}
$object = new Adherent($this->db);
} else { } else {
throw new RestException(401, "this type is not recognized yet."); throw new RestException(401, "this type is not recognized yet.");
} }
@ -472,12 +516,31 @@ class Categories extends DolibarrApi
throw new RestException(404, 'category not found'); throw new RestException(404, 'category not found');
} }
// TODO Add all types if ($type === Categorie::TYPE_PRODUCT) {
if ($type === "product") {
if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) {
throw new RestException(401); throw new RestException(401);
} }
$object = new Product($this->db); $object = new Product($this->db);
} elseif ($type === Categorie::TYPE_CUSTOMER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_SUPPLIER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_CONTACT) {
if(! DolibarrApiAccess::$user->rights->societe->contact->creer) {
throw new RestException(401);
}
$object = new Contact($this->db);
} elseif ($type === Categorie::TYPE_MEMBER) {
if(! DolibarrApiAccess::$user->rights->adherent->creer) {
throw new RestException(401);
}
$object = new Adherent($this->db);
} else { } else {
throw new RestException(401, "this type is not recognized yet."); throw new RestException(401, "this type is not recognized yet.");
} }
@ -531,12 +594,31 @@ class Categories extends DolibarrApi
throw new RestException(404, 'category not found'); throw new RestException(404, 'category not found');
} }
// TODO Add all types if ($type === Categorie::TYPE_PRODUCT) {
if ($type === "product") {
if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) {
throw new RestException(401); throw new RestException(401);
} }
$object = new Product($this->db); $object = new Product($this->db);
} elseif ($type === Categorie::TYPE_CUSTOMER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_SUPPLIER) {
if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
$object = new Societe($this->db);
} elseif ($type === Categorie::TYPE_CONTACT) {
if(! DolibarrApiAccess::$user->rights->societe->contact->creer) {
throw new RestException(401);
}
$object = new Contact($this->db);
} elseif ($type === Categorie::TYPE_MEMBER) {
if(! DolibarrApiAccess::$user->rights->adherent->creer) {
throw new RestException(401);
}
$object = new Adherent($this->db);
} else { } else {
throw new RestException(401, "this type is not recognized yet."); throw new RestException(401, "this type is not recognized yet.");
} }