From 1a38e78a9b09e4b3d64ee4ece1f3b20ffc736c9f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 13 May 2023 14:36:08 +0200 Subject: [PATCH] Fix error management on file upload on ticket --- htdocs/ticket/card.php | 39 +++++++++++++++------------- htdocs/ticket/class/ticket.class.php | 23 +++++++++++----- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index d46a787f983..cd04a62124e 100755 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -58,6 +58,7 @@ $projectid = GETPOST('projectid', 'int'); $cancel = GETPOST('cancel', 'alpha'); $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); +$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); $contactid = GETPOST('contactid', 'int'); $notifyTiers = GETPOST("notify_tiers_at_create", 'alpha'); @@ -115,6 +116,10 @@ if ($id || $track_id || $ref) { } } +$now = dol_now(); + +$actionobject = new ActionsTicket($db); + // Store current page url $url_page_current = DOL_URL_ROOT.'/ticket/card.php'; @@ -123,13 +128,12 @@ if ($user->socid > 0) $socid = $user->socid; $result = restrictedArea($user, 'ticket', $object->id); $triggermodname = 'TICKET_MODIFY'; -$permissiontoadd = $user->rights->ticket->write; - -$actionobject = new ActionsTicket($db); +$permissiontoread = $user->hasRight('ticket', 'read'); +$permissiontoadd = $user->hasRight('ticket', 'write'); +$permissiontodelete = $user->hasRight('ticket', 'delete'); $upload_dir = $conf->ticket->dir_output; -$now = dol_now(); /* @@ -174,7 +178,7 @@ if (empty($reshook)) { } // Action to add an action (not a message) - if (GETPOST('save', 'alpha') && !empty($user->rights->ticket->write)) { + if (GETPOST('save', 'alpha') && $permissiontoadd) { $error = 0; if (!GETPOST("type_code", 'alpha')) { @@ -304,7 +308,7 @@ if (empty($reshook)) { } } - if ($action == 'update' && $user->rights->ticket->write && $object->status < Ticket::STATUS_CLOSED) { + if ($action == 'update' && $permissiontoadd && $object->status < Ticket::STATUS_CLOSED) { $error = 0; $ret = $object->fetch(GETPOST('id', 'int'), GETPOST('ref', 'alpha'), GETPOST('track_id', 'alpha')); @@ -369,7 +373,7 @@ if (empty($reshook)) { } // Mark as Read - if ($action == "mark_ticket_read" && $user->rights->ticket->write) { + if ($action == "mark_ticket_read" && $permissiontoadd) { $object->fetch('', '', GETPOST("track_id", 'alpha')); if ($object->markAsRead($user) > 0) { @@ -384,7 +388,7 @@ if (empty($reshook)) { } // Assign to someone - if ($action == "assign_user" && GETPOST('btn_assign_user', 'alpha') && $user->rights->ticket->write) { + if ($action == "assign_user" && GETPOST('btn_assign_user', 'alpha') && $permissiontoadd) { $object->fetch('', '', GETPOST("track_id", 'alpha')); $useroriginassign = $object->fk_user_assign; $usertoassign = GETPOST('fk_user_assign', 'int'); @@ -443,7 +447,7 @@ if (empty($reshook)) { // Action to add a message (private or not, with email or not). // This may also send an email (concatenated with email_intro and email footer if checkbox was selected) - if ($action == 'add_message' && GETPOSTISSET('btn_add_message') && $user->rights->ticket->read) { + if ($action == 'add_message' && GETPOSTISSET('btn_add_message') && $permissiontoread) { $ret = $object->newMessage($user, $action, (GETPOST('private_message', 'alpha') == "on" ? 1 : 0), 0); if ($ret > 0) { @@ -461,7 +465,7 @@ if (empty($reshook)) { } } - if (($action == "confirm_close" || $action == "confirm_abandon") && GETPOST('confirm', 'alpha') == 'yes' && $user->rights->ticket->write) { + if (($action == "confirm_close" || $action == "confirm_abandon") && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) { $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); if ($object->close($user, ($action == "confirm_abandon" ? 1 : 0))) { @@ -475,7 +479,7 @@ if (empty($reshook)) { } } - if ($action == "confirm_public_close" && GETPOST('confirm', 'alpha') == 'yes') { + if ($action == "confirm_public_close" && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) { $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); if ($_SESSION['email_customer'] == $object->origin_email || $_SESSION['email_customer'] == $object->thirdparty->email) { $object->close($user); @@ -493,7 +497,7 @@ if (empty($reshook)) { } } - if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $user->rights->ticket->delete) { + if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $permissiontodelete) { if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { if ($object->delete($user) > 0) { setEventMessages('
'.$langs->trans('TicketDeletedSuccess').'
', null, 'mesgs'); @@ -578,7 +582,7 @@ if (empty($reshook)) { } } } - } elseif ($action == 'classin' && $user->rights->ticket->write) { + } elseif ($action == 'classin' && $permissiontoadd) { // Categorisation dans projet if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { $object->setProject($projectid); @@ -586,7 +590,7 @@ if (empty($reshook)) { header("Location: ".$url); exit(); } - } elseif ($action == 'setcontract' && $user->rights->ticket->write) { + } elseif ($action == 'setcontract' && $permissiontoadd) { // Categorisation dans contrat if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) { $object->setContract(GETPOST('contractid', 'int')); @@ -617,7 +621,7 @@ if (empty($reshook)) { } $action = 'view'; - } elseif ($action == 'confirm_set_status' && $user->rights->ticket->write && !GETPOST('cancel')) { + } elseif ($action == 'confirm_set_status' && $permissiontoadd && !GETPOST('cancel')) { // Reopen ticket if ($object->fetch(GETPOST('id', 'int'), GETPOST('track_id', 'alpha')) >= 0) { $new_status = GETPOST('new_status', 'int'); @@ -638,7 +642,7 @@ if (empty($reshook)) { } // Action to update one extrafield - if ($action == "update_extras" && !empty($permissiontoadd)) { + if ($action == "update_extras" && $permissiontoadd) { $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); @@ -662,7 +666,7 @@ if (empty($reshook)) { } } - if ($action == "change_property" && GETPOST('btn_update_ticket_prop', 'alpha') && $user->rights->ticket->write) { + if ($action == "change_property" && GETPOST('btn_update_ticket_prop', 'alpha') && $permissiontoadd) { $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')); $object->type_code = GETPOST('update_value_type', 'aZ09'); @@ -686,7 +690,6 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once // Actions to build doc - $permissiontoadd = $user->rights->ticket->write; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; //var_dump($action);exit; diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index adf104d9ae9..f91d850ebf4 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -2265,8 +2265,8 @@ class Ticket extends CommonObject * Used for files linked into messages. * Files may be renamed during copy to avoid overwriting existing files. * - * @param string $forcetrackid Force trackid - * @return array Array with final path/name/mime of files. + * @param string $forcetrackid Force trackid + * @return array|int Array with final path/name/mime of files. */ public function copyFilesForTicket($forcetrackid = null) { @@ -2309,6 +2309,11 @@ class Ticket extends CommonObject } $res = dol_move($filepath[$i], $destfile, 0, 1, 0, 1); + if (!$res) { + // Move has failed + $this->error = "Failed to move file ".dirbasename($filepath[$i])." into ".dirbasename($destfile); + return -1; + } if (image_format_supported($destfile) == 1) { // Create small thumbs for image (Ratio is near 16/9) @@ -2379,11 +2384,11 @@ class Ticket extends CommonObject * Add new message on a ticket (private/public area). * Can also send it be email if GETPOST('send_email', 'int') is set. For such email, header and footer is added. * - * @param User $user User for action - * @param string $action Action string - * @param int $private 1=Message is private. TODO Implement this. What does this means ? - * @param int $public_area 1=Is the public area - * @return int + * @param User $user User for action + * @param string $action Action string + * @param int $private 1=Message is private. TODO Implement this. What does this means ? + * @param int $public_area 1=Is the public area + * @return int <0 if KO, >= 0 if OK */ public function newMessage($user, &$action, $private = 1, $public_area = 0) { @@ -2420,6 +2425,10 @@ class Ticket extends CommonObject // Copy attached files (saved into $_SESSION) as linked files to ticket. Return array with final name used. $resarray = $object->copyFilesForTicket(); + if (is_numeric($resarray) && $resarray == -1) { + setEventMessages($object->error, $object->errors, 'errors'); + return -1; + } $listofpaths = $resarray['listofpaths']; $listofnames = $resarray['listofnames'];