0
Отклонен

webservice allow sla setting on ticket creation

yves tesniere 9 лет назад обновлен glpi 8 лет назад 2

Allow to set sla when create ticket by webservices :

lines in bold added to webservice plugin class function methodCreateTicket:

methodhelpdesk.class.php

/**
* Create a new ticket
* for an authenticated user
*
* @param $params array of options
* (entity, user, group, date, itemtype, itemid, title, content, urgency, category)
* @param $protocol the communication protocol used
*
* @return array of hashtable
**/
static function methodCreateTicket($params=array(), $protocol) {
global $CFG_GLPI;



if (isset($params['help'])) {
return array('content' => 'string,mandatory',
'title' => 'string,optional',
'entity' => 'integer,optional',
'urgency' => 'integer,optional',
'impact' => 'integer,optional',
'category' => 'integer,optional',
'user' => 'integer,optional',
'requester' => 'integer,optional',
'observer' => 'integer,optional',
'group' => 'integer,optional',
'groupassign' => 'integer,optional',
'date' => 'datetime,optional',
'type' => 'integer,optional',
'category' => 'integer,optional',
'itemtype' => 'string,optional',
'item' => 'integer,optional',
'source' => 'string,optional',
'user_email' => 'string,optional',
'use_email_notification' => 'bool,optional',
'slas_id' => 'integer,optional',
'help' => 'bool,optional');
}



if (!Session::getLoginUserID()) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
}



// ignore config for content : always mandatory
if ((!isset($params['content']) || empty($params['content']))) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'content');
}



// Source of the ticket, dynamically created
if (isset($params['source'])) {
if (empty($params['content'])) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'source');
}
$source = Dropdown::importExternal('RequestType', $params['source']);
} else {
$source = Dropdown::importExternal('RequestType', 'WebServices');
}



// ===== Build the Ticket =====
// author : always the logged user
$data = array('_users_id_requester'
=> Session::getLoginUserID(), // Requester / Victime
'users_id_recipient'
=> Session::getLoginUserID(), // Recorder
'requesttypes_id'
=> $source,
'status' => Ticket::INCOMING,
'content' => addslashes(Toolbox::clean_cross_side_scripting_deep($params["content"])),
'type' => Ticket::INCIDENT_TYPE,
'items_id' => 0);



// Title : optional (default = start of contents set by add method)
if (isset($params['title'])) {
$data['name'] = addslashes(Toolbox::clean_cross_side_scripting_deep($params['title']));
}



// entity : optionnal, default = current one
if (!isset($params['entity'])) {
$data['entities_id'] = $_SESSION['glpiactive_entity'];
} else {
if (!is_numeric($params['entity'])
|| !in_array($params['entity'], $_SESSION['glpiactiveentities'])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'entity');
}
$data['entities_id'] = $params['entity'];
}



// user (author) : optionnal, default = current one
if (isset($params['user'])) {
if (!is_numeric($params['user'])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user');
}
$data['_users_id_requester'] = $params['user'];
}



// Email notification
if (isset($params['user_email'])) {
if (!NotificationMail::isUserAddressValid($params['user_email'])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user_email');
}
$data['_users_id_requester_notif']['alternative_email'] = $params['user_email'];
$data['_users_id_requester_notif']['use_notification'] = 1;



} else if (isset($params['use_email_notification']) && $params['use_email_notification']) {
$data['_users_id_requester_notif']['use_notification'] = 1;



} else if (isset($params['use_email_notification']) && !$params['use_email_notification']) {
$data['_users_id_requester_notif']['use_notification'] = 0;
}



if (isset($params['requester'])) {
if (is_array($params['requester'])) {
foreach ($params['requester'] as $id) {
if (is_numeric($id) && $id > 0) {
$data['_additional_requesters'][] = array('users_id' => $id,
'use_notification' => true);
} else {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'requester');
}
}
} else if (is_numeric($params['requester']) && ($params['requester'] > 0)) {
$data['_additional_requesters'][] = array('users_id' => $params['requester'],
'use_notification' => true);
} else {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'requester');
}
}



