More work on exception handling and user context building
parent
e68ecf50c6
commit
8968be1ffd
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/28/2017
|
||||
* Time: 8:54 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Helpers;
|
||||
|
||||
|
||||
class Helpers {
|
||||
static function getHeader($key) {
|
||||
$headers = getallheaders();
|
||||
|
||||
$uppercaseHeaders = array();
|
||||
foreach ($headers as $header => $value) {
|
||||
$uppercaseHeaders[strtoupper($header)] = $value;
|
||||
}
|
||||
|
||||
return isset($uppercaseHeaders[$key])
|
||||
? $uppercaseHeaders[$key]
|
||||
: NULL;
|
||||
}
|
||||
|
||||
static function hashToken($token) {
|
||||
return hash('sha512', $token);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
<?php
|
||||
namespace BusinessLogic\Category;
|
||||
|
||||
use DataAccess\CategoryGateway;
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidAuthenticationTokenException extends Exception {
|
||||
public function __construct() {
|
||||
parent::__construct('The X-Auth-Token is invalid. The token must be for an active helpdesk user.');
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/28/2017
|
||||
* Time: 9:55 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class MissingAuthenticationTokenException extends Exception {
|
||||
function __construct() {
|
||||
parent::__construct("An 'X-Auth-Token' is required for all requests");
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\Validation;
|
||||
namespace BusinessLogic\Exceptions;
|
||||
|
||||
use BusinessLogic\Validation\ValidationModel;
|
||||
use Exception;
|
||||
|
||||
class ValidationException extends Exception {
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
require_once(API_PATH . 'dao/security_dao.php');
|
||||
|
||||
function get_user_for_token($token, $hesk_settings) {
|
||||
|
||||
$hash = hash('sha512', $token);
|
||||
|
||||
return get_user_for_token_hash($hash, $hesk_settings);
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
|
@ -1,107 +0,0 @@
|
||||
<?php
|
||||
require_once(API_PATH . 'dao/ticket_dao.php');
|
||||
|
||||
function get_ticket_for_staff($hesk_settings, $user, $id = NULL) {
|
||||
|
||||
$tickets = get_ticket_for_id($hesk_settings, $user, $id);
|
||||
|
||||
if ($tickets == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($id === NULL) {
|
||||
$original_tickets = $tickets;
|
||||
$tickets = array();
|
||||
foreach ($original_tickets as $ticket) {
|
||||
$ticket = remove_common_properties($ticket);
|
||||
$ticket = convert_to_camel_case($ticket);
|
||||
$ticket = handle_dates($ticket);
|
||||
$tickets[] = $ticket;
|
||||
}
|
||||
} else {
|
||||
$tickets = remove_common_properties($tickets);
|
||||
$tickets = handle_dates($tickets);
|
||||
$tickets = convert_to_camel_case($tickets);
|
||||
}
|
||||
|
||||
|
||||
return $tickets;
|
||||
}
|
||||
|
||||
function remove_common_properties($ticket) {
|
||||
unset($ticket['lastchange']);
|
||||
unset($ticket['firstreply']);
|
||||
unset($ticket['closedat']);
|
||||
unset($ticket['openedby']);
|
||||
unset($ticket['firstreplyby']);
|
||||
unset($ticket['closedby']);
|
||||
unset($ticket['replies']);
|
||||
unset($ticket['staffreplies']);
|
||||
unset($ticket['lastreplier']);
|
||||
unset($ticket['replierid']);
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
function handle_dates($ticket) {
|
||||
$ticket['dt'] = hesk_date($ticket['dt'], true);
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
function convert_to_camel_case($ticket) {
|
||||
if (isset($ticket['articles'])) {
|
||||
$ticket['suggestedArticles'] = $ticket['articles'];
|
||||
unset($ticket['articles']);
|
||||
}
|
||||
$ticket['legacyAuditTrail'] = $ticket['history'];
|
||||
unset($ticket['history']);
|
||||
$ticket['linkedTo'] = $ticket['parent'];
|
||||
unset($ticket['parent']);
|
||||
$ticket['timeWorked'] = $ticket['time_worked'];
|
||||
unset($ticket['time_worked']);
|
||||
$ticket['userAgent'] = $ticket['user_agent'];
|
||||
unset($ticket['user_agent']);
|
||||
$ticket['screenResolutionWidth'] = $ticket['screen_resolution_width'];
|
||||
unset($ticket['screen_resolution_width']);
|
||||
$ticket['screenResolutionHeight'] = $ticket['screen_resolution_height'];
|
||||
unset($ticket['screen_resolution_height']);
|
||||
$ticket['trackingId'] = $ticket['trackid'];
|
||||
unset($ticket['trackid']);
|
||||
$ticket['dateCreated'] = $ticket['dt'];
|
||||
unset($ticket['dt']);
|
||||
$ticket['dueDate'] = $ticket['due_date'];
|
||||
unset($ticket['due_date']);
|
||||
$ticket['overdueEmailSent'] = $ticket['overdue_email_sent'];
|
||||
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
function get_ticket($hesk_settings, $id) {
|
||||
$ticket = get_ticket_for_id($hesk_settings, $id);
|
||||
$ticket = remove_common_properties($ticket);
|
||||
$ticket = remove_staff_specific_properties($ticket);
|
||||
$ticket = convert_to_camel_case($ticket);
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
function remove_staff_specific_properties($ticket) {
|
||||
unset($ticket['articles']);
|
||||
unset($ticket['ip']);
|
||||
unset($ticket['language']);
|
||||
unset($ticket['owner']);
|
||||
unset($ticket['time_worked']);
|
||||
unset($ticket['history']);
|
||||
unset($ticket['latitude']);
|
||||
unset($ticket['longitude']);
|
||||
unset($ticket['user_agent']);
|
||||
unset($ticket['screen_resolution_width']);
|
||||
unset($ticket['screen_resolution_height']);
|
||||
unset($ticket['parent']);
|
||||
unset($ticket['due_date']);
|
||||
unset($ticket['overdue_email_sent']);
|
||||
|
||||
return $ticket;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
require_once(API_PATH . 'dao/user_dao.php');
|
||||
|
||||
function retrieve_user($hesk_settings, $id = NULL) {
|
||||
$users = get_user($hesk_settings, $id);
|
||||
|
||||
if ($id === NULL) {
|
||||
$original_users = $users;
|
||||
$users = array();
|
||||
foreach ($original_users as $user) {
|
||||
$user = remove_unneeded_properties($user);
|
||||
$user = convert_to_camel_case($user);
|
||||
$users[] = $user;
|
||||
}
|
||||
} else {
|
||||
$users = remove_unneeded_properties($users);
|
||||
$users = convert_to_camel_case($users);
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
function remove_unneeded_properties($user) {
|
||||
unset($user['pass']);
|
||||
unset($user['permission_template']);
|
||||
unset($user['language']);
|
||||
unset($user['replies']);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
function convert_to_camel_case($user) {
|
||||
$user['username'] = $user['user'];
|
||||
unset($user['user']);
|
||||
$user['admin'] = $user['isadmin'];
|
||||
unset($user['isadmin']);
|
||||
$user['afterReply'] = $user['afterreply'];
|
||||
unset($user['afterreply']);
|
||||
$user['autoStart'] = $user['autostart'];
|
||||
unset($user['autostart']);
|
||||
$user['notifyCustomerNew'] = $user['notify_customer_new'];
|
||||
unset($user['notify_customer_new']);
|
||||
$user['notifyCustomerReply'] = $user['notify_customer_reply'];
|
||||
unset($user['notify_customer_reply']);
|
||||
$user['showSuggested'] = $user['show_suggested'];
|
||||
unset($user['show_suggested']);
|
||||
$user['notifyNewUnassigned'] = $user['notify_new_unassigned'];
|
||||
unset($user['notify_new_unassigned']);
|
||||
$user['notifyNewMy'] = $user['notify_new_my'];
|
||||
unset($user['notify_new_my']);
|
||||
$user['notifyReplyUnassigned'] = $user['notify_reply_unassigned'];
|
||||
unset($user['notify_reply_unassigned']);
|
||||
$user['notifyReplyMy'] = $user['notify_reply_my'];
|
||||
unset($user['notify_reply_my']);
|
||||
$user['notifyAssigned'] = $user['notify_assigned'];
|
||||
unset($user['notify_assigned']);
|
||||
$user['notifyPm'] = $user['notify_pm'];
|
||||
unset($user['notify_pm']);
|
||||
$user['notifyNote'] = $user['notify_note'];
|
||||
unset($user['notify_note']);
|
||||
$user['notifyNoteUnassigned'] = $user['notify_note_unassigned'];
|
||||
unset($user['notify_note_unassigned']);
|
||||
$user['defaultList'] = $user['default_list'];
|
||||
unset($user['default_list']);
|
||||
$user['ratingNeg'] = $user['ratingneg'];
|
||||
unset($user['ratingneg']);
|
||||
$user['ratingPos'] = $user['ratingpos'];
|
||||
unset($user['ratingpos']);
|
||||
$user['heskPrivileges'] = $user['heskprivileges'];
|
||||
unset($user['heskprivileges']);
|
||||
$user['defaultCalendarView'] = $user['default_calendar_view'];
|
||||
unset($user['default_calendar_view']);
|
||||
$user['notifyOverdueUnassigned'] = $user['notify_overdue_unassigned'];
|
||||
unset($user['notify_overdue_unassigned']);
|
||||
|
||||
return $user;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
function get_header($key) {
|
||||
$headers = getallheaders();
|
||||
|
||||
return isset($headers[$key])
|
||||
? $headers[$key]
|
||||
: NULL;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
function get_category($hesk_settings, $id = NULL) {
|
||||
$sql = "SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` ";
|
||||
if ($id != NULL) {
|
||||
$sql .= "WHERE `id` = ".intval($id);
|
||||
}
|
||||
|
||||
$response = hesk_dbQuery($sql);
|
||||
|
||||
if (hesk_dbNumRows($response) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$results = array();
|
||||
while ($row = hesk_dbFetchAssoc($response)) {
|
||||
$row['id'] = intval($row['id']);
|
||||
$row['displayOrder'] = intval($row['cat_order']);
|
||||
unset($row['cat_order']);
|
||||
$row['autoassign'] = $row['autoassign'] == 1;
|
||||
$row['type'] = intval($row['type']);
|
||||
$row['priority'] = intval($row['priority']);
|
||||
$row['manager'] = intval($row['manager']) == 0 ? NULL : intval($row['manager']);
|
||||
$results[] = $row;
|
||||
}
|
||||
|
||||
return $id == NULL ? $results : $results[0];
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
class AccessException extends Exception {
|
||||
public function __construct($code)
|
||||
{
|
||||
$message = '';
|
||||
if ($code == 401) {
|
||||
$message = 'The X-Auth-Token is invalid';
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue