Skip to content

Commit

Permalink
fix(issue): enhance error message when canceling an issue
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Oct 26, 2020
1 parent bdd533a commit cf21817
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 6 additions & 1 deletion ajax/cancelticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
exit;
}
$ticketId = (int) $_POST['id'];
PluginFormcreatorCommon::cancelMyTicket($ticketId);
if (!PluginFormcreatorCommon::cancelMyTicket($ticketId)) {
http_response_code(403);
echo implode('<br>', $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR]);
$_SESSION['MESSAGE_AFTER_REDIRECT'] = [];
exit;
}
16 changes: 15 additions & 1 deletion inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,28 @@ public static function showFontAwesomeDropdown($name, $options = []) {
echo $output;
}

/**
* Cancel a new ticketn while it is still allowed
*
* In case of error, a message is added to the session
*
* @param integer $id
* @return boolean true on success, false otherwise
*/
public static function cancelMyTicket($id) {
$ticket = new Ticket();
$ticket->getFromDB($id);
if (!$ticket->canRequesterUpdateItem()) {
Session::addMessageAfterRedirect(__('You cannot delete this issue. Maybe it is taken into account.', 'formcreator'), true, ERROR);
return false;
}

if (!$ticket->delete($ticket->fields)) {
Session::addMessageAfterRedirect(__('Failed to delete this issue. An internal error occured.', 'formcreator'), true, ERROR);
return false;
}

return $ticket->delete($ticket->fields);
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,6 @@ function plugin_formcreator_cancelMyTicket(id) {
}).done(function(response) {
window.location.replace(formcreatorRootDoc + '/front/issue.php?reset=reset');
}).error(function(response) {
alert("<?php echo __('Failed to cancel the ticket', 'formcreator'); ?>");
alert(response.responseText);
});
}
}

0 comments on commit cf21817

Please sign in to comment.