From d8b4f9248de80e4a2cd0992565d449ac3f106df7 Mon Sep 17 00:00:00 2001 From: Pichi1966 <57623859+josett225@users.noreply.github.com> Date: Thu, 13 Jun 2024 08:53:30 +0200 Subject: [PATCH] # NEW : add ActionComm categories accessible thru API (#30005) * Update api_categories.class.php Add Actioncomm Categories management thru API * Update api_categories.class.php * Update api_categories.class.php * Update api_categories.class.php * Update api_categories.class.php * Update api_categories.class.php --- .../categories/class/api_categories.class.php | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index a779419c426..96227240a72 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2024 Jose MARTINEZ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +20,7 @@ use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php'; - +require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/api_members.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/api_products.class.php'; @@ -125,7 +126,7 @@ class Categories extends DolibarrApi * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number - * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact', 'actioncomm') * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names * @return array Array of category objects @@ -295,7 +296,7 @@ class Categories extends DolibarrApi * Get the list of categories linked to an object * * @param int $id Object ID - * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact', 'project') + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact', 'project', 'actioncomm') * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list @@ -315,7 +316,8 @@ class Categories extends DolibarrApi Categorie::TYPE_SUPPLIER, Categorie::TYPE_MEMBER, Categorie::TYPE_PROJECT, - Categorie::TYPE_KNOWLEDGEMANAGEMENT + Categorie::TYPE_KNOWLEDGEMANAGEMENT, + Categorie::TYPE_ACTIONCOMM ])) { throw new RestException(403); } @@ -334,6 +336,8 @@ class Categories extends DolibarrApi throw new RestException(403); } elseif ($type == Categorie::TYPE_KNOWLEDGEMANAGEMENT && !DolibarrApiAccess::$user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) { throw new RestException(403); + } elseif ($type == Categorie::TYPE_ACTIONCOMM && !DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) { + throw new RestException(403); } $categories = $this->category->getListForItem($id, $type, $sortfield, $sortorder, $limit, $page); @@ -348,7 +352,7 @@ class Categories extends DolibarrApi * Link an object to a category by id * * @param int $id ID of category - * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact', 'actioncomm') * @param int $object_id ID of object * * @return array @@ -396,6 +400,11 @@ class Categories extends DolibarrApi throw new RestException(403); } $object = new Adherent($this->db); + } elseif ($type === Categorie::TYPE_ACTIONCOMM) { + if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) { + throw new RestException(403); + } + $object = new ActionComm($this->db); } else { throw new RestException(400, "this type is not recognized yet."); } @@ -472,6 +481,11 @@ class Categories extends DolibarrApi throw new RestException(403); } $object = new Adherent($this->db); + } elseif ($type === Categorie::TYPE_ACTIONCOMM) { + if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) { + throw new RestException(403); + } + $object = new ActionComm($this->db); } else { throw new RestException(400, "this type is not recognized yet."); } @@ -500,7 +514,7 @@ class Categories extends DolibarrApi * Unlink an object from a category by id * * @param int $id ID of category - * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact', 'actioncomm') * @param int $object_id ID of the object * * @return array @@ -548,6 +562,11 @@ class Categories extends DolibarrApi throw new RestException(403); } $object = new Adherent($this->db); + } elseif ($type === Categorie::TYPE_ACTIONCOMM) { + if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) { + throw new RestException(403); + } + $object = new ActionComm($this->db); } else { throw new RestException(400, "this type is not recognized yet."); } @@ -574,7 +593,7 @@ class Categories extends DolibarrApi * Unlink an object from a category by ref * * @param int $id ID of category - * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact', 'actioncomm') * @param string $object_ref Reference of the object * * @return array @@ -622,6 +641,11 @@ class Categories extends DolibarrApi throw new RestException(403); } $object = new Adherent($this->db); + } elseif ($type === Categorie::TYPE_ACTIONCOMM) { + if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) { + throw new RestException(403); + } + $object = new ActionComm($this->db); } else { throw new RestException(400, "this type is not recognized yet."); } @@ -774,6 +798,7 @@ class Categories extends DolibarrApi } elseif ($type == 'project') { $objects_api = new Projects(); } + if (is_object($objects_api)) { foreach ($objects as $obj) { $cleaned_objects[] = $objects_api->_cleanObjectDatas($obj);