if (isset($params['victim'])) {
if (is_array($params['victim'])) {
foreach ($params['victim'] as $id) {
if (is_numeric($id) && ($id > 0)) {
$data['_additional_requesters'][] = array('users_id' => $id,
'use_notification' => false);
} else {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'victim');
}
}
} else if (is_numeric($params['victim']) && ($params['victim'] > 0)) {
$data['_additional_requesters'][] = array('users_id' => $params['victim'],
'use_notification' => false);
} else {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'victim');
}
}



if (isset($params['observer'])) {
if (is_array($params['observer'])) {
foreach ($params['observer'] as $id) {
if (is_numeric($id) && ($id > 0)) {
$data['_additional_observers'][] = array('users_id' => $id,
'use_notification' => true);
} else {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'observer');
}
}
} else if (is_numeric($params['observer']) && ($params['observer'] > 0)) {
$data['_additional_observers'][] = array('users_id' => $params['observer'],
'use_notification' => true);
} else {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'observer');
}
}



// group (author) : optionnal, default = none
if (!isset($params['group'])) {
$data['_groups_id_requester'] = 0;
} else {
if (!is_numeric($params['group'])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'group');
}
$data['_groups_id_requester'] = $params['group'];
}



// groupassign (technicians group) : optionnal, default = none
if (!isset($params['groupassign'])) {
$data['_groups_id_assign'] = 0;
} else {
if (!is_numeric($params['groupassign'])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'groupassign');
}
$data['_groups_id_assign'] = $params['groupassign'];
}



// date (open) : optional, default set by add method
if (isset($params['date'])) {
if (preg_match(WEBSERVICES_REGEX_DATETIME, $params['date'])) {
$data['date'] = $params['date'];
} else {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'date');
}
}



// Item type + id
if (isset($params['itemtype'])) {
if (!isset($params['item'])) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'item');
}
if (!class_exists($params['itemtype'])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '',
'itemtype=' . $params['itemtype']);
}
}



$item = NULL;
if (isset($params['item'])) {
if (!isset($params['itemtype'])) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '','itemtype');
}
if (!is_numeric($params['item']) || $params['item'] <= 0) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '',
'item=' . $params['item']);
}



// Both ok
$data['itemtype'] = $params['itemtype'];
$data['items_id'] = $params['item'];
}



// Hack for compatibility with previous version
if (isset($params['urgence'])) {
$params['urgency'] = $params['urgence'];
}



// urgence (priority while not exists) : optionnal, default = 3
if (!isset($params['urgency'])) {
$data['urgency'] = 3;



} else if ((!is_numeric($params['urgency'])
|| ($params['urgency'] < 1)
|| ($params['urgency'] > 5))
|| (isset($params['urgency'])
&& !($CFG_GLPI['urgency_mask']&(1<<$params["urgency"])))) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'urgency');



} else {
$data['urgency'] = $params['urgency'];
}



if (isset($params['impact'])) {
if ((!is_numeric($params['impact'])
|| ($params['impact'] < 1)
|| ($params['impact'] > 5))
|| (isset($params['impact'])
&& !($CFG_GLPI['impact_mask']&(1<<$params["impact"])))) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'impact');
} else {
$data['impact'] = $params['impact'];
}
}



// category : optionnal
if (isset($params['category'])) {
if (!is_numeric($params['category']) || ($params['category'] < 1)) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'category');
}
$data['itilcategories_id'] = $params['category'];
}
// slas_id : optionnal
if (isset($params['slas_id'])) {
if (!is_numeric($params['slas_id']) || ($params['slas_id'] < 1)) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'slas_id');
}
$data['slas_id'] = $params['slas_id'];
}



// type : optionnal (default = INCIDENT)
if (isset($params['type'])) {
$types = Ticket::getTypes();
if (!is_numeric($params['type']) || !isset($types[$params['type']])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'type');
}
$data['type'] = $params['type'];
}
$ticket = new Ticket();
if (!$ticket->canCreate()) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
}
if (!$ticket->canAssign()) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
$data['_groups_id_assign'] = 0;
}
if ($newID = $ticket->add($data)) {
return self::methodGetTicket(array('ticket' => $newID), $protocol);
}
return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '',self::getDisplayError());
}


Hello,

This is a plugin feature request.

Please post your suggestion on the plugin's forge.


For your information, a new GLPi integrated API will be released in version 9.1

Сервис поддержки клиентов работает на платформе UserEcho