From 641348d7576cd9be6667e2fe4755b0c8a1ea9529 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 29 Nov 2015 15:39:38 -0500 Subject: [PATCH] Converted everything to camelCase se and some other improvements --- api/admin/canned/index.php | 4 +- api/admin/ticket-template/index.php | 26 ++++++++ api/admin/ticket/index.php | 30 ++++----- api/admin/user/index.php | 88 +++++++++++++++++++++++++- api/businesslogic/ticket_retriever.php | 46 ++++++++++---- api/businesslogic/user_retriever.php | 73 +++++++++++++++++++++ api/category/index.php | 6 +- api/dao/canned_dao.php | 5 +- api/dao/category_dao.php | 3 +- api/dao/ticket_template_dao.php | 3 +- api/dao/user_dao.php | 4 -- api/ticket/index.php | 4 +- 12 files changed, 246 insertions(+), 46 deletions(-) create mode 100644 api/businesslogic/user_retriever.php diff --git a/api/admin/canned/index.php b/api/admin/canned/index.php index bd4357c4..260115f4 100644 --- a/api/admin/canned/index.php +++ b/api/admin/canned/index.php @@ -27,7 +27,7 @@ $request_method = $_SERVER['REQUEST_METHOD']; * @apiSuccess {Number} id ID of the canned response * @apiSuccess {String} title The title of the canned response. * @apiSuccess {String} message The contents of the canned response, including HTML markup. - * @apiSuccess {Integer} reply_order The position of the canned response in the list of canned responses (in multiples of 10). + * @apiSuccess {Integer} replyOrder The position of the canned response in the list of canned responses (in multiples of 10). * * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK @@ -35,7 +35,7 @@ $request_method = $_SERVER['REQUEST_METHOD']; * "id": 2, * "title": "html", * "message": "

My canned response 

\r\n

%%HESK_ID%%

", - * "reply_order": 10 + * "replyOrder": 10 * } * * @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required diff --git a/api/admin/ticket-template/index.php b/api/admin/ticket-template/index.php index 491c792d..dd25d3b6 100644 --- a/api/admin/ticket-template/index.php +++ b/api/admin/ticket-template/index.php @@ -15,6 +15,32 @@ hesk_dbConnect(); // Routing $request_method = $_SERVER['REQUEST_METHOD']; +/** + * @api {get} /admin/ticket-template Retrieve a ticket templates + * @apiVersion 0.0.0 + * @apiName GetTicketTemplate + * @apiGroup Ticket Template + * @apiPermission protected + * + * @apiParam {Number} [id] The ID of the ticket template. Omit for all templates. + * + * @apiSuccess {Number} id ID of the template + * @apiSuccess {String} title The title of the template. + * @apiSuccess {String} message The contents of the template, including HTML markup. + * @apiSuccess {Integer} displayOrder The position of the template in the list of templates (in multiples of 10). + * + * @apiSuccessExample {json} Success-Response: + * HTTP/1.1 200 OK + * { + * "id": 2, + * "title": "html", + * "message": "

My ticket template 

