From 345a256ef60cc780bffe58359d021bb2b8519e35 Mon Sep 17 00:00:00 2001 From: Carlos Herrera Date: Tue, 7 Oct 2025 20:48:58 +0200 Subject: [PATCH] API get documents dont support "projects_tasks" (#35671) * API get documents dont support "projects_tasks" Fixes #35650 * fix: add missing whitespace formatting in api_documents class --------- Co-authored-by: Laurent Destailleur --- htdocs/api/class/api_documents.class.php | 38 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index c2201fed3fc..b96ca75da94 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -80,6 +80,11 @@ class Documents extends DolibarrApi throw new RestException(400, 'bad value for parameter original_file'); } + // Normalize modulepart for project_task + if ($modulepart == 'task' || $modulepart == 'project_task') { + $modulepart = 'project_task'; + } + //--- Finds and returns the document $entity = $conf->entity; @@ -314,11 +319,11 @@ class Documents extends DolibarrApi * List documents of an element * * Use element ID or Ref. - * Supported modules: thirdparty, user, member, proposal, order, supplier_order, shipment, invoice, supplier_invoice, product, event, expensereport, knowledgemanagement, category, contract + * Supported modules: thirdparty, user, member, proposal, order, supplier_order, shipment, invoice, supplier_invoice, product, event, expensereport, knowledgemanagement, category, contract, project, project_task * * @since 7.0.0 Initial implementation * - * @param string $modulepart Name of module or area concerned ('thirdparty', 'member', 'proposal', 'order', 'invoice', 'supplier_invoice', 'shipment', 'project', ...) + * @param string $modulepart Name of module or area concerned ('thirdparty', 'member', 'proposal', 'order', 'invoice', 'supplier_invoice', 'shipment', 'project', 'project_task', ...) * @param int $id ID of element * @param string $ref Ref of element * @param string $sortfield Sort criteria ('','fullname','relativename','name','date','size') @@ -634,8 +639,28 @@ class Documents extends DolibarrApi if (!$result) { throw new RestException(404, 'Project not found'); } + $upload_dir = $conf->project->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'project'); + } elseif ($modulepart == 'task' || $modulepart == 'project_task') { + $modulepart = 'project_task'; + require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php'; - $upload_dir = getMultidirOutput($object) . "/" . get_exdir(0, 0, 0, 1, $object, 'project'); + if (!DolibarrApiAccess::$user->hasRight('projet', 'lire')) { + throw new RestException(403); + } + + $object = new Task($this->db); + $result = $object->fetch($id, $ref); + if (!$result) { + throw new RestException(404, 'Task not found'); + } + + // Fetch the project to build the correct path + $project_result = $object->fetchProject(); + if ($project_result < 0) { + throw new RestException(500, 'Error while fetching project for task'); + } + + $upload_dir = $conf->project->dir_output . "/" . dol_sanitizeFileName($object->project->ref) . "/" . dol_sanitizeFileName($object->ref); } elseif ($modulepart == 'mrp') { $modulepart = 'mrp'; require_once DOL_DOCUMENT_ROOT . '/mrp/class/mo.class.php'; @@ -1067,7 +1092,7 @@ class Documents extends DolibarrApi * * @since 11.0.0 Initial implementation * - * @param string $modulepart Name of module or area concerned by file download ('product', ...) + * @param string $modulepart Name of module or area concerned by file download ('product', 'project', 'project_task', ...) * @param string $original_file Relative path with filename, relative to modulepart (for example: PRODUCT-REF-999/IMAGE-999.jpg) * @return array Success code * @phan-return array{success:array{code:int,message:string}} @@ -1092,6 +1117,11 @@ class Documents extends DolibarrApi throw new RestException(400, 'bad value for parameter original_file'); } + // Normalize modulepart for project_task + if ($modulepart == 'task') { + $modulepart = 'project_task'; + } + //--- Finds and returns the document $entity = $conf->entity;