", + * "displayOrder": 10 + * } + * + * @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required + * @apiError (invalidXAuthToken) 401 The `X-Auth-Token` provided was invalid + */ if ($request_method == 'GET') { $token = get_header('X-Auth-Token'); diff --git a/api/admin/ticket/index.php b/api/admin/ticket/index.php index a95fc1fb..f347af43 100644 --- a/api/admin/ticket/index.php +++ b/api/admin/ticket/index.php @@ -25,57 +25,57 @@ $request_method = $_SERVER['REQUEST_METHOD']; * @apiParam {Number} [id] The ID of the ticket. Omit for all tickets. * * @apiSuccess {Number} id ID of the ticket - * @apiSuccess {String} trackid The tracking id of the ticket + * @apiSuccess {String} trackingId The tracking id of the ticket * @apiSuccess {String} name The name of the contact * @apiSuccess {String} email The email address of the ticket (empty string if no email) * @apiSuccess {Integer} category The ID of the category the ticket is in * @apiSuccess {Integer} priority The ID of the priority the ticket is in * @apiSuccess {String} subject The subject of the ticket * @apiSuccess {String} message The original message of the ticket - * @apiSuccess {String} dt The date and time the ticket was submitted, in `YYYY-MM-DD hh:mm:ss` + * @apiSuccess {String} dateCreated The date and time the ticket was submitted, in `YYYY-MM-DD hh:mm:ss` * @apiSuccess {Integer} articles The knowledgebase article IDs suggested when the user created the ticket * @apiSuccess {String} ip The IP address of the submitter * @apiSuccess {String} language The language the ticket was submitted in * @apiSuccess {Integer} status The ID of the status the ticket is set to * @apiSuccess {Integer} owner The user ID of the ticket owner - * @apiSuccess {String} time_worked The total time worked on the ticket, in `hh:mm:ss` + * @apiSuccess {String} timeWorked The total time worked on the ticket, in `hh:mm:ss` * @apiSuccess {Boolean} archive `true` if the ticket is tagged
`false` otherwise * @apiSuccess {Boolean} locked `true` if the ticket is locked
`false` otherwise * @apiSuccess {Binary[]} attachments Array of attachments, in base-64 encoded binary * @apiSuccess {Integer[]} merged Array of merged ticket IDs - * @apiSuccess {String} history HTML markup of the entire "Audit Trail" section + * @apiSuccess {String} legacyAuditTrail HTML markup of the entire "Audit Trail" section * @apiSuccess {String} custom1-20 Custom fields 1-20's values. - * @apiSuccess {Integer} parent The ID of the ticket linked to this ticket + * @apiSuccess {Integer} linkedTo The ID of the ticket linked to this ticket * @apiSuccess {String} latitude The latitudinal coordinate of the user's location, or one of the corresponding error codes. * @apiSuccess {String} longitude The longitudinal coordinate of the user's location, or one of the corresponding error codes. * @apiSuccess {Boolean} html `true` if the ticket was created with HTML encoding
`false` otherwise - * @apiSuccess {String} user_agent The user agent of the user who submitted the ticket - * @apiSuccess {Integer} screen_resolution_width The width of the screen resolution of the user who submitted the ticket - * @apiSuccess {Integer} screen_resolution_height The height of the screen resolution of the user who submitted the ticket + * @apiSuccess {String} userAgent The user agent of the user who submitted the ticket + * @apiSuccess {Integer} screenResolutionWidth The width of the screen resolution of the user who submitted the ticket + * @apiSuccess {Integer} screenResolutionHeight The height of the screen resolution of the user who submitted the ticket * * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * "id": 22, - * "trackid": "EVL-RRL-DUBG", + * "trackingId": "EVL-RRL-DUBG", * "name": "Test", * "email": "", * "category": 1, * "priority": 3, * "subject": "test", * "message": "test", - * "dt": "2014-12-28 00:57:26", + * "dateCreated": "2014-12-28 00:57:26", * "articles": null, * "ip": "127.0.0.1", * "language": null, * "status": 3, * "owner": 1, - * "time_worked": "00:05:07", + * "timeWorked": "00:05:07", * "archive": true, * "locked": true, * "attachments": "", * "merged": "", - * "history": "
  • 2014-12-28 06:57:28 | ticket created by Your name (mkoch)
  • 2014-12-31 21:00:59 | closed by Your name (mkoch)
  • 2014-12-31 21:01:05 | status changed to Waiting reply by Your name (mkoch)
  • 2014-12-31 21:01:58 | closed by Your name (mkoch)
  • 2015-01-17 16:21:18 | closed by Your name (mkoch)
  • 2015-01-17 16:21:31 | closed by Your name (mkoch)
  • 2015-01-17 16:22:05 | closed by Your name (mkoch)
  • 2015-01-17 16:24:06 | status changed to by Your name (mkoch)
  • 2015-01-17 16:25:40 | status changed to On Hold by Your name (mkoch)
  • 2015-01-17 16:25:53 | status changed to In Progress by Your name (mkoch)
  • 2015-01-17 21:39:11 | locked by Your name (mkoch)
  • ", + * "legacyAuditTrail": "
  • 2014-12-28 06:57:28 | ticket created by Your name (username)
  • 2014-12-31 21:00:59 | closed by Your name (username)
  • 2014-12-31 21:01:05 | status changed to Waiting reply by Your name (username)
  • 2014-12-31 21:01:58 | closed by Your name (username)
  • 2015-01-17 16:21:18 | closed by Your name (username)
  • ", * "custom1": "1420671600", * "custom2": "", * "custom3": "", @@ -100,9 +100,9 @@ $request_method = $_SERVER['REQUEST_METHOD']; * "latitude": "E-0", * "longitude": "E-0", * "html": false, - * "user_agent": null, - * "screen_resolution_width": null, - * "screen_resolution_height": null + * "userAgent": null, + * "screenResolutionWidth": null, + * "screenResolutionHeight": null * } * * @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required diff --git a/api/admin/user/index.php b/api/admin/user/index.php index 1c944628..4b980a21 100644 --- a/api/admin/user/index.php +++ b/api/admin/user/index.php @@ -6,7 +6,7 @@ require_once(HESK_PATH . 'hesk_settings.inc.php'); require_once(HESK_PATH . 'inc/common.inc.php'); require_once(API_PATH . 'core/headers.php'); require_once(API_PATH . 'core/output.php'); -require_once(API_PATH . 'dao/user_dao.php'); +require_once(API_PATH . 'businesslogic/user_retriever.php'); require_once(API_PATH . 'businesslogic/security_retriever.php'); hesk_load_api_database_functions(); @@ -15,6 +15,88 @@ hesk_dbConnect(); // Routing $request_method = $_SERVER['REQUEST_METHOD']; +/** + * @api {get} /admin/user Retrieve a helpdesk user + * @apiVersion 0.0.0 + * @apiName GetUser + * @apiGroup User + * @apiPermission protected + * + * @apiParam {Number} [id] The ID of the user. Omit for all users. + * + * @apiSuccess {Number} id ID of the user + * @apiSuccess {String} username The user's username + * @apiSuccess {Boolean} admin `true` if the user is under a permission template that is market as an administrative group
    `false` otherwise + * @apiSuccess {String} name The user's name + * @apiSuccess {String} email The user's email address + * @apiSuccess {String} signature The user's signature, in plaintext + * @apiSuccess {Unknown} language ??? (Unknown) + * @apiSuccess {String[]} categories Ticket categories the user has access to. If the user is an admin, this list has one element: "" + * @apiSuccess {Integer} afterReply Action to perform after replying to a ticket:
    + * `0` - Show the ticket I just replied to
    + * `1` - Return to the main administration page
    + * `2` - Open next ticket that needs my reply + * @apiSuccess {Boolean} autoStart Automatically start timer when the user opens a ticket + * @apiSuccess {Boolean} notifyCustomerNew Select notify customer option in the new ticket form + * @apiSuccess {Boolean} notifyCustomerReply Select notify customer option in the ticket reply form + * @apiSuccess {Boolean} showSuggested Show what knowledgebase articles were suggested to customers + * @apiSuccess {Boolean} notifyNewUnassigned Notify the user when a new ticket is submitted with owner: Unassigned + * @apiSuccess {Boolean} notifyNewMy Notify the user when a new ticket is submitted and is assigned to the user + * @apiSuccess {Boolean} notifyAssigned Notify the user when a ticket is assigned to the user + * @apiSuccess {Boolean} notifyReplyUnassigned Notify the user when the client responds to a ticket with owner: Unassigned + * @apiSuccess {Boolean} notifyReplyMy Notify the user when the client responds to a ticket assigned to the user + * @apiSuccess {Boolean} notifyPm Notify the user when a private message is sent to the user + * @apiSuccess {Boolean} notifyNoteUnassigned Notify the user when someone adds a note to a ticket not assigned to the user + * @apiSuccess {Unknown} defaultList ??? (Currently unknown) + * @apiSuccess {Boolean} autoassign Tickets are auto-assigned to this user + * @apiSuccess {String[]} heskPrivileges Helpdesk features the user has access to. If the user is an admin, this list has one element: "" + * @apiSuccess {Integer} ratingNeg Total number of negative feedback to "Was this reply helpful?" on replies by this user + * @apiSuccess {Integer} ratingPos Total number of positive feedback to "Was this reply helpful?" on replies by this user + * @apiSuccess {String} rating The overall rating of the user, as a floating point decimal + * @apiSuccess {Integer} autorefresh The ticket table autorefresh time for the user, in milliseconds + * @apiSuccess {Boolean} active `true` if the user is active
    `false` otherwise + * + * @apiSuccessExample {json} Success-Response: + * HTTP/1.1 200 OK + * { + * "id": 1, + * "username": "mkoch", + * "admin": true, + * "name": "Your name", + * "email": "mkoch227@gmail.com", + * "signature": "Sincerely,\r\n\r\nYour name\r\nYour website\r\nhttp://www.yourwebsite.com\r\n& < > ^ &", + * "language": null, + * "categories": [ + * "" + * ], + * "afterReply": 0, + * "autoStart": true, + * "notifyCustomerNew": true, + * "notifyCustomerReply": true, + * "showSuggested": true, + * "notifyNewUnassigned": true, + * "notifyNewMy": true, + * "notifyReplyUnassigned": true, + * "notifyReplyMy": true, + * "notifyAssigned": true, + * "notifyPm": false, + * "notifyNote": true, + * "notifyNoteUnassigned": false, + * "defaultList": "", + * "autoassign": true, + * "heskPrivileges": [ + * "" + * ], + * "ratingNeg": 0, + * "ratingPos": 0, + * "rating": "0", + * "autorefresh": 0, + * "active": true + * } + * + * @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required + * @apiError (invalidXAuthToken) 401 The `X-Auth-Token` provided was invalid + */ if ($request_method == 'GET') { $token = get_header('X-Auth-Token'); @@ -25,9 +107,9 @@ if ($request_method == 'GET') { } if (isset($_GET['id'])) { - $results = get_user($hesk_settings, $_GET['id']); + $results = retrieve_user($hesk_settings, $_GET['id']); } else { - $results = get_user($hesk_settings); + $results = retrieve_user($hesk_settings); } if ($results == NULL) { diff --git a/api/businesslogic/ticket_retriever.php b/api/businesslogic/ticket_retriever.php index 59f4ee69..b5165292 100644 --- a/api/businesslogic/ticket_retriever.php +++ b/api/businesslogic/ticket_retriever.php @@ -5,24 +5,16 @@ function get_ticket_for_staff($hesk_settings, $id = NULL) { $tickets = get_ticket_for_id($hesk_settings, $id); if ($id === NULL) { - foreach ($tickets as $ticket) { + $original_tickets = $tickets; + $tickets = []; + foreach ($original_tickets as $ticket) { $ticket = remove_common_properties($ticket); - $ticket['suggestedArticles'] = $ticket['articles']; - unset($ticket['articles']); - $ticket['legacyAuditTrail'] = $ticket['history']; - unset($ticket['history']); - $ticket['linkedTo'] = $ticket['parent']; - unset($ticket['parent']); + $ticket = convert_to_camel_case($ticket); + $tickets[] = $ticket; } } else { $tickets = remove_common_properties($tickets); - - $tickets['suggestedArticles'] = $tickets['articles']; - unset($tickets['articles']); - $tickets['legacyAuditTrail'] = $tickets['history']; - unset($tickets['history']); - $tickets['linkedTo'] = $tickets['parent']; - unset($tickets['parent']); + $tickets = convert_to_camel_case($tickets); } @@ -44,10 +36,36 @@ function remove_common_properties($ticket) { 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']); + + 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; } diff --git a/api/businesslogic/user_retriever.php b/api/businesslogic/user_retriever.php new file mode 100644 index 00000000..ddfa06ed --- /dev/null +++ b/api/businesslogic/user_retriever.php @@ -0,0 +1,73 @@ +`false` otherwise * @apiSuccess {Integer} type `0` - Public
    `1` - Private * @apiSuccess {Integer} priority Default priority of tickets created in this category @@ -35,11 +35,11 @@ $request_method = $_SERVER['REQUEST_METHOD']; * { * "id": 1, * "name": "General", - * "cat_order": 10, + * "displayOrder": 10, * "autoassign": true, * "type": 0, * "priority": 2, - * "manager": 0 + * "manager": null * } */ if ($request_method == 'GET') { diff --git a/api/dao/canned_dao.php b/api/dao/canned_dao.php index ea653942..07725436 100644 --- a/api/dao/canned_dao.php +++ b/api/dao/canned_dao.php @@ -15,7 +15,10 @@ function get_canned_response($hesk_settings, $id = NULL) { $results = []; while ($row = hesk_dbFetchAssoc($response)) { $row['id'] = intval($row['id']); - $row['reply_order'] = intval($row['reply_order']); + + $row['replyOrder'] = intval($row['reply_order']); + unset($row['reply_order']); + $row['title'] = hesk_html_entity_decode($row['title']); $row['message'] = hesk_html_entity_decode($row['message']); $results[] = $row; diff --git a/api/dao/category_dao.php b/api/dao/category_dao.php index 60441e0d..24e0ddf7 100644 --- a/api/dao/category_dao.php +++ b/api/dao/category_dao.php @@ -15,7 +15,8 @@ function get_category($hesk_settings, $id = NULL) { $results = []; while ($row = hesk_dbFetchAssoc($response)) { $row['id'] = intval($row['id']); - $row['cat_order'] = intval($row['cat_order']); + $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']); diff --git a/api/dao/ticket_template_dao.php b/api/dao/ticket_template_dao.php index d31d8aa4..6335378d 100644 --- a/api/dao/ticket_template_dao.php +++ b/api/dao/ticket_template_dao.php @@ -15,7 +15,8 @@ function get_ticket_template($hesk_settings, $id = NULL) { $results = []; while ($row = hesk_dbFetchAssoc($response)) { $row['id'] = intval($row['id']); - $row['tpl_order'] = intval($row['tpl_order']); + $row['displayOrder'] = intval($row['tpl_order']); + unset($row['tpl_order']); $row['title'] = hesk_html_entity_decode($row['title']); $row['message'] = hesk_html_entity_decode($row['message']); $results[] = $row; diff --git a/api/dao/user_dao.php b/api/dao/user_dao.php index c44d8b40..b7bdde12 100644 --- a/api/dao/user_dao.php +++ b/api/dao/user_dao.php @@ -15,10 +15,6 @@ function get_user($hesk_settings, $id = NULL) { $results = []; while ($row = hesk_dbFetchAssoc($response)) { - // Never send back a user's password, even if it is hashed. - unset($row['pass']); - unset($row['permission_template']); - $row['id'] = intval($row['id']); $row['isadmin'] = get_boolean($row['isadmin']); $row['signature'] = hesk_html_entity_decode($row['signature']); diff --git a/api/ticket/index.php b/api/ticket/index.php index 30cf1470..4f48fe32 100644 --- a/api/ticket/index.php +++ b/api/ticket/index.php @@ -45,14 +45,14 @@ $request_method = $_SERVER['REQUEST_METHOD']; * HTTP/1.1 200 OK * { * "id": 22, - * "trackid": "EVL-RRL-DUBG", + * "trackingId": "EVL-RRL-DUBG", * "name": "Test", * "email": "", * "category": 1, * "priority": 3, * "subject": "test", * "message": "test", - * "dt": "2014-12-28 00:57:26", + * "dateCreated": "2014-12-28 00:57:26", * "status": 3, * "archive": true, * "locked": true,