From c241338fbef4c14cb18d81f20fac2fbc883dbeba Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 5 Nov 2017 12:00:41 -0500 Subject: [PATCH 01/20] Couple small QoL changes --- admin/calendar.php | 20 +++++++++++--------- calendar.php | 6 +++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/admin/calendar.php b/admin/calendar.php index a3256299..679bfd21 100644 --- a/admin/calendar.php +++ b/admin/calendar.php @@ -551,16 +551,18 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); +
-

-

-

-

-

-

-

-

-

+
-

\ No newline at end of file From f70c3635a9d30b3440414c59b9c1c9854b443b04 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 29 Nov 2017 21:58:30 -0500 Subject: [PATCH 02/20] Working on moving the calendar API --- api/BusinessLogic/Calendar/AbstractEvent.php | 20 +++ api/BusinessLogic/Calendar/CalendarEvent.php | 21 +++ api/BusinessLogic/Calendar/TicketEvent.php | 18 +++ api/DataAccess/Calendar/CalendarGateway.php | 129 +++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 api/BusinessLogic/Calendar/AbstractEvent.php create mode 100644 api/BusinessLogic/Calendar/CalendarEvent.php create mode 100644 api/BusinessLogic/Calendar/TicketEvent.php create mode 100644 api/DataAccess/Calendar/CalendarGateway.php diff --git a/api/BusinessLogic/Calendar/AbstractEvent.php b/api/BusinessLogic/Calendar/AbstractEvent.php new file mode 100644 index 00000000..5413ef48 --- /dev/null +++ b/api/BusinessLogic/Calendar/AbstractEvent.php @@ -0,0 +1,20 @@ +init(); + + $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')"; + $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')"; + + $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border` "; + + if ($staff) { + $sql .= ",`reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit` "; + } + + $sql .= "FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events` + INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` + ON `events`.`category` = `categories`.`id` "; + + if ($staff) { + $sql .= "LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` AS `reminders` ON + `reminders`.`user_id` = " . intval($_SESSION['id']) . " AND `reminders`.`event_id` = `events`.`id`"; + } + $sql .= "WHERE NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) AND `categories`.`usage` <> 1"; + + if (!$staff) { + $sql .= " AND `categories`.`type` = '0'"; + } + + $rs = hesk_dbQuery($sql); + + $events = array(); + while ($row = hesk_dbFetchAssoc($rs)) { + // Skip the event if the user does not have access to it + // TODO This should be business logic + if ($staff && !$_SESSION['isadmin'] && !in_array($row['category'], $_SESSION['categories'])) { + continue; + } + + $event['type'] = 'CALENDAR'; + $event['id'] = intval($row['id']); + $event['startTime'] = $row['start']; + $event['endTime'] = $row['end']; + $event['allDay'] = $row['all_day'] ? true : false; + $event['title'] = $row['name']; + $event['location'] = $row['location']; + $event['comments'] = $row['comments']; + $event['categoryId'] = $row['category']; + $event['categoryName'] = $row['category_name']; + $event['backgroundColor'] = $row['background_color']; + $event['foregroundColor'] = $row['foreground_color']; + $event['displayBorder'] = $row['display_border']; + + if ($staff) { + $event['reminderValue'] = $row['reminder_value']; + $event['reminderUnits'] = $row['reminder_unit']; + } + + $events[] = $event; + } + + if ($staff) { + $oldTimeSetting = $heskSettings['timeformat']; + $heskSettings['timeformat'] = 'Y-m-d'; + $currentDate = hesk_date(); + $heskSettings['timeformat'] = $oldTimeSetting; + + $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, + CASE WHEN `due_date` < '{$currentDate}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, + `tickets`.`priority` AS `priority` + FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` AS `tickets` + INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` + ON `categories`.`id` = `tickets`.`category` + AND `categories`.`usage` <> 2 + LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner` + ON `tickets`.`owner` = `owner`.`id` + WHERE `due_date` >= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) + . " / 1000), @@session.time_zone, '+00:00') + AND `due_date` <= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00') + AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) "; + + $rs = hesk_dbQuery($sql); + while ($row = hesk_dbFetchAssoc($rs)) { + // Skip the ticket if the user does not have access to it + if (!hesk_checkPermission('can_view_tickets', 0) + || ($row['owner_id'] && $row['owner_id'] != $_SESSION['id'] && !hesk_checkPermission('can_view_ass_others', 0)) + || (!$row['owner_id'] && !hesk_checkPermission('can_view_unassigned', 0))) { + continue; + } + + $event['type'] = 'TICKET'; + $event['trackingId'] = $row['trackid']; + $event['subject'] = $row['subject']; + $event['title'] = $row['subject']; + $event['startTime'] = $row['due_date']; + $event['url'] = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; + $event['categoryId'] = $row['category']; + $event['categoryName'] = $row['category_name']; + $event['backgroundColor'] = $row['background_color']; + $event['foregroundColor'] = $row['foreground_color']; + $event['displayBorder'] = $row['display_border']; + $event['owner'] = $row['owner_name']; + $event['priority'] = $row['priority']; + + $events[] = $event; + } + } + + $this->close(); + + return $events; + } +} \ No newline at end of file From 5ee4ed5864d9147e3e923d0959c6884f930fb668 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 6 Dec 2017 21:37:42 -0500 Subject: [PATCH 03/20] revert meeee --- api/BusinessLogic/Calendar/CalendarEvent.php | 2 + .../Calendar/SearchEventsFilter.php | 21 ++ api/BusinessLogic/Security/UserContext.php | 4 + api/BusinessLogic/Security/UserPrivilege.php | 2 + api/DataAccess/Calendar/CalendarGateway.php | 209 ++++++++++++------ 5 files changed, 171 insertions(+), 67 deletions(-) create mode 100644 api/BusinessLogic/Calendar/SearchEventsFilter.php diff --git a/api/BusinessLogic/Calendar/CalendarEvent.php b/api/BusinessLogic/Calendar/CalendarEvent.php index 91a45761..893cbccb 100644 --- a/api/BusinessLogic/Calendar/CalendarEvent.php +++ b/api/BusinessLogic/Calendar/CalendarEvent.php @@ -4,6 +4,8 @@ namespace BusinessLogic\Calendar; class CalendarEvent extends AbstractEvent { + public $id; + public $type = 'CALENDAR'; public $endTime; diff --git a/api/BusinessLogic/Calendar/SearchEventsFilter.php b/api/BusinessLogic/Calendar/SearchEventsFilter.php new file mode 100644 index 00000000..1a509f9f --- /dev/null +++ b/api/BusinessLogic/Calendar/SearchEventsFilter.php @@ -0,0 +1,21 @@ +username === "API - ANONYMOUS USER"; + } + static function buildAnonymousUser() { $userContext = new UserContext(); $userContext->id = -1; diff --git a/api/BusinessLogic/Security/UserPrivilege.php b/api/BusinessLogic/Security/UserPrivilege.php index 353e8e43..0d68418f 100644 --- a/api/BusinessLogic/Security/UserPrivilege.php +++ b/api/BusinessLogic/Security/UserPrivilege.php @@ -15,4 +15,6 @@ class UserPrivilege extends \BaseClass { const CAN_EDIT_TICKETS = 'can_edit_tickets'; const CAN_DELETE_TICKETS = 'can_del_tickets'; const CAN_MANAGE_CATEGORIES = 'can_man_cat'; + const CAN_VIEW_ASSIGNED_TO_OTHER = 'can_view_ass_others'; + const CAN_VIEW_UNASSIGNED = 'can_view_unassigned'; } \ No newline at end of file diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 8327808b..5fea19a3 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -3,84 +3,159 @@ namespace DataAccess\Calendar; +use BusinessLogic\Calendar\CalendarEvent; +use BusinessLogic\Calendar\SearchEventsFilter; +use BusinessLogic\Calendar\TicketEvent; use BusinessLogic\Security\UserContext; +use BusinessLogic\Security\UserPrivilege; use DataAccess\CommonDao; class CalendarGateway extends CommonDao { - /** * @param $startTime int * @param $endTime int - * @param $userContext UserContext + * @param $searchEventsFilter SearchEventsFilter * @param $heskSettings array - * @return array */ - public function getEventsForStaff($startTime, $endTime, $userContext, $heskSettings) { + public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { $this->init(); $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')"; $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')"; - $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, - `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border` "; - - if ($staff) { - $sql .= ",`reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit` "; + // EVENTS + $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, + `reminders`.`amount` AS `reminder_value`, `reminder`.`unit` AS `reminder_unit` + FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events` + INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` + ON `events`.`category` = `categories`.`id` + LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` AS `reminders` + ON `reminders`.`user_id` = " . intval($searchEventsFilter->reminderUserId) . " + AND `reminders`.`event_id` = `events`.`id` + WHERE NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) + AND `categories`.`usage` <> 1 + AND `categories`.`type` = '0'"; + + if (!empty($searchEventsFilter->categories)) { + $categoriesAsString = implode(',', $searchEventsFilter->categories); + $sql .= " AND `events`.`category` IN (" . $categoriesAsString . ")"; } - $sql .= "FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events` - INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` - ON `events`.`category` = `categories`.`id` "; + $rs = hesk_dbQuery($sql); + while ($row = hesk_dbFetchAssoc($rs)) { + $event = new CalendarEvent(); + $event->id = intval($row['id']); + $event->startTime = $row['start']; + $event->endTime = $row['end']; + $event->allDay = $row['all_day'] ? true : false; + $event->title = $row['name']; + $event->location = $row['location']; + $event->comments = $row['comments']; + $event->categoryId = $row['category']; + $event->categoryName = $row['category_name']; + $event->backgroundColor = $row['background_color']; + $event->foregroundColor = $row['foreground_color']; + $event->displayBorder = $row['display_border']; + $event->reminderValue = $row['reminder_value']; + $event->reminderUnits = $row['reminder_unit']; - if ($staff) { - $sql .= "LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` AS `reminders` ON - `reminders`.`user_id` = " . intval($_SESSION['id']) . " AND `reminders`.`event_id` = `events`.`id`"; + $events[] = $event; } - $sql .= "WHERE NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) AND `categories`.`usage` <> 1"; - if (!$staff) { - $sql .= " AND `categories`.`type` = '0'"; + // TICKETS + if ($searchEventsFilter->includeTickets) { + $oldTimeSetting = $heskSettings['timeformat']; + $heskSettings['timeformat'] = 'Y-m-d'; + $currentDate = hesk_date(); + $heskSettings['timeformat'] = $oldTimeSetting; + + $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, + CASE WHEN `due_date` < '{$currentDate}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, + `tickets`.`priority` AS `priority` + FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` AS `tickets` + INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` + ON `categories`.`id` = `tickets`.`category` + AND `categories`.`usage` <> 2 + LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner` + ON `tickets`.`owner` = `owner`.`id` + WHERE `due_date` >= {$startTimeSql}) + AND `due_date` <= {$endTimeSql}) + AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) + AND (`owner` = " . $searchEventsFilter->reminderUserId; + + if ($searchEventsFilter->includeUnassignedTickets) { + $sql .= ""; + } + + $sql .= ")"; } + $this->close(); + } + + /** + * @param $startTime int + * @param $endTime int + * @param $userContext UserContext + * @param $heskSettings array + * @return array + */ + public function getXXEventsForStaff($startTime, $endTime, $userContext, $heskSettings) { + $this->init(); + + $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')"; + $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')"; + + $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, + `reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit` + FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events` + INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` + ON `events`.`category` = `categories`.`id` + LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` AS `reminders` + ON `reminders`.`user_id` = " . intval($userContext->id) . " + AND `reminders`.`event_id` = `events`.`id` + WHERE NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) + AND `categories`.`usage` <> 1 + AND `categories`.`type` = '0'"; + $rs = hesk_dbQuery($sql); $events = array(); while ($row = hesk_dbFetchAssoc($rs)) { // Skip the event if the user does not have access to it // TODO This should be business logic - if ($staff && !$_SESSION['isadmin'] && !in_array($row['category'], $_SESSION['categories'])) { + if (!$userContext->admin && in_array($row['category'], $userContext->categories)) { continue; } - $event['type'] = 'CALENDAR'; - $event['id'] = intval($row['id']); - $event['startTime'] = $row['start']; - $event['endTime'] = $row['end']; - $event['allDay'] = $row['all_day'] ? true : false; - $event['title'] = $row['name']; - $event['location'] = $row['location']; - $event['comments'] = $row['comments']; - $event['categoryId'] = $row['category']; - $event['categoryName'] = $row['category_name']; - $event['backgroundColor'] = $row['background_color']; - $event['foregroundColor'] = $row['foreground_color']; - $event['displayBorder'] = $row['display_border']; - - if ($staff) { - $event['reminderValue'] = $row['reminder_value']; - $event['reminderUnits'] = $row['reminder_unit']; - } + $event = new CalendarEvent(); + $event->id = intval($row['id']); + $event->startTime = $row['start']; + $event->endTime = $row['end']; + $event->allDay = $row['all_day'] ? true : false; + $event->title = $row['name']; + $event->location = $row['location']; + $event->comments = $row['comments']; + $event->categoryId = $row['category']; + $event->categoryName = $row['category_name']; + $event->backgroundColor = $row['background_color']; + $event->foregroundColor = $row['foreground_color']; + $event->displayBorder = $row['display_border']; + $event->reminderValue = $row['reminder_value']; + $event->reminderUnits = $row['reminder_unit']; $events[] = $event; } - if ($staff) { - $oldTimeSetting = $heskSettings['timeformat']; - $heskSettings['timeformat'] = 'Y-m-d'; - $currentDate = hesk_date(); - $heskSettings['timeformat'] = $oldTimeSetting; + $oldTimeSetting = $heskSettings['timeformat']; + $heskSettings['timeformat'] = 'Y-m-d'; + $currentDate = hesk_date(); + $heskSettings['timeformat'] = $oldTimeSetting; - $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, CASE WHEN `due_date` < '{$currentDate}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, `tickets`.`priority` AS `priority` @@ -95,31 +170,31 @@ class CalendarGateway extends CommonDao { AND `due_date` <= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00') AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) "; - $rs = hesk_dbQuery($sql); - while ($row = hesk_dbFetchAssoc($rs)) { - // Skip the ticket if the user does not have access to it - if (!hesk_checkPermission('can_view_tickets', 0) - || ($row['owner_id'] && $row['owner_id'] != $_SESSION['id'] && !hesk_checkPermission('can_view_ass_others', 0)) - || (!$row['owner_id'] && !hesk_checkPermission('can_view_unassigned', 0))) { - continue; - } - - $event['type'] = 'TICKET'; - $event['trackingId'] = $row['trackid']; - $event['subject'] = $row['subject']; - $event['title'] = $row['subject']; - $event['startTime'] = $row['due_date']; - $event['url'] = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; - $event['categoryId'] = $row['category']; - $event['categoryName'] = $row['category_name']; - $event['backgroundColor'] = $row['background_color']; - $event['foregroundColor'] = $row['foreground_color']; - $event['displayBorder'] = $row['display_border']; - $event['owner'] = $row['owner_name']; - $event['priority'] = $row['priority']; - - $events[] = $event; + $rs = hesk_dbQuery($sql); + while ($row = hesk_dbFetchAssoc($rs)) { + // Skip the ticket if the user does not have access to it + // TODO Move to Business logic + if (!in_array(UserPrivilege::CAN_VIEW_TICKETS, $userContext->permissions) + || ($row['owner_id'] && $row['owner_id'] != $userContext->id && !in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions)) + || (!$row['owner_id']) && !in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions)) { + continue; } + + $event = new TicketEvent(); + $event->trackingId = $row['trackid']; + $event->subject = $row['subject']; + $event->title = $row['subject']; + $event->startTime = $row['due_date']; + $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; + $event->categoryId = $row['category']; + $event->categoryName = $row['category_name']; + $event->backgroundColor = $row['background_color']; + $event->foregroundColor = $row['foreground_color']; + $event->displayBorder = $row['display_border']; + $event->owner = $row['owner_name']; + $event->priority = $row['priority']; + + $events[] = $event; } $this->close(); From 13161696ae30f3b207d190a3c323add9a44aca10 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 10 Dec 2017 22:01:18 -0500 Subject: [PATCH 04/20] Working on refactoring the calendar API --- .../Calendar/CalendarHandler.php | 18 +++++++++++ .../Calendar/CalendarController.php | 23 ++++++++++++++ api/DataAccess/Calendar/CalendarGateway.php | 30 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 api/BusinessLogic/Calendar/CalendarHandler.php create mode 100644 api/Controllers/Calendar/CalendarController.php diff --git a/api/BusinessLogic/Calendar/CalendarHandler.php b/api/BusinessLogic/Calendar/CalendarHandler.php new file mode 100644 index 00000000..f3374279 --- /dev/null +++ b/api/BusinessLogic/Calendar/CalendarHandler.php @@ -0,0 +1,18 @@ +calendarGateway = $calendarGateway; + } + + public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { + return $this->calendarGateway->getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings); + } +} \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php new file mode 100644 index 00000000..60a57b79 --- /dev/null +++ b/api/Controllers/Calendar/CalendarController.php @@ -0,0 +1,23 @@ +get(CalendarHandler::clazz()); + + $events = $calendarHandler->getEventsForStaff($startTime, $endTime, new SearchEventsFilter(), $hesk_settings); + + return output($events); + } +} \ No newline at end of file diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 5fea19a3..b3ae4b92 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -86,10 +86,38 @@ class CalendarGateway extends CommonDao { AND (`owner` = " . $searchEventsFilter->reminderUserId; if ($searchEventsFilter->includeUnassignedTickets) { - $sql .= ""; + $sql .= " OR `owner` = 0 "; + } + + if ($searchEventsFilter->includeTicketsAssignedToOthers) { + $sql .= " OR `owner` NOT IN (0, " . $searchEventsFilter->reminderUserId . ") "; } $sql .= ")"; + + if (!empty($searchEventsFilter->categories)) { + $categoriesAsString = implode(',', $searchEventsFilter->categories); + $sql .= " AND `events`.`category` IN (" . $categoriesAsString . ")"; + } + + $rs = hesk_dbQuery($sql); + while ($row = hesk_dbFetchAssoc($rs)) { + $event = new TicketEvent(); + $event->trackingId = $row['trackid']; + $event->subject = $row['subject']; + $event->title = $row['subject']; + $event->startTime = $row['due_date']; + $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; + $event->categoryId = $row['category']; + $event->categoryName = $row['category_name']; + $event->backgroundColor = $row['background_color']; + $event->foregroundColor = $row['foreground_color']; + $event->displayBorder = $row['display_border']; + $event->owner = $row['owner_name']; + $event->priority = $row['priority']; + + $events[] = $event; + } } $this->close(); From 814523ba6e21999ca8f2978dde9907228696fe95 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 17 Dec 2017 22:05:32 -0500 Subject: [PATCH 05/20] getEventsForStaff endpoint appears to be working --- api/BusinessLogic/Calendar/ReminderUnit.php | 26 +++++++++++++++++ .../Calendar/CalendarController.php | 26 ++++++++++++++--- api/Core/Constants/Priority.php | 15 ++++++++++ api/DataAccess/Calendar/CalendarGateway.php | 28 +++++++++++-------- api/index.php | 2 ++ 5 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 api/BusinessLogic/Calendar/ReminderUnit.php diff --git a/api/BusinessLogic/Calendar/ReminderUnit.php b/api/BusinessLogic/Calendar/ReminderUnit.php new file mode 100644 index 00000000..866ad8e9 --- /dev/null +++ b/api/BusinessLogic/Calendar/ReminderUnit.php @@ -0,0 +1,26 @@ +errorKeys = array('START_AND_END_TIMES_REQUIRED'); + throw new ValidationException($validationModel); + } + + $startTime = $_GET['start']; + $endTime = $_GET['end']; /* @var $calendarHandler CalendarHandler */ $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); - $events = $calendarHandler->getEventsForStaff($startTime, $endTime, new SearchEventsFilter(), $hesk_settings); + $searchEventsFilter = new SearchEventsFilter(); + $searchEventsFilter->reminderUserId = $userContext->id; + $searchEventsFilter->includeTicketsAssignedToOthers = in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions); + $searchEventsFilter->includeUnassignedTickets = in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions); + $searchEventsFilter->includeTickets = true; + $searchEventsFilter->categories = $userContext->admin ? null : $userContext->categories; + + $events = $calendarHandler->getEventsForStaff($startTime, $endTime, $searchEventsFilter, $hesk_settings); return output($events); } diff --git a/api/Core/Constants/Priority.php b/api/Core/Constants/Priority.php index 39b86313..de361ab3 100644 --- a/api/Core/Constants/Priority.php +++ b/api/Core/Constants/Priority.php @@ -8,4 +8,19 @@ class Priority extends \BaseClass { const HIGH = 1; const MEDIUM = 2; const LOW = 3; + + static function getByValue($value) { + switch ($value) { + case self::CRITICAL: + return 'CRITICAL'; + case self::HIGH: + return 'HIGH'; + case self::MEDIUM: + return 'MEDIUM'; + case self::LOW: + return 'LOW'; + default: + return 'UNKNOWN'; + } + } } \ No newline at end of file diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index b3ae4b92..dc724a73 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -4,10 +4,12 @@ namespace DataAccess\Calendar; use BusinessLogic\Calendar\CalendarEvent; +use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Calendar\TicketEvent; use BusinessLogic\Security\UserContext; use BusinessLogic\Security\UserPrivilege; +use Core\Constants\Priority; use DataAccess\CommonDao; class CalendarGateway extends CommonDao { @@ -20,13 +22,15 @@ class CalendarGateway extends CommonDao { public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { $this->init(); + $events = array(); + $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')"; $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')"; // EVENTS $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, - `reminders`.`amount` AS `reminder_value`, `reminder`.`unit` AS `reminder_unit` + `reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events` INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` ON `events`.`category` = `categories`.`id` @@ -52,13 +56,13 @@ class CalendarGateway extends CommonDao { $event->title = $row['name']; $event->location = $row['location']; $event->comments = $row['comments']; - $event->categoryId = $row['category']; + $event->categoryId = intval($row['category']); $event->categoryName = $row['category_name']; $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border']; - $event->reminderValue = $row['reminder_value']; - $event->reminderUnits = $row['reminder_unit']; + $event->displayBorder = $row['display_border'] === '1'; + $event->reminderValue = $row['reminder_value'] === null ? null : floatval($row['reminder_value']); + $event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']); $events[] = $event; } @@ -80,8 +84,8 @@ class CalendarGateway extends CommonDao { AND `categories`.`usage` <> 2 LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner` ON `tickets`.`owner` = `owner`.`id` - WHERE `due_date` >= {$startTimeSql}) - AND `due_date` <= {$endTimeSql}) + WHERE `due_date` >= {$startTimeSql} + AND `due_date` <= {$endTimeSql} AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) AND (`owner` = " . $searchEventsFilter->reminderUserId; @@ -107,20 +111,22 @@ class CalendarGateway extends CommonDao { $event->subject = $row['subject']; $event->title = $row['subject']; $event->startTime = $row['due_date']; - $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; - $event->categoryId = $row['category']; + $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event->trackingId; + $event->categoryId = intval($row['category']); $event->categoryName = $row['category_name']; $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border']; + $event->displayBorder = $row['display_border'] === '0'; $event->owner = $row['owner_name']; - $event->priority = $row['priority']; + $event->priority = Priority::getByValue($row['priority']); $events[] = $event; } } $this->close(); + + return $events; } /** diff --git a/api/index.php b/api/index.php index 4766701c..9e617185 100644 --- a/api/index.php +++ b/api/index.php @@ -202,6 +202,8 @@ Link::all(array( '/v1/statuses' => action(\Controllers\Statuses\StatusController::clazz(), RequestMethod::all()), // Settings '/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()), + // Calendar + '/v1/calendar/events/staff' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), /* Internal use only routes */ // Resend email response From 9eab1525ef9202fddb6d899ec9aa1fb82fb25831 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 21 Dec 2017 22:10:45 -0500 Subject: [PATCH 06/20] Getting started on moving the update event endpoint --- api/DataAccess/Calendar/CalendarGateway.php | 113 +------------------- api/index.php | 1 + js/calendar/mods-for-hesk-calendar.js | 5 +- 3 files changed, 7 insertions(+), 112 deletions(-) diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index dc724a73..558e4113 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -3,12 +3,11 @@ namespace DataAccess\Calendar; +use BusinessLogic\Calendar\AbstractEvent; use BusinessLogic\Calendar\CalendarEvent; use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Calendar\TicketEvent; -use BusinessLogic\Security\UserContext; -use BusinessLogic\Security\UserPrivilege; use Core\Constants\Priority; use DataAccess\CommonDao; @@ -18,6 +17,7 @@ class CalendarGateway extends CommonDao { * @param $endTime int * @param $searchEventsFilter SearchEventsFilter * @param $heskSettings array + * @return AbstractEvent[] */ public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { $this->init(); @@ -101,7 +101,7 @@ class CalendarGateway extends CommonDao { if (!empty($searchEventsFilter->categories)) { $categoriesAsString = implode(',', $searchEventsFilter->categories); - $sql .= " AND `events`.`category` IN (" . $categoriesAsString . ")"; + $sql .= " AND `tickets`.`category` IN (" . $categoriesAsString . ")"; } $rs = hesk_dbQuery($sql); @@ -128,111 +128,4 @@ class CalendarGateway extends CommonDao { return $events; } - - /** - * @param $startTime int - * @param $endTime int - * @param $userContext UserContext - * @param $heskSettings array - * @return array - */ - public function getXXEventsForStaff($startTime, $endTime, $userContext, $heskSettings) { - $this->init(); - - $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')"; - $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')"; - - $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, - `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, - `reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit` - FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events` - INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` - ON `events`.`category` = `categories`.`id` - LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` AS `reminders` - ON `reminders`.`user_id` = " . intval($userContext->id) . " - AND `reminders`.`event_id` = `events`.`id` - WHERE NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) - AND `categories`.`usage` <> 1 - AND `categories`.`type` = '0'"; - - $rs = hesk_dbQuery($sql); - - $events = array(); - while ($row = hesk_dbFetchAssoc($rs)) { - // Skip the event if the user does not have access to it - // TODO This should be business logic - if (!$userContext->admin && in_array($row['category'], $userContext->categories)) { - continue; - } - - $event = new CalendarEvent(); - $event->id = intval($row['id']); - $event->startTime = $row['start']; - $event->endTime = $row['end']; - $event->allDay = $row['all_day'] ? true : false; - $event->title = $row['name']; - $event->location = $row['location']; - $event->comments = $row['comments']; - $event->categoryId = $row['category']; - $event->categoryName = $row['category_name']; - $event->backgroundColor = $row['background_color']; - $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border']; - $event->reminderValue = $row['reminder_value']; - $event->reminderUnits = $row['reminder_unit']; - - $events[] = $event; - } - - $oldTimeSetting = $heskSettings['timeformat']; - $heskSettings['timeformat'] = 'Y-m-d'; - $currentDate = hesk_date(); - $heskSettings['timeformat'] = $oldTimeSetting; - - $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, - `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, - CASE WHEN `due_date` < '{$currentDate}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, - `tickets`.`priority` AS `priority` - FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` AS `tickets` - INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` - ON `categories`.`id` = `tickets`.`category` - AND `categories`.`usage` <> 2 - LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner` - ON `tickets`.`owner` = `owner`.`id` - WHERE `due_date` >= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) - . " / 1000), @@session.time_zone, '+00:00') - AND `due_date` <= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00') - AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) "; - - $rs = hesk_dbQuery($sql); - while ($row = hesk_dbFetchAssoc($rs)) { - // Skip the ticket if the user does not have access to it - // TODO Move to Business logic - if (!in_array(UserPrivilege::CAN_VIEW_TICKETS, $userContext->permissions) - || ($row['owner_id'] && $row['owner_id'] != $userContext->id && !in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions)) - || (!$row['owner_id']) && !in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions)) { - continue; - } - - $event = new TicketEvent(); - $event->trackingId = $row['trackid']; - $event->subject = $row['subject']; - $event->title = $row['subject']; - $event->startTime = $row['due_date']; - $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; - $event->categoryId = $row['category']; - $event->categoryName = $row['category_name']; - $event->backgroundColor = $row['background_color']; - $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border']; - $event->owner = $row['owner_name']; - $event->priority = $row['priority']; - - $events[] = $event; - } - - $this->close(); - - return $events; - } } \ No newline at end of file diff --git a/api/index.php b/api/index.php index 9e617185..d833c236 100644 --- a/api/index.php +++ b/api/index.php @@ -204,6 +204,7 @@ Link::all(array( '/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()), // Calendar '/v1/calendar/events/staff' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), + '/v1/calendar/events/staff/{i}' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::PUT), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), /* Internal use only routes */ // Resend email response diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 97c4fc7b..88197f4f 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -16,9 +16,10 @@ $(document).ready(function() { defaultView: $('#setting_default_view').text().trim(), events: function(start, end, timezone, callback) { $.ajax({ - url: heskPath + 'internal-api/admin/calendar/?start=' + start + '&end=' + end, + url: heskPath + 'api/v1/calendar/events/staff?start=' + start + '&end=' + end, method: 'GET', dataType: 'json', + headers: { 'X-Internal-Call': true }, success: function(data) { var events = []; $(data).each(function() { @@ -90,7 +91,7 @@ $(document).ready(function() { var $eventMarkup = $(this); var eventTitle = event.title; - if (event.fontIconMarkup != undefined) { + if (event.fontIconMarkup !== undefined) { eventTitle = event.fontIconMarkup + ' ' + eventTitle; } From c805fd8eab2ffc13eea3cbc8138d666bf0d0f964 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sat, 23 Dec 2017 22:04:52 -0500 Subject: [PATCH 07/20] Working on new update event endpoint --- .../Calendar/CalendarHandler.php | 4 +++ api/BusinessLogic/Calendar/ReminderUnit.php | 15 ++++++++ .../Calendar/CalendarController.php | 36 +++++++++++++++++++ api/DataAccess/Calendar/CalendarGateway.php | 29 +++++++++++++++ internal-api/dao/calendar_dao.php | 23 ------------ 5 files changed, 84 insertions(+), 23 deletions(-) diff --git a/api/BusinessLogic/Calendar/CalendarHandler.php b/api/BusinessLogic/Calendar/CalendarHandler.php index f3374279..7f327997 100644 --- a/api/BusinessLogic/Calendar/CalendarHandler.php +++ b/api/BusinessLogic/Calendar/CalendarHandler.php @@ -15,4 +15,8 @@ class CalendarHandler extends \BaseClass { public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { return $this->calendarGateway->getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings); } + + public function updateEvent($calendarEvent, $userContext, $heskSettings) { + $this->calendarGateway->updateEvent($calendarEvent, $userContext, $heskSettings); + } } \ No newline at end of file diff --git a/api/BusinessLogic/Calendar/ReminderUnit.php b/api/BusinessLogic/Calendar/ReminderUnit.php index 866ad8e9..e45b2169 100644 --- a/api/BusinessLogic/Calendar/ReminderUnit.php +++ b/api/BusinessLogic/Calendar/ReminderUnit.php @@ -23,4 +23,19 @@ class ReminderUnit { return 'UNKNOWN'; } } + + static function getByName($name) { + switch ($name) { + case 'MINUTE': + return self::MINUTE; + case 'HOUR': + return self::HOUR; + case 'DAY': + return self::DAY; + case 'WEEK': + return self::WEEK; + default: + return null; + } + } } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index 6a9a6861..1a180fc1 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -3,12 +3,16 @@ namespace Controllers\Calendar; +use BusinessLogic\Calendar\CalendarEvent; use BusinessLogic\Calendar\CalendarHandler; +use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Exceptions\ValidationException; +use BusinessLogic\Helpers; use BusinessLogic\Security\UserContext; use BusinessLogic\Security\UserPrivilege; use BusinessLogic\ValidationModel; +use Controllers\JsonRetriever; class CalendarController extends \BaseClass { function get() { @@ -38,4 +42,36 @@ class CalendarController extends \BaseClass { return output($events); } + + function put($id) { + /* @var $userContext UserContext */ + global $applicationContext, $hesk_settings, $userContext; + + $json = JsonRetriever::getJsonData(); + + $event = $this->transformJson($json); + + /* @var $calendarHandler CalendarHandler */ + $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); + + return output($calendarHandler->updateEvent($event, $userContext, $hesk_settings)); + } + + private function transformJson($json, $creating = false) { + $event = new CalendarEvent(); + + if ($creating) { + $event->id = Helpers::safeArrayGet($json, 'id'); + } + + $event->startTime = date('Y-m-d H:i:s', Helpers::safeArrayGet($json, 'startTime')); + $event->endTime = date('Y-m-d H:i:s', Helpers::safeArrayGet($json, 'endTime')); + $event->allDay = Helpers::safeArrayGet($json, 'allDay') === 'true'; + $event->title = Helpers::safeArrayGet($json, 'title'); + $event->location = Helpers::safeArrayGet($json, 'location'); + $event->comments = Helpers::safeArrayGet($json, 'comments'); + $event->categoryId = Helpers::safeArrayGet($json, 'categoryId'); + $event->reminderValue = Helpers::safeArrayGet($json, 'reminderValue'); + $event->reminderUnits = ReminderUnit::getByName(Helpers::safeArrayGet($json, 'reminderUnits')); + } } \ No newline at end of file diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 558e4113..9367dbb7 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -8,6 +8,7 @@ use BusinessLogic\Calendar\CalendarEvent; use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Calendar\TicketEvent; +use BusinessLogic\Security\UserContext; use Core\Constants\Priority; use DataAccess\CommonDao; @@ -128,4 +129,32 @@ class CalendarGateway extends CommonDao { return $events; } + + /** + * @param $event CalendarEvent + * @param $userContext UserContext + * @param $heskSettings array + */ + public function updateEvent($event, $userContext, $heskSettings) { + $this->init(); + + $sql = "UPDATE `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` SET `start` = '" . hesk_dbEscape($event->startTime) + . "', `end` = '" . hesk_dbEscape($event->endTime) . "', `all_day` = '" . ($event->allDay ? 1 : 0) . "', `name` = '" + . hesk_dbEscape(addslashes($event->title)) . "', `location` = '" . hesk_dbEscape(addslashes($event->location)) . "', `comments` = '" + . hesk_dbEscape(addslashes($event->comments)) . "', `category` = " . intval($event->categoryId) . " WHERE `id` = " . intval($event->id); + + if ($event->reminderValue != null) { + $delete_sql = "DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` WHERE `event_id` = " . intval($event->id) + . " AND `user_id` = " . intval($userContext->id); + hesk_dbQuery($delete_sql); + $insert_sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`, + `amount`, `unit`) VALUES (" . intval($userContext->id) . ", " . intval($event->id) . ", " . intval($event->reminderValue) . ", + " . intval($event->reminderUnits) . ")"; + hesk_dbQuery($insert_sql); + } + + hesk_dbQuery($sql); + + $this->close(); + } } \ No newline at end of file diff --git a/internal-api/dao/calendar_dao.php b/internal-api/dao/calendar_dao.php index a3f15d98..3ad28dbf 100644 --- a/internal-api/dao/calendar_dao.php +++ b/internal-api/dao/calendar_dao.php @@ -154,30 +154,7 @@ function update_event($event, $hesk_settings) { print_error('Access Denied', 'You cannot edit an event in this category'); } - $event['start'] = date('Y-m-d H:i:s', strtotime($event['start'])); - $event['end'] = date('Y-m-d H:i:s', strtotime($event['end'])); - if ($event['create_ticket_date'] != null) { - $event['create_ticket_date'] = date('Y-m-d H:i:s', strtotime($event['create_ticket_date'])); - } - $event['all_day'] = $event['all_day'] ? 1 : 0; - $event['assign_to'] = $event['assign_to'] != null ? intval($event['assign_to']) : 'NULL'; - - $sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` SET `start` = '" . hesk_dbEscape($event['start']) - . "', `end` = '" . hesk_dbEscape($event['end']) . "', `all_day` = '" . hesk_dbEscape($event['all_day']) . "', `name` = '" - . hesk_dbEscape(addslashes($event['title'])) . "', `location` = '" . hesk_dbEscape(addslashes($event['location'])) . "', `comments` = '" - . hesk_dbEscape(addslashes($event['comments'])) . "', `category` = " . intval($event['category']) . " WHERE `id` = " . intval($event['id']); - if ($event['reminder_amount'] != null) { - $delete_sql = "DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` WHERE `event_id` = " . intval($event['id']) - . " AND `user_id` = " . intval($event['reminder_user']); - hesk_dbQuery($delete_sql); - $insert_sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`, - `amount`, `unit`) VALUES (" . intval($event['reminder_user']) . ", " . intval($event['id']) . ", " . intval($event['reminder_amount']) . ", - " . intval($event['reminder_units']) . ")"; - hesk_dbQuery($insert_sql); - } - - hesk_dbQuery($sql); } function delete_event($id, $hesk_settings) { From 86f1fb3ca23232259e92eea6fa998027868ec114 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 27 Dec 2017 22:00:30 -0500 Subject: [PATCH 08/20] Slowly working on moving more API endpoints --- admin/calendar.php | 16 +++--- .../Calendar/CalendarHandler.php | 31 ++++++++++- .../Calendar/SearchEventsFilter.php | 9 ++++ api/BusinessLogic/Tickets/TicketEditor.php | 21 ++++++++ .../Calendar/CalendarController.php | 33 ++++++++---- .../Tickets/StaffTicketController.php | 11 ++++ api/DataAccess/Calendar/CalendarGateway.php | 51 ++++++++++++++++--- api/index.php | 2 +- js/calendar/mods-for-hesk-calendar.js | 20 +++++--- 9 files changed, 157 insertions(+), 37 deletions(-) diff --git a/admin/calendar.php b/admin/calendar.php index 679bfd21..905cc81d 100644 --- a/admin/calendar.php +++ b/admin/calendar.php @@ -282,10 +282,10 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
@@ -453,10 +453,10 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
diff --git a/api/BusinessLogic/Calendar/CalendarHandler.php b/api/BusinessLogic/Calendar/CalendarHandler.php index 7f327997..5347eaf1 100644 --- a/api/BusinessLogic/Calendar/CalendarHandler.php +++ b/api/BusinessLogic/Calendar/CalendarHandler.php @@ -3,7 +3,10 @@ namespace BusinessLogic\Calendar; +use BusinessLogic\Exceptions\ApiFriendlyException; +use BusinessLogic\Security\UserContext; use DataAccess\Calendar\CalendarGateway; +use PHPUnit\Runner\Exception; class CalendarHandler extends \BaseClass { private $calendarGateway; @@ -12,11 +15,35 @@ class CalendarHandler extends \BaseClass { $this->calendarGateway = $calendarGateway; } - public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { - return $this->calendarGateway->getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings); + public function getEventsForStaff($searchEventsFilter, $heskSettings) { + return $this->calendarGateway->getEventsForStaff($searchEventsFilter, $heskSettings); } + /** + * @param $calendarEvent CalendarEvent + * @param $userContext UserContext + * @param $heskSettings array + * @return CalendarEvent + * @throws \Exception If more than one event is returned for the given ID + */ public function updateEvent($calendarEvent, $userContext, $heskSettings) { $this->calendarGateway->updateEvent($calendarEvent, $userContext, $heskSettings); + + $eventFilter = new SearchEventsFilter(); + $eventFilter->eventId = $calendarEvent->id; + $eventFilter->reminderUserId = $userContext->id; + + $events = $this->calendarGateway->getEventsForStaff($eventFilter, $heskSettings); + + if (count($events) !== 1) { + throw new \Exception("Expected exactly 1 event, found: " . count($events)); + } + + return $events[0]; + } + + + public function createEvent($calendarEvent, $userContext, $heskSettings) { + return $this->calendarGateway->createEvent($calendarEvent, $userContext, $heskSettings); } } \ No newline at end of file diff --git a/api/BusinessLogic/Calendar/SearchEventsFilter.php b/api/BusinessLogic/Calendar/SearchEventsFilter.php index 1a509f9f..72e31b3d 100644 --- a/api/BusinessLogic/Calendar/SearchEventsFilter.php +++ b/api/BusinessLogic/Calendar/SearchEventsFilter.php @@ -4,6 +4,15 @@ namespace BusinessLogic\Calendar; class SearchEventsFilter { + /* @var $startTime int|null */ + public $startTime; + + /* @var $endTime int|null */ + public $endTime; + + /* @var $id int|null */ + public $eventId; + /* @var $categories int[]|null */ public $categories; diff --git a/api/BusinessLogic/Tickets/TicketEditor.php b/api/BusinessLogic/Tickets/TicketEditor.php index e15b33d9..5b6e2f7d 100644 --- a/api/BusinessLogic/Tickets/TicketEditor.php +++ b/api/BusinessLogic/Tickets/TicketEditor.php @@ -135,4 +135,25 @@ class TicketEditor extends \BaseClass { throw new ValidationException($validationModel); } } + + /** + * @param $id int + * @param $dueDate string + * @param $userContext UserContext + * @param $heskSettings array + * @throws ApiFriendlyException If ticket does not exist or if the user cannot edit the ticket + */ + function updateDueDate($id, $dueDate, $userContext, $heskSettings) { + $ticket = $this->ticketGateway->getTicketById($id, $heskSettings); + + if ($ticket === null) { + throw new ApiFriendlyException("Please enter a valid ticket ID.", "Ticket Not Found!", 400); + } + + if (!$this->userToTicketChecker->isTicketAccessibleToUser($userContext, $ticket, $heskSettings, array(UserPrivilege::CAN_EDIT_TICKETS))) { + throw new ApiFriendlyException("User " . $userContext->id . " does not have permission to edit ticket " . $id, "Access Denied", 403); + } + + // TODO Do it + } } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index 1a180fc1..2e30c0b1 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -32,18 +32,20 @@ class CalendarController extends \BaseClass { $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); $searchEventsFilter = new SearchEventsFilter(); + $searchEventsFilter->startTime = $startTime; + $searchEventsFilter->endTime = $endTime; $searchEventsFilter->reminderUserId = $userContext->id; $searchEventsFilter->includeTicketsAssignedToOthers = in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions); $searchEventsFilter->includeUnassignedTickets = in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions); $searchEventsFilter->includeTickets = true; $searchEventsFilter->categories = $userContext->admin ? null : $userContext->categories; - $events = $calendarHandler->getEventsForStaff($startTime, $endTime, $searchEventsFilter, $hesk_settings); + $events = $calendarHandler->getEventsForStaff($searchEventsFilter, $hesk_settings); return output($events); } - function put($id) { + function post() { /* @var $userContext UserContext */ global $applicationContext, $hesk_settings, $userContext; @@ -53,25 +55,36 @@ class CalendarController extends \BaseClass { /* @var $calendarHandler CalendarHandler */ $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); + } + + function put($id) { + /* @var $userContext UserContext */ + global $applicationContext, $hesk_settings, $userContext; + + $json = JsonRetriever::getJsonData(); + + $event = $this->transformJson($json, $id); + + /* @var $calendarHandler CalendarHandler */ + $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); return output($calendarHandler->updateEvent($event, $userContext, $hesk_settings)); } - private function transformJson($json, $creating = false) { + private function transformJson($json, $id = null) { $event = new CalendarEvent(); - if ($creating) { - $event->id = Helpers::safeArrayGet($json, 'id'); - } - - $event->startTime = date('Y-m-d H:i:s', Helpers::safeArrayGet($json, 'startTime')); - $event->endTime = date('Y-m-d H:i:s', Helpers::safeArrayGet($json, 'endTime')); - $event->allDay = Helpers::safeArrayGet($json, 'allDay') === 'true'; + $event->id = $id; + $event->startTime = date('Y-m-d H:i:s', strtotime(Helpers::safeArrayGet($json, 'startTime'))); + $event->endTime = date('Y-m-d H:i:s', strtotime(Helpers::safeArrayGet($json, 'endTime'))); + $event->allDay = Helpers::safeArrayGet($json, 'allDay'); $event->title = Helpers::safeArrayGet($json, 'title'); $event->location = Helpers::safeArrayGet($json, 'location'); $event->comments = Helpers::safeArrayGet($json, 'comments'); $event->categoryId = Helpers::safeArrayGet($json, 'categoryId'); $event->reminderValue = Helpers::safeArrayGet($json, 'reminderValue'); $event->reminderUnits = ReminderUnit::getByName(Helpers::safeArrayGet($json, 'reminderUnits')); + + return $event; } } \ No newline at end of file diff --git a/api/Controllers/Tickets/StaffTicketController.php b/api/Controllers/Tickets/StaffTicketController.php index 023f5352..ea4761a1 100644 --- a/api/Controllers/Tickets/StaffTicketController.php +++ b/api/Controllers/Tickets/StaffTicketController.php @@ -4,6 +4,7 @@ namespace Controllers\Tickets; use BusinessLogic\Helpers; +use BusinessLogic\Security\UserContext; use BusinessLogic\Tickets\EditTicketModel; use BusinessLogic\Tickets\TicketDeleter; use BusinessLogic\Tickets\TicketEditor; @@ -45,6 +46,16 @@ class StaffTicketController extends \BaseClass { return; } + static function updateDueDate($id) { + /* @var $userContext UserContext */ + global $applicationContext, $userContext, $hesk_settings; + + /* @var $ticketEditor TicketEditor */ + $ticketEditor = $applicationContext->get(TicketEditor::clazz()); + + + } + private function getEditTicketModel($id, $jsonRequest) { $editTicketModel = new EditTicketModel(); $editTicketModel->id = $id; diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 9367dbb7..a644370d 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -11,23 +11,19 @@ use BusinessLogic\Calendar\TicketEvent; use BusinessLogic\Security\UserContext; use Core\Constants\Priority; use DataAccess\CommonDao; +use DataAccess\Logging\LoggingGateway; class CalendarGateway extends CommonDao { /** - * @param $startTime int - * @param $endTime int * @param $searchEventsFilter SearchEventsFilter * @param $heskSettings array * @return AbstractEvent[] */ - public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { + public function getEventsForStaff($searchEventsFilter, $heskSettings) { $this->init(); $events = array(); - $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')"; - $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')"; - // EVENTS $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, @@ -38,9 +34,21 @@ class CalendarGateway extends CommonDao { LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` AS `reminders` ON `reminders`.`user_id` = " . intval($searchEventsFilter->reminderUserId) . " AND `reminders`.`event_id` = `events`.`id` - WHERE NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) + WHERE 1=1"; + + if ($searchEventsFilter->startTime !== null && $searchEventsFilter->endTime !== null) { + $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($searchEventsFilter->startTime) . " / 1000), @@session.time_zone, '+00:00')"; + $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($searchEventsFilter->endTime) . " / 1000), @@session.time_zone, '+00:00')"; + + + $sql .= " AND NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) AND `categories`.`usage` <> 1 AND `categories`.`type` = '0'"; + } + + if ($searchEventsFilter->eventId !== null) { + $sql .= " AND `events`.`id` = " . intval($searchEventsFilter->eventId); + } if (!empty($searchEventsFilter->categories)) { $categoriesAsString = implode(',', $searchEventsFilter->categories); @@ -130,6 +138,33 @@ class CalendarGateway extends CommonDao { return $events; } + /** + * @param $event CalendarEvent + * @param $userContext UserContext + * @param $heskSettings array + * @return CalendarEvent + */ + public function createEvent($event, $userContext, $heskSettings) { + $this->init(); + + hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` (`start`, `end`, `all_day`, `name`, + `location`, `comments`, `category`) VALUES ('" . hesk_dbEscape($event->startTime) . "', '" . hesk_dbEscape($event->endTime) . "', + '" . ($event->allDay ? 1 : 0) . "', '" . hesk_dbEscape(addslashes($event->title)) . "', + '" . hesk_dbEscape(addslashes($event->location)) . "', '". hesk_dbEscape(addslashes($event->comments)) . "', " . intval($event->categoryId) . ")"); + + $event->id = hesk_dbInsertID(); + + if ($event->reminderValue !== null) { + hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`, + `amount`, `unit`) VALUES (" . intval($userContext->id) . ", " . intval($event->id) . ", " . intval($event->reminderValue) . ", + " . intval($event->reminderUnits) . ")"); + } + + $this->close(); + + return $event; + } + /** * @param $event CalendarEvent * @param $userContext UserContext @@ -143,7 +178,7 @@ class CalendarGateway extends CommonDao { . hesk_dbEscape(addslashes($event->title)) . "', `location` = '" . hesk_dbEscape(addslashes($event->location)) . "', `comments` = '" . hesk_dbEscape(addslashes($event->comments)) . "', `category` = " . intval($event->categoryId) . " WHERE `id` = " . intval($event->id); - if ($event->reminderValue != null) { + if ($event->reminderValue !== null) { $delete_sql = "DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` WHERE `event_id` = " . intval($event->id) . " AND `user_id` = " . intval($userContext->id); hesk_dbQuery($delete_sql); diff --git a/api/index.php b/api/index.php index d833c236..00bd9af3 100644 --- a/api/index.php +++ b/api/index.php @@ -203,7 +203,7 @@ Link::all(array( // Settings '/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()), // Calendar - '/v1/calendar/events/staff' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), + '/v1/calendar/events/staff' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET, RequestMethod::POST), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), '/v1/calendar/events/staff/{i}' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::PUT), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), /* Internal use only routes */ diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 88197f4f..1ccfe7eb 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -204,7 +204,6 @@ $(document).ready(function() { allDay: allDay, comments: $createForm.find('textarea[name="comments"]').val(), categoryId: $createForm.find('select[name="category"]').val(), - action: 'create', type: 'CALENDAR', backgroundColor: $createForm.find('select[name="category"] :selected').attr('data-background-color'), foregroundColor: $createForm.find('select[name="category"] :selected').attr('data-foreground-color'), @@ -216,8 +215,10 @@ $(document).ready(function() { $.ajax({ method: 'POST', - url: heskPath + 'internal-api/admin/calendar/', - data: data, + url: heskPath + 'api/v1/calendar/events/staff', + data: JSON.stringify(data), + contentType: 'json', + headers: { 'X-Internal-Call': true }, success: function(id) { addToCalendar(id, data, $('#lang_event_created').text()); $('#create-event-modal').modal('hide'); @@ -245,7 +246,6 @@ $(document).ready(function() { } var data = { - id: $form.find('input[name="id"]').val(), title: $form.find('input[name="name"]').val(), location: $form.find('input[name="location"]').val(), startTime: moment(start).format(dateFormat), @@ -257,15 +257,19 @@ $(document).ready(function() { foregroundColor: $form.find('select[name="category"] :selected').attr('data-foreground-color'), displayBorder: $form.find('select[name="category"] :selected').attr('data-display-border'), categoryName: $form.find('select[name="category"] :selected').text().trim(), - action: 'update', reminderValue: $form.find('input[name="reminder-value"]').val(), reminderUnits: $form.find('select[name="reminder-unit"]').val() }; $.ajax({ method: 'POST', - url: heskPath + 'internal-api/admin/calendar/', - data: data, + url: heskPath + 'api/v1/calendar/events/staff/' + $form.find('input[name="id"]').val(), + data: JSON.stringify(data), + contentType: 'json', + headers: { + 'X-Internal-Call': true, + 'X-HTTP-Method-Override': 'PUT' + }, success: function() { removeFromCalendar(data.id); addToCalendar(data.id, data, $('#lang_event_updated').text()); @@ -291,7 +295,7 @@ function removeFromCalendar(id) { } function buildEvent(id, dbObject) { - if (dbObject.type == 'TICKET') { + if (dbObject.type === 'TICKET') { return { title: dbObject.title, subject: dbObject.subject, From bd5b3e1322ff03f6cd097f90d64ff3e078c32dc9 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 1 Jan 2018 21:39:01 -0500 Subject: [PATCH 09/20] Working on moving the update ticket due date endpoint --- api/BusinessLogic/Tickets/AuditTrailEvent.php | 9 +++ api/BusinessLogic/Tickets/TicketEditor.php | 59 +++++++++++++++++-- api/DataAccess/Tickets/TicketGateway.php | 14 +++++ 3 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 api/BusinessLogic/Tickets/AuditTrailEvent.php diff --git a/api/BusinessLogic/Tickets/AuditTrailEvent.php b/api/BusinessLogic/Tickets/AuditTrailEvent.php new file mode 100644 index 00000000..d3063e73 --- /dev/null +++ b/api/BusinessLogic/Tickets/AuditTrailEvent.php @@ -0,0 +1,9 @@ +ticketGateway = $ticketGateway; $this->userToTicketChecker = $userToTicketChecker; + $this->auditTrailGateway = $auditTrailGateway; } @@ -141,19 +148,61 @@ class TicketEditor extends \BaseClass { * @param $dueDate string * @param $userContext UserContext * @param $heskSettings array - * @throws ApiFriendlyException If ticket does not exist or if the user cannot edit the ticket + * @return Ticket The updated ticket */ function updateDueDate($id, $dueDate, $userContext, $heskSettings) { $ticket = $this->ticketGateway->getTicketById($id, $heskSettings); + $this->validateDueDate($ticket, $dueDate, $userContext, $heskSettings); + + $this->ticketGateway->updateTicketDueDate($ticket->id, $dueDate, $heskSettings); + + $event = AuditTrailEvent::DUE_DATE_REMOVED; + $replacementValues = array(0 => $userContext->name . ' (' . $userContext->username . ')'); + if ($dueDate !== null) { + $event = AuditTrailEvent::DUE_DATE_CHANGED; + $replacementValues = array( + 0 => $userContext->name . ' (' . $userContext->username . ')', + 1 => date('Y-m-d H:i:s', strtotime($dueDate)) + ); + } + + $this->auditTrailGateway->insertAuditTrailRecord($ticket->id, + AuditTrailEntityType::TICKET, + $event, + DateTimeHelpers::heskDate($heskSettings), + $replacementValues, + $heskSettings); + + $ticket->dueDate = $dueDate; + + return $ticket; + } + + /** + * @param $ticket Ticket + * @param $dueDate string + * @param $userContext UserContext + * @param $heskSettings array + * @throws ValidationException When validation fails + */ + private function validateDueDate($ticket, $dueDate, $userContext, $heskSettings) { + $validationModel = new ValidationModel(); + if ($ticket === null) { - throw new ApiFriendlyException("Please enter a valid ticket ID.", "Ticket Not Found!", 400); + $validationModel->errorKeys[] = 'TICKET_MUST_EXIST_FOR_ID'; } if (!$this->userToTicketChecker->isTicketAccessibleToUser($userContext, $ticket, $heskSettings, array(UserPrivilege::CAN_EDIT_TICKETS))) { - throw new ApiFriendlyException("User " . $userContext->id . " does not have permission to edit ticket " . $id, "Access Denied", 403); + $validationModel->errorKeys[] = 'TICKET_MUST_BE_ACCESSIBLE_TO_USER'; } - // TODO Do it + if ($dueDate === false) { + $validationModel->errorKeys[] = 'DUE_DATE_MUST_BE_IN_VALID_FORMAT'; + } + + if (count($validationModel->errorKeys) > 0) { + throw new ValidationException($validationModel); + } } } \ No newline at end of file diff --git a/api/DataAccess/Tickets/TicketGateway.php b/api/DataAccess/Tickets/TicketGateway.php index 4c72a9f2..2ea5a84d 100644 --- a/api/DataAccess/Tickets/TicketGateway.php +++ b/api/DataAccess/Tickets/TicketGateway.php @@ -440,4 +440,18 @@ class TicketGateway extends CommonDao { $this->close(); } + + function updateTicketDueDate($id, $dueDate, $heskSettings) { + $this->init(); + + $sqlDueDate = 'NULL'; + if ($dueDate != NULL) { + $sqlDueDate = "'" . date('Y-m-d H:i:s', strtotime($dueDate)) . "'"; + } + + hesk_dbQuery("UPDATE `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` SET `due_date` = {$sqlDueDate} + WHERE `id` = " . intval($id)); + + $this->close(); + } } \ No newline at end of file From 0514965040d3199a843bdfd676198319d3359b35 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Tue, 2 Jan 2018 13:05:10 -0500 Subject: [PATCH 10/20] Update due date mostly done... just need to fix the buildEvent function --- api/BusinessLogic/Calendar/AbstractEvent.php | 2 ++ api/BusinessLogic/Calendar/CalendarEvent.php | 2 -- api/BusinessLogic/Helpers.php | 4 ++++ .../Tickets/StaffTicketController.php | 4 ++++ api/DataAccess/Calendar/CalendarGateway.php | 14 ++++++----- api/index.php | 1 + js/calendar/mods-for-hesk-calendar.js | 23 ++++++++++++------- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/api/BusinessLogic/Calendar/AbstractEvent.php b/api/BusinessLogic/Calendar/AbstractEvent.php index 5413ef48..27f2a184 100644 --- a/api/BusinessLogic/Calendar/AbstractEvent.php +++ b/api/BusinessLogic/Calendar/AbstractEvent.php @@ -4,6 +4,8 @@ namespace BusinessLogic\Calendar; class AbstractEvent { + public $id; + public $startTime; public $title; diff --git a/api/BusinessLogic/Calendar/CalendarEvent.php b/api/BusinessLogic/Calendar/CalendarEvent.php index 893cbccb..91a45761 100644 --- a/api/BusinessLogic/Calendar/CalendarEvent.php +++ b/api/BusinessLogic/Calendar/CalendarEvent.php @@ -4,8 +4,6 @@ namespace BusinessLogic\Calendar; class CalendarEvent extends AbstractEvent { - public $id; - public $type = 'CALENDAR'; public $endTime; diff --git a/api/BusinessLogic/Helpers.php b/api/BusinessLogic/Helpers.php index f2a49c6d..b841fd27 100644 --- a/api/BusinessLogic/Helpers.php +++ b/api/BusinessLogic/Helpers.php @@ -30,4 +30,8 @@ class Helpers extends \BaseClass { static function boolval($val) { return $val == true; } + + static function heskHtmlSpecialCharsDecode($in) { + return str_replace(array('&', '<', '>', '"'), array('&', '<', '>', '"'), $in); + } } \ No newline at end of file diff --git a/api/Controllers/Tickets/StaffTicketController.php b/api/Controllers/Tickets/StaffTicketController.php index ea4761a1..e049bca5 100644 --- a/api/Controllers/Tickets/StaffTicketController.php +++ b/api/Controllers/Tickets/StaffTicketController.php @@ -53,7 +53,11 @@ class StaffTicketController extends \BaseClass { /* @var $ticketEditor TicketEditor */ $ticketEditor = $applicationContext->get(TicketEditor::clazz()); + $json = JsonRetriever::getJsonData(); + $dueDate = date('Y-m-d H:i:s', strtotime(Helpers::safeArrayGet($json, 'dueDate'))); + + $ticketEditor->updateDueDate($id, $dueDate, $userContext, $hesk_settings); } private function getEditTicketModel($id, $jsonRequest) { diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index a644370d..f101f1bd 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -8,6 +8,7 @@ use BusinessLogic\Calendar\CalendarEvent; use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Calendar\TicketEvent; +use BusinessLogic\Helpers; use BusinessLogic\Security\UserContext; use Core\Constants\Priority; use DataAccess\CommonDao; @@ -61,15 +62,15 @@ class CalendarGateway extends CommonDao { $event->id = intval($row['id']); $event->startTime = $row['start']; $event->endTime = $row['end']; - $event->allDay = $row['all_day'] ? true : false; + $event->allDay = Helpers::boolval($row['all_day']); $event->title = $row['name']; $event->location = $row['location']; $event->comments = $row['comments']; $event->categoryId = intval($row['category']); - $event->categoryName = $row['category_name']; + $event->categoryName = Helpers::heskHtmlSpecialCharsDecode($row['category_name']); $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border'] === '1'; + $event->displayBorder = Helpers::boolval($row['display_border']); $event->reminderValue = $row['reminder_value'] === null ? null : floatval($row['reminder_value']); $event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']); @@ -83,7 +84,7 @@ class CalendarGateway extends CommonDao { $currentDate = hesk_date(); $heskSettings['timeformat'] = $oldTimeSetting; - $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, + $sql = "SELECT `tickets`.`id` AS `id`, `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, CASE WHEN `due_date` < '{$currentDate}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, `tickets`.`priority` AS `priority` @@ -116,16 +117,17 @@ class CalendarGateway extends CommonDao { $rs = hesk_dbQuery($sql); while ($row = hesk_dbFetchAssoc($rs)) { $event = new TicketEvent(); + $event->id = intval($row['id']); $event->trackingId = $row['trackid']; $event->subject = $row['subject']; $event->title = $row['subject']; $event->startTime = $row['due_date']; $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event->trackingId; $event->categoryId = intval($row['category']); - $event->categoryName = $row['category_name']; + $event->categoryName = Helpers::heskHtmlSpecialCharsDecode($row['category_name']); $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border'] === '0'; + $event->displayBorder = Helpers::boolval($row['display_border']); $event->owner = $row['owner_name']; $event->priority = Priority::getByValue($row['priority']); diff --git a/api/index.php b/api/index.php index 00bd9af3..3888685c 100644 --- a/api/index.php +++ b/api/index.php @@ -194,6 +194,7 @@ Link::all(array( '/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::clazz(), RequestMethod::all(), SecurityHandler::OPEN), // Tickets - Staff '/v1/staff/tickets/{i}' => action(\Controllers\Tickets\StaffTicketController::clazz(), RequestMethod::all()), + '/v1/staff/tickets/{i}/due-date' => action(\Controllers\Tickets\StaffTicketController::clazz() . '::updateDueDate', array(RequestMethod::PATCH), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), // Attachments '/v1/tickets/{a}/attachments/{i}' => action(\Controllers\Attachments\PublicAttachmentController::clazz() . '::getRaw', RequestMethod::all()), '/v1/staff/tickets/{i}/attachments' => action(\Controllers\Attachments\StaffTicketAttachmentsController::clazz(), RequestMethod::all()), diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 1ccfe7eb..1d6729f4 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -482,15 +482,19 @@ function updateCategoryVisibility() { function respondToDragAndDrop(event, delta, revertFunc) { var heskPath = $('p#hesk-path').text(); + if (event.type === 'TICKET') { + var uri = 'api/v1/staff/tickets/' + event.id + '/due-date'; $.ajax({ method: 'POST', - url: heskPath + 'internal-api/admin/calendar/', - data: { - trackingId: event.trackingId, - action: 'update-ticket', - dueDate: event.start.format('YYYY-MM-DD') + url: heskPath + uri, + headers: { + 'X-Internal-Call': true, + 'X-HTTP-Method-Override': 'PATCH' }, + data: JSON.stringify({ + dueDate: event.start.format('YYYY-MM-DD') + }), success: function() { event.fontIconMarkup = getIcon({ startTime: event.start @@ -519,7 +523,6 @@ function respondToDragAndDrop(event, delta, revertFunc) { end += ' ' + event.end.format('HH:mm:ss'); } var data = { - id: event.id, title: event.title, location: event.location, startTime: start, @@ -533,8 +536,12 @@ function respondToDragAndDrop(event, delta, revertFunc) { }; $.ajax({ method: 'POST', - url: heskPath + 'internal-api/admin/calendar/', - data: data, + url: heskPath + 'api/v1/calendar/events/staff/' + event.id, + data: JSON.stringify(data), + headers: { + 'X-Internal-Call': true, + 'X-HTTP-Method-Override': 'PUT' + }, success: function() { mfhAlert.success(mfhLang.text('event_updated')); }, From c4b79a722c1f7aae466e5aad8c611a0f8099319f Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 3 Jan 2018 13:04:23 -0500 Subject: [PATCH 11/20] More calendar tweaks --- .../Calendar/CalendarHandler.php | 14 +++++- .../Calendar/CalendarController.php | 2 + api/DataAccess/Calendar/CalendarGateway.php | 2 - js/calendar/mods-for-hesk-calendar.js | 44 +++++++++++-------- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/api/BusinessLogic/Calendar/CalendarHandler.php b/api/BusinessLogic/Calendar/CalendarHandler.php index 5347eaf1..766ea537 100644 --- a/api/BusinessLogic/Calendar/CalendarHandler.php +++ b/api/BusinessLogic/Calendar/CalendarHandler.php @@ -44,6 +44,18 @@ class CalendarHandler extends \BaseClass { public function createEvent($calendarEvent, $userContext, $heskSettings) { - return $this->calendarGateway->createEvent($calendarEvent, $userContext, $heskSettings); + $this->calendarGateway->createEvent($calendarEvent, $userContext, $heskSettings); + + $eventFilter = new SearchEventsFilter(); + $eventFilter->eventId = $calendarEvent->id; + $eventFilter->reminderUserId = $userContext->id; + + $events = $this->calendarGateway->getEventsForStaff($eventFilter, $heskSettings); + + if (count($events) !== 1) { + throw new \Exception("Expected exactly 1 event, found: " . count($events)); + } + + return $events[0]; } } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index 2e30c0b1..f7be1d0e 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -55,6 +55,8 @@ class CalendarController extends \BaseClass { /* @var $calendarHandler CalendarHandler */ $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); + + return output($calendarHandler->createEvent($event, $userContext, $hesk_settings)); } function put($id) { diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index f101f1bd..416e7f1e 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -163,8 +163,6 @@ class CalendarGateway extends CommonDao { } $this->close(); - - return $event; } /** diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 1d6729f4..677a5db1 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -52,16 +52,7 @@ $(document).ready(function() { var $contents = $(contents); var format = 'dddd, MMMM Do YYYY'; - var endDate = event.end == null ? event.start : event.end; - - if (event.allDay) { - endDate = event.end.clone(); - endDate.add(-1, 'days'); - } - - if (!event.allDay && event.type !== 'TICKET') { - format += ', HH:mm'; - } + var endDate = event.end === null ? event.start : event.end; if (event.type === 'TICKET') { contents = $('.ticket-popover-template').html(); @@ -77,6 +68,13 @@ $(document).ready(function() { .find('.popover-category span').text(event.categoryName).end() .find('.popover-priority span').text(event.priority); } else { + if (event.allDay) { + endDate = event.end.clone(); + endDate.add(-1, 'days'); + } else { + format += ', HH:mm'; + } + if (event.location === '') { $contents.find('.popover-location').hide(); } @@ -196,6 +194,9 @@ $(document).ready(function() { dateFormat = 'YYYY-MM-DD HH:mm:ss'; } + var reminderValue = $createForm.find('input[name="reminder-value"]').val(); + var reminderUnits = $createForm.find('select[name="reminder-unit"]').val(); + var data = { title: $createForm.find('input[name="name"]').val(), location: $createForm.find('input[name="location"]').val(), @@ -209,8 +210,8 @@ $(document).ready(function() { foregroundColor: $createForm.find('select[name="category"] :selected').attr('data-foreground-color'), displayBorder: $createForm.find('select[name="category"] :selected').attr('data-display-border'), categoryName: $createForm.find('select[name="category"] :selected').text().trim(), - reminderValue: $createForm.find('input[name="reminder-value"]').val(), - reminderUnits: $createForm.find('select[name="reminder-unit"]').val() + reminderValue: reminderValue === "" ? null : reminderValue, + reminderUnits: reminderValue === "" ? null : reminderUnits }; $.ajax({ @@ -245,25 +246,29 @@ $(document).ready(function() { dateFormat = 'YYYY-MM-DD HH:mm:ss'; } + var reminderValue = $createForm.find('input[name="reminder-value"]').val(); + var reminderUnits = $createForm.find('select[name="reminder-unit"]').val(); + var data = { + id: $form.find('input[name="id"]').val(), title: $form.find('input[name="name"]').val(), location: $form.find('input[name="location"]').val(), startTime: moment(start).format(dateFormat), endTime: moment(end).format(dateFormat), allDay: allDay, comments: $form.find('textarea[name="comments"]').val(), - categoryId: $form.find('select[name="category"]').val(), + categoryId: parseInt($form.find('select[name="category"]').val()), backgroundColor: $form.find('select[name="category"] :selected').attr('data-background-color'), foregroundColor: $form.find('select[name="category"] :selected').attr('data-foreground-color'), displayBorder: $form.find('select[name="category"] :selected').attr('data-display-border'), categoryName: $form.find('select[name="category"] :selected').text().trim(), - reminderValue: $form.find('input[name="reminder-value"]').val(), - reminderUnits: $form.find('select[name="reminder-unit"]').val() + reminderValue: reminderValue === "" ? null : reminderValue, + reminderUnits: reminderValue === "" ? null : reminderUnits }; $.ajax({ method: 'POST', - url: heskPath + 'api/v1/calendar/events/staff/' + $form.find('input[name="id"]').val(), + url: heskPath + 'api/v1/calendar/events/staff/' + data.id, data: JSON.stringify(data), contentType: 'json', headers: { @@ -297,6 +302,7 @@ function removeFromCalendar(id) { function buildEvent(id, dbObject) { if (dbObject.type === 'TICKET') { return { + id: id, title: dbObject.title, subject: dbObject.subject, trackingId: dbObject.trackingId, @@ -384,7 +390,7 @@ function displayCreateModal(date, viewName) { .find('input[name="location"]').val('').end() .find('textarea[name="comments"]').val('').end() .find('select[name="category"]').val($form.find('select[name="category"] option:first-child').val()).end() - .find('select[name="reminder-unit"]').val(0).end() + .find('select[name="reminder-unit"]').val("MINUTE").end() .find('input[name="reminder-value"]').val('').end(); var $modal = $('#create-event-modal'); @@ -534,9 +540,11 @@ function respondToDragAndDrop(event, delta, revertFunc) { reminderValue: event.reminderValue, reminderUnits: event.reminderUnits }; + + var url = heskPath + 'api/v1/calendar/events/staff/' + event.id; $.ajax({ method: 'POST', - url: heskPath + 'api/v1/calendar/events/staff/' + event.id, + url: url, data: JSON.stringify(data), headers: { 'X-Internal-Call': true, From 3d73b9a4b25c55481c09efeea982ae4e79484690 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 7 Jan 2018 22:02:43 -0500 Subject: [PATCH 12/20] All main staff calendar endpoints moved --- .../Calendar/CalendarHandler.php | 6 +++-- .../Calendar/CalendarController.php | 12 ++++++++++ api/DataAccess/Calendar/CalendarGateway.php | 16 +++++++++++++ api/index.php | 2 +- js/calendar/mods-for-hesk-calendar.js | 24 +++++++++---------- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/api/BusinessLogic/Calendar/CalendarHandler.php b/api/BusinessLogic/Calendar/CalendarHandler.php index 766ea537..ad5a1775 100644 --- a/api/BusinessLogic/Calendar/CalendarHandler.php +++ b/api/BusinessLogic/Calendar/CalendarHandler.php @@ -3,10 +3,8 @@ namespace BusinessLogic\Calendar; -use BusinessLogic\Exceptions\ApiFriendlyException; use BusinessLogic\Security\UserContext; use DataAccess\Calendar\CalendarGateway; -use PHPUnit\Runner\Exception; class CalendarHandler extends \BaseClass { private $calendarGateway; @@ -58,4 +56,8 @@ class CalendarHandler extends \BaseClass { return $events[0]; } + + public function deleteEvent($id, $userContext, $heskSettings) { + $this->calendarGateway->deleteEvent($id, $userContext, $heskSettings); + } } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index f7be1d0e..d586b310 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -73,6 +73,18 @@ class CalendarController extends \BaseClass { return output($calendarHandler->updateEvent($event, $userContext, $hesk_settings)); } + function delete($id) { + /* @var $userContext UserContext */ + global $applicationContext, $hesk_settings, $userContext; + + /* @var $calendarHandler CalendarHandler */ + $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); + + $calendarHandler->deleteEvent($id, $userContext, $hesk_settings); + + return http_response_code(204); + } + private function transformJson($json, $id = null) { $event = new CalendarEvent(); diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 416e7f1e..81b7026f 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -192,4 +192,20 @@ class CalendarGateway extends CommonDao { $this->close(); } + + /** + * @param $id int + * @param $userContext UserContext + * @param $heskSettings array + */ + public function deleteEvent($id, $userContext, $heskSettings) { + $this->init(); + + hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` + WHERE `event_id` = " . intval($id) . " AND `user_id` = " . intval($userContext->id)); + hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` + WHERE `id` = " . intval($id)); + + $this->close(); + } } \ No newline at end of file diff --git a/api/index.php b/api/index.php index 3888685c..2277d647 100644 --- a/api/index.php +++ b/api/index.php @@ -205,7 +205,7 @@ Link::all(array( '/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()), // Calendar '/v1/calendar/events/staff' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET, RequestMethod::POST), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), - '/v1/calendar/events/staff/{i}' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::PUT), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), + '/v1/calendar/events/staff/{i}' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::PUT, RequestMethod::DELETE), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), /* Internal use only routes */ // Resend email response diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 677a5db1..2561381b 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -16,7 +16,7 @@ $(document).ready(function() { defaultView: $('#setting_default_view').text().trim(), events: function(start, end, timezone, callback) { $.ajax({ - url: heskPath + 'api/v1/calendar/events/staff?start=' + start + '&end=' + end, + url: heskPath + 'api/index.php/v1/calendar/events/staff?start=' + start + '&end=' + end, method: 'GET', dataType: 'json', headers: { 'X-Internal-Call': true }, @@ -160,17 +160,15 @@ $(document).ready(function() { $editForm.find('#delete-button').click(function() { var id = $editForm.find('input[name="id"]').val(); - var data = { - id: id, - action: 'delete' - }; - $.ajax({ method: 'POST', - url: heskPath + 'internal-api/admin/calendar/', - data: data, + url: heskPath + 'api/index.php/v1/calendar/events/staff/' + id, + headers: { + 'X-Internal-Call': true, + 'X-HTTP-Method-Override': 'DELETE' + }, success: function() { - removeFromCalendar(data.id); + removeFromCalendar(id); mfhAlert.success(mfhLang.text('event_deleted')); $('#edit-event-modal').modal('hide'); }, @@ -216,7 +214,7 @@ $(document).ready(function() { $.ajax({ method: 'POST', - url: heskPath + 'api/v1/calendar/events/staff', + url: heskPath + 'api/index.php/v1/calendar/events/staff', data: JSON.stringify(data), contentType: 'json', headers: { 'X-Internal-Call': true }, @@ -268,7 +266,7 @@ $(document).ready(function() { $.ajax({ method: 'POST', - url: heskPath + 'api/v1/calendar/events/staff/' + data.id, + url: heskPath + 'api/index.php/v1/calendar/events/staff/' + data.id, data: JSON.stringify(data), contentType: 'json', headers: { @@ -490,7 +488,7 @@ function respondToDragAndDrop(event, delta, revertFunc) { var heskPath = $('p#hesk-path').text(); if (event.type === 'TICKET') { - var uri = 'api/v1/staff/tickets/' + event.id + '/due-date'; + var uri = 'api/index.php/v1/staff/tickets/' + event.id + '/due-date'; $.ajax({ method: 'POST', url: heskPath + uri, @@ -541,7 +539,7 @@ function respondToDragAndDrop(event, delta, revertFunc) { reminderUnits: event.reminderUnits }; - var url = heskPath + 'api/v1/calendar/events/staff/' + event.id; + var url = heskPath + 'api/index.php/v1/calendar/events/staff/' + event.id; $.ajax({ method: 'POST', url: url, From 4c2432a35bec4dacc697dc003dae03bf4d1d8b97 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Tue, 9 Jan 2018 12:37:29 -0500 Subject: [PATCH 13/20] Moved all calendar API logic to the api folder --- api/BusinessLogic/Categories/Category.php | 2 +- .../Categories/CategoryHandler.php | 13 ++ .../Calendar/CalendarController.php | 27 ++- api/DataAccess/Calendar/CalendarGateway.php | 3 +- api/index.php | 1 + internal-api/calendar/index.php | 29 --- internal-api/dao/calendar_dao.php | 195 ------------------ .../mods-for-hesk-calendar-admin-readonly.js | 3 +- .../mods-for-hesk-calendar-readonly.js | 2 +- js/calendar/mods-for-hesk-calendar.js | 4 +- 10 files changed, 44 insertions(+), 235 deletions(-) delete mode 100644 internal-api/calendar/index.php delete mode 100644 internal-api/dao/calendar_dao.php diff --git a/api/BusinessLogic/Categories/Category.php b/api/BusinessLogic/Categories/Category.php index 597c3410..f7ea363e 100644 --- a/api/BusinessLogic/Categories/Category.php +++ b/api/BusinessLogic/Categories/Category.php @@ -22,7 +22,7 @@ class Category extends \BaseClass { public $autoAssign; /** - * @var int The type of Categories (1 = Private, 2 = Public) + * @var int The type of Categories (1 = Private, 0 = Public) */ public $type; diff --git a/api/BusinessLogic/Categories/CategoryHandler.php b/api/BusinessLogic/Categories/CategoryHandler.php index 98e5b6d4..49d0b189 100644 --- a/api/BusinessLogic/Categories/CategoryHandler.php +++ b/api/BusinessLogic/Categories/CategoryHandler.php @@ -187,4 +187,17 @@ class CategoryHandler extends \BaseClass { $this->categoryGateway->updateCategory($category, $heskSettings); $this->categoryGateway->resortAllCategories($heskSettings); } + + function getPublicCategories($heskSettings) { + $allCategories = $this->categoryGateway->getAllCategories($heskSettings, $this->modsForHeskSettingsGateway->getAllSettings($heskSettings)); + + $publicCategories = array(); + foreach ($allCategories as $category) { + if ($category->type === 0) { + $publicCategories[] = $category; + } + } + + return $publicCategories; + } } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index d586b310..0953b585 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -7,12 +7,14 @@ use BusinessLogic\Calendar\CalendarEvent; use BusinessLogic\Calendar\CalendarHandler; use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; +use BusinessLogic\Categories\CategoryHandler; use BusinessLogic\Exceptions\ValidationException; use BusinessLogic\Helpers; use BusinessLogic\Security\UserContext; use BusinessLogic\Security\UserPrivilege; use BusinessLogic\ValidationModel; use Controllers\JsonRetriever; +use DataAccess\Settings\ModsForHeskSettingsGateway; class CalendarController extends \BaseClass { function get() { @@ -35,10 +37,27 @@ class CalendarController extends \BaseClass { $searchEventsFilter->startTime = $startTime; $searchEventsFilter->endTime = $endTime; $searchEventsFilter->reminderUserId = $userContext->id; - $searchEventsFilter->includeTicketsAssignedToOthers = in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions); - $searchEventsFilter->includeUnassignedTickets = in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions); - $searchEventsFilter->includeTickets = true; - $searchEventsFilter->categories = $userContext->admin ? null : $userContext->categories; + + if ($userContext->isAnonymousUser()) { + $searchEventsFilter->includeTicketsAssignedToOthers = false; + $searchEventsFilter->includeUnassignedTickets = false; + $searchEventsFilter->includeTickets = false; + + /* @var $categoryHandler CategoryHandler */ + $categoryHandler = $applicationContext->get(CategoryHandler::clazz()); + + $publicCategories = $categoryHandler->getPublicCategories($hesk_settings); + $ids = array(); + foreach ($publicCategories as $category) { + $ids[] = $category->id; + } + $searchEventsFilter->categories = $ids; + } else { + $searchEventsFilter->includeTicketsAssignedToOthers = in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions); + $searchEventsFilter->includeUnassignedTickets = in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions); + $searchEventsFilter->includeTickets = true; + $searchEventsFilter->categories = $userContext->admin ? null : $userContext->categories; + } $events = $calendarHandler->getEventsForStaff($searchEventsFilter, $hesk_settings); diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 81b7026f..ddb263e6 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -43,8 +43,7 @@ class CalendarGateway extends CommonDao { $sql .= " AND NOT (`end` < {$startTimeSql} OR `start` > {$endTimeSql}) - AND `categories`.`usage` <> 1 - AND `categories`.`type` = '0'"; + AND `categories`.`usage` <> 1"; } if ($searchEventsFilter->eventId !== null) { diff --git a/api/index.php b/api/index.php index 2277d647..7c0574b2 100644 --- a/api/index.php +++ b/api/index.php @@ -204,6 +204,7 @@ Link::all(array( // Settings '/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()), // Calendar + '/v1/calendar/events' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET), SecurityHandler::OPEN), '/v1/calendar/events/staff' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET, RequestMethod::POST), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), '/v1/calendar/events/staff/{i}' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::PUT, RequestMethod::DELETE), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), diff --git a/internal-api/calendar/index.php b/internal-api/calendar/index.php deleted file mode 100644 index 1ccc6011..00000000 --- a/internal-api/calendar/index.php +++ /dev/null @@ -1,29 +0,0 @@ - {$end_time_sql}) AND `categories`.`usage` <> 1"; - - if (!$staff) { - $sql .= " AND `categories`.`type` = '0'"; - } - - $rs = hesk_dbQuery($sql); - - $events = array(); - while ($row = hesk_dbFetchAssoc($rs)) { - // Skip the event if the user does not have access to it - if ($staff && !$_SESSION['isadmin'] && !in_array($row['category'], $_SESSION['categories'])) { - continue; - } - - mfh_log_debug('Calendar', "Creating event with id: {$row['id']}", ''); - - $event['type'] = 'CALENDAR'; - $event['id'] = intval($row['id']); - $event['startTime'] = $row['start']; - $event['endTime'] = $row['end']; - $event['allDay'] = $row['all_day'] ? true : false; - $event['title'] = $row['name']; - $event['location'] = $row['location']; - $event['comments'] = $row['comments']; - $event['categoryId'] = $row['category']; - $event['categoryName'] = $row['category_name']; - $event['backgroundColor'] = $row['background_color']; - $event['foregroundColor'] = $row['foreground_color']; - $event['displayBorder'] = $row['display_border']; - - if ($staff) { - $event['reminderValue'] = $row['reminder_value']; - $event['reminderUnits'] = $row['reminder_unit']; - } - - $events[] = $event; - } - - if ($staff) { - $old_time_setting = $hesk_settings['timeformat']; - $hesk_settings['timeformat'] = 'Y-m-d'; - $current_date = hesk_date(); - $hesk_settings['timeformat'] = $old_time_setting; - - $sql = "SELECT `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, - `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, - CASE WHEN `due_date` < '{$current_date}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, - `tickets`.`priority` AS `priority` - FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` AS `tickets` - INNER JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` AS `categories` - ON `categories`.`id` = `tickets`.`category` - AND `categories`.`usage` <> 2 - LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` AS `owner` - ON `tickets`.`owner` = `owner`.`id` - WHERE `due_date` >= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($start) - . " / 1000), @@session.time_zone, '+00:00') - AND `due_date` <= CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($end) . " / 1000), @@session.time_zone, '+00:00') - AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) "; - - $rs = hesk_dbQuery($sql); - while ($row = hesk_dbFetchAssoc($rs)) { - // Skip the ticket if the user does not have access to it - if (!hesk_checkPermission('can_view_tickets', 0) - || ($row['owner_id'] && $row['owner_id'] != $_SESSION['id'] && !hesk_checkPermission('can_view_ass_others', 0)) - || (!$row['owner_id'] && !hesk_checkPermission('can_view_unassigned', 0))) { - continue; - } - - $event['type'] = 'TICKET'; - $event['trackingId'] = $row['trackid']; - $event['subject'] = $row['subject']; - $event['title'] = $row['subject']; - $event['startTime'] = $row['due_date']; - $event['url'] = $hesk_settings['hesk_url'] . '/' . $hesk_settings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; - $event['categoryId'] = $row['category']; - $event['categoryName'] = $row['category_name']; - $event['backgroundColor'] = $row['background_color']; - $event['foregroundColor'] = $row['foreground_color']; - $event['displayBorder'] = $row['display_border']; - $event['owner'] = $row['owner_name']; - - $priorities = array( - 0 => $hesklang['critical'], - 1 => $hesklang['high'], - 2 => $hesklang['medium'], - 3 => $hesklang['low'] - ); - $event['priority'] = $priorities[$row['priority']]; - - $events[] = $event; - } - } - - return $events; -} - -function create_event($event, $hesk_settings) { - // Make sure the user can create events in this category - if (!$_SESSION['isadmin'] && !in_array($event['category'], $_SESSION['categories'])) { - print_error('Access Denied', 'You cannot create an event in this category'); - } - - $event['start'] = date('Y-m-d H:i:s', strtotime($event['start'])); - $event['end'] = date('Y-m-d H:i:s', strtotime($event['end'])); - $event['all_day'] = $event['all_day'] ? 1 : 0; - - $sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` (`start`, `end`, `all_day`, - `name`, `location`, `comments`, `category`) VALUES ( - '" . hesk_dbEscape($event['start']) . "', '" . hesk_dbEscape($event['end']) . "', '" . hesk_dbEscape($event['all_day']) . "', - '" . hesk_dbEscape(addslashes($event['title'])) . "', '" . hesk_dbEscape(addslashes($event['location'])) . "', '" . hesk_dbEscape(addslashes($event['comments'])) . "', - " . intval($event['category']) . ")"; - - hesk_dbQuery($sql); - $event_id = hesk_dbInsertID(); - - if ($event['reminder_amount'] != null) { - $sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`, - `amount`, `unit`) VALUES (" . intval($event['reminder_user']) . ", " . intval($event_id) . ", " . intval($event['reminder_amount']) . ", - " . intval($event['reminder_units']) . ")"; - - hesk_dbQuery($sql); - } - - return $event_id; -} - -function update_event($event, $hesk_settings) { - // Make sure the user can edit events in this category - if (!$_SESSION['isadmin'] && !in_array($event['category'], $_SESSION['categories'])) { - print_error('Access Denied', 'You cannot edit an event in this category'); - } - - -} - -function delete_event($id, $hesk_settings) { - // Make sure the user can delete events in this category - $categoryRs = hesk_dbQuery('SELECT `category` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'calendar_event` WHERE `id` = ' . intval($id)); - $category = hesk_dbFetchAssoc($categoryRs); - if (!$_SESSION['isadmin'] && !in_array($category['category'], $_SESSION['categories'])) { - print_error('Access Denied', 'You cannot delete events in this category'); - } - - $sql = "DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` WHERE `id` = " . intval($id); - - hesk_dbQuery($sql); -} - -function update_ticket_due_date($ticket, $hesk_settings) { - $ticket_id_rs = hesk_dbQuery("SELECT `id` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` WHERE `trackid` = '" . hesk_dbEscape($ticket['trackid']) . "'"); - $ticket_id = hesk_dbFetchAssoc($ticket_id_rs); - - $due_date = 'NULL'; - $language_key = 'audit_due_date_removed'; - $audit_array = array(0 => $_SESSION['name'] . ' (' . $_SESSION['user'] . ')'); - if ($ticket['due_date'] != NULL) { - $audit_array = array( - 0 => $_SESSION['name'] . ' (' . $_SESSION['user'] . ')', - 1 => date('Y-m-d H:i:s', strtotime($ticket['due_date'])) - ); - $due_date = "'" . date('Y-m-d H:i:s', strtotime($ticket['due_date'])) . "'"; - $language_key = 'audit_due_date_changed'; - } - $sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `due_date` = {$due_date}, `overdue_email_sent` = '0' - WHERE `trackid` = '" . hesk_dbEscape($ticket['trackid']) . "'"; - - mfh_insert_audit_trail_record($ticket_id['id'], 'TICKET', $language_key, hesk_date(), - $audit_array); - - hesk_dbQuery($sql); -} \ No newline at end of file diff --git a/js/calendar/mods-for-hesk-calendar-admin-readonly.js b/js/calendar/mods-for-hesk-calendar-admin-readonly.js index 619e5d23..7290189e 100644 --- a/js/calendar/mods-for-hesk-calendar-admin-readonly.js +++ b/js/calendar/mods-for-hesk-calendar-admin-readonly.js @@ -16,9 +16,10 @@ $(document).ready(function() { defaultView: $('#setting_default_view').text().trim(), events: function(start, end, timezone, callback) { $.ajax({ - url: heskPath + 'internal-api/admin/calendar/?start=' + start + '&end=' + end, + url: heskPath + 'api/index.php/v1/calendar/events/staff?start=' + start + '&end=' + end, method: 'GET', dataType: 'json', + headers: { 'X-Internal-Call': true }, success: function(data) { var events = []; $(data).each(function() { diff --git a/js/calendar/mods-for-hesk-calendar-readonly.js b/js/calendar/mods-for-hesk-calendar-readonly.js index eff85039..a282c155 100644 --- a/js/calendar/mods-for-hesk-calendar-readonly.js +++ b/js/calendar/mods-for-hesk-calendar-readonly.js @@ -16,7 +16,7 @@ $(document).ready(function() { defaultView: $('#setting_default_view').text().trim(), events: function(start, end, timezone, callback) { $.ajax({ - url: heskPath + 'internal-api/calendar/?start=' + start + '&end=' + end, + url: heskPath + 'api/index.php/v1/calendar/events/?start=' + start + '&end=' + end, method: 'GET', dataType: 'json', success: function(data) { diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 2561381b..48fac68f 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -218,8 +218,8 @@ $(document).ready(function() { data: JSON.stringify(data), contentType: 'json', headers: { 'X-Internal-Call': true }, - success: function(id) { - addToCalendar(id, data, $('#lang_event_created').text()); + success: function(createdEvent) { + addToCalendar(createdEvent.id, data, $('#lang_event_created').text()); $('#create-event-modal').modal('hide'); updateCategoryVisibility(); }, From 4959ccb815dd6d530c5f027624e10f07d9f4657b Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 18 Jan 2018 22:02:48 -0500 Subject: [PATCH 14/20] Add php-rrule for recurring event parsing --- api/composer.json | 3 +- api/composer.lock | 147 ++++++++++++++++++++++++++++++---------------- 2 files changed, 100 insertions(+), 50 deletions(-) diff --git a/api/composer.json b/api/composer.json index b91d34b5..c7215460 100644 --- a/api/composer.json +++ b/api/composer.json @@ -17,6 +17,7 @@ "phpmailer/phpmailer": "^5.2", "mailgun/mailgun-php": "1.7.2", "mike-koch/php-di": "4.4.11", - "doctrine/annotations": "1.2" + "doctrine/annotations": "1.2", + "rlanvin/php-rrule": "1.6.0" } } diff --git a/api/composer.lock b/api/composer.lock index 1668fba8..14ef8855 100644 --- a/api/composer.lock +++ b/api/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "cba4f6a9b461d9050bd4095da7c79aea", + "content-hash": "271633d6be53dff4f327e318b49a049f", "packages": [ { "name": "container-interop/container-interop", @@ -690,18 +690,62 @@ ], "time": "2017-02-14T16:28:37+00:00" }, + { + "name": "rlanvin/php-rrule", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/rlanvin/php-rrule.git", + "reference": "c543bda87d2f8b6c490210f1a6e2bf0d79162a4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rlanvin/php-rrule/zipball/c543bda87d2f8b6c490210f1a6e2bf0d79162a4a", + "reference": "c543bda87d2f8b6c490210f1a6e2bf0d79162a4a", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "<6" + }, + "suggest": { + "ext-intl": "Intl extension is needed for humanReadable()" + }, + "type": "library", + "autoload": { + "psr-4": { + "RRule\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Lightweight and fast recurrence rules for PHP (RFC 5545)", + "homepage": "https://github.com/rlanvin/php-rrule", + "keywords": [ + "date", + "ical", + "recurrence", + "recurring", + "rrule" + ], + "time": "2017-10-11T12:23:40+00:00" + }, { "name": "symfony/event-dispatcher", - "version": "v2.8.28", + "version": "v2.8.33", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "7fe089232554357efb8d4af65ce209fc6e5a2186" + "reference": "d64be24fc1eba62f9daace8a8918f797fc8e87cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/7fe089232554357efb8d4af65ce209fc6e5a2186", - "reference": "7fe089232554357efb8d4af65ce209fc6e5a2186", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d64be24fc1eba62f9daace8a8918f797fc8e87cc", + "reference": "d64be24fc1eba62f9daace8a8918f797fc8e87cc", "shasum": "" }, "require": { @@ -748,7 +792,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-10-01T21:00:16+00:00" + "time": "2018-01-03T07:36:31+00:00" }, { "name": "zendframework/zend-code", @@ -1334,29 +1378,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.1.1", + "version": "4.2.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2" + "reference": "66465776cfc249844bde6d117abff1d22e06c2da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/2d3d238c433cf69caeb4842e97a3223a116f94b2", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/66465776cfc249844bde6d117abff1d22e06c2da", + "reference": "66465776cfc249844bde6d117abff1d22e06c2da", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -1375,7 +1425,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-08-30T18:51:59+00:00" + "time": "2017-11-27T17:38:31+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1426,16 +1476,16 @@ }, { "name": "phpspec/prophecy", - "version": "v1.7.2", + "version": "1.7.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6" + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", "shasum": "" }, "require": { @@ -1447,7 +1497,7 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7" }, "type": "library", "extra": { @@ -1485,20 +1535,20 @@ "spy", "stub" ], - "time": "2017-09-04T11:05:03+00:00" + "time": "2017-11-24T13:59:53+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "5.2.3", + "version": "5.3.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "8e1d2397d8adf59a3f12b2878a3aaa66d1ab189d" + "reference": "661f34d0bd3f1a7225ef491a70a020ad23a057a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/8e1d2397d8adf59a3f12b2878a3aaa66d1ab189d", - "reference": "8e1d2397d8adf59a3f12b2878a3aaa66d1ab189d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/661f34d0bd3f1a7225ef491a70a020ad23a057a1", + "reference": "661f34d0bd3f1a7225ef491a70a020ad23a057a1", "shasum": "" }, "require": { @@ -1507,14 +1557,13 @@ "php": "^7.0", "phpunit/php-file-iterator": "^1.4.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^2.0", + "phpunit/php-token-stream": "^2.0.1", "sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/environment": "^3.0", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": "^2.5", "phpunit/phpunit": "^6.0" }, "suggest": { @@ -1523,7 +1572,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.2.x-dev" + "dev-master": "5.3.x-dev" } }, "autoload": { @@ -1538,7 +1587,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1549,20 +1598,20 @@ "testing", "xunit" ], - "time": "2017-11-03T13:47:33+00:00" + "time": "2017-12-06T09:29:45+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "1.4.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", "shasum": "" }, "require": { @@ -1596,7 +1645,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -1690,16 +1739,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0" + "reference": "791198a2c6254db10131eecfe8c06670700904db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/9a02332089ac48e704c70f6cefed30c224e3c0b0", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", "shasum": "" }, "require": { @@ -1735,7 +1784,7 @@ "keywords": [ "tokenizer" ], - "time": "2017-08-20T05:47:52+00:00" + "time": "2017-11-27T05:48:46+00:00" }, { "name": "phpunit/phpunit", @@ -1974,16 +2023,16 @@ }, { "name": "sebastian/comparator", - "version": "2.1.0", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158" + "reference": "11c07feade1d65453e06df3b3b90171d6d982087" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1174d9018191e93cb9d719edec01257fc05f8158", - "reference": "1174d9018191e93cb9d719edec01257fc05f8158", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/11c07feade1d65453e06df3b3b90171d6d982087", + "reference": "11c07feade1d65453e06df3b3b90171d6d982087", "shasum": "" }, "require": { @@ -2034,7 +2083,7 @@ "compare", "equality" ], - "time": "2017-11-03T07:16:52+00:00" + "time": "2018-01-12T06:34:42+00:00" }, { "name": "sebastian/diff", @@ -2488,16 +2537,16 @@ }, { "name": "symfony/console", - "version": "v2.8.28", + "version": "v2.8.33", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "f81549d2c5fdee8d711c9ab3c7e7362353ea5853" + "reference": "a4bd0f02ea156cf7b5138774a7ba0ab44d8da4fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/f81549d2c5fdee8d711c9ab3c7e7362353ea5853", - "reference": "f81549d2c5fdee8d711c9ab3c7e7362353ea5853", + "url": "https://api.github.com/repos/symfony/console/zipball/a4bd0f02ea156cf7b5138774a7ba0ab44d8da4fe", + "reference": "a4bd0f02ea156cf7b5138774a7ba0ab44d8da4fe", "shasum": "" }, "require": { @@ -2545,7 +2594,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-10-01T21:00:16+00:00" + "time": "2018-01-03T07:36:31+00:00" }, { "name": "symfony/debug", From 78cb2de9b6767bd005a00b466a948df3802c78aa Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Fri, 19 Jan 2018 22:17:15 -0500 Subject: [PATCH 15/20] Going to use rrule.js instead --- api/BusinessLogic/Calendar/CalendarEvent.php | 2 + .../Calendar/CalendarController.php | 2 + api/composer.json | 3 +- api/composer.lock | 46 +------------------ 4 files changed, 6 insertions(+), 47 deletions(-) diff --git a/api/BusinessLogic/Calendar/CalendarEvent.php b/api/BusinessLogic/Calendar/CalendarEvent.php index 91a45761..9e974b01 100644 --- a/api/BusinessLogic/Calendar/CalendarEvent.php +++ b/api/BusinessLogic/Calendar/CalendarEvent.php @@ -18,4 +18,6 @@ class CalendarEvent extends AbstractEvent { public $reminderValue; public $reminderUnits; + + public $recurringRule; } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index 0953b585..2c84270a 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -15,6 +15,7 @@ use BusinessLogic\Security\UserPrivilege; use BusinessLogic\ValidationModel; use Controllers\JsonRetriever; use DataAccess\Settings\ModsForHeskSettingsGateway; +use RRule\RRule; class CalendarController extends \BaseClass { function get() { @@ -117,6 +118,7 @@ class CalendarController extends \BaseClass { $event->categoryId = Helpers::safeArrayGet($json, 'categoryId'); $event->reminderValue = Helpers::safeArrayGet($json, 'reminderValue'); $event->reminderUnits = ReminderUnit::getByName(Helpers::safeArrayGet($json, 'reminderUnits')); + $event->recurringRule = Helpers::safeArrayGet($json, 'recurringRule'); return $event; } diff --git a/api/composer.json b/api/composer.json index c7215460..b91d34b5 100644 --- a/api/composer.json +++ b/api/composer.json @@ -17,7 +17,6 @@ "phpmailer/phpmailer": "^5.2", "mailgun/mailgun-php": "1.7.2", "mike-koch/php-di": "4.4.11", - "doctrine/annotations": "1.2", - "rlanvin/php-rrule": "1.6.0" + "doctrine/annotations": "1.2" } } diff --git a/api/composer.lock b/api/composer.lock index 14ef8855..f882508e 100644 --- a/api/composer.lock +++ b/api/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "271633d6be53dff4f327e318b49a049f", + "content-hash": "cba4f6a9b461d9050bd4095da7c79aea", "packages": [ { "name": "container-interop/container-interop", @@ -690,50 +690,6 @@ ], "time": "2017-02-14T16:28:37+00:00" }, - { - "name": "rlanvin/php-rrule", - "version": "v1.6.0", - "source": { - "type": "git", - "url": "https://github.com/rlanvin/php-rrule.git", - "reference": "c543bda87d2f8b6c490210f1a6e2bf0d79162a4a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/rlanvin/php-rrule/zipball/c543bda87d2f8b6c490210f1a6e2bf0d79162a4a", - "reference": "c543bda87d2f8b6c490210f1a6e2bf0d79162a4a", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "<6" - }, - "suggest": { - "ext-intl": "Intl extension is needed for humanReadable()" - }, - "type": "library", - "autoload": { - "psr-4": { - "RRule\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Lightweight and fast recurrence rules for PHP (RFC 5545)", - "homepage": "https://github.com/rlanvin/php-rrule", - "keywords": [ - "date", - "ical", - "recurrence", - "recurring", - "rrule" - ], - "time": "2017-10-11T12:23:40+00:00" - }, { "name": "symfony/event-dispatcher", "version": "v2.8.33", From 770a01a970a2c44ff7be6cec3105b35e13c63c39 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 21 Jan 2018 22:03:54 -0500 Subject: [PATCH 16/20] Add status to ticket popover on calendar --- admin/calendar.php | 10 +++++++++- api/BusinessLogic/Calendar/CalendarEvent.php | 2 -- api/BusinessLogic/Calendar/TicketEvent.php | 2 ++ api/Controllers/Calendar/CalendarController.php | 3 ++- api/DataAccess/Calendar/CalendarGateway.php | 6 +++++- .../mods-for-hesk-calendar-admin-readonly.js | 16 ++++++++++++---- js/calendar/mods-for-hesk-calendar.js | 15 ++++++++++++--- 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/admin/calendar.php b/admin/calendar.php index 905cc81d..4fc81a57 100644 --- a/admin/calendar.php +++ b/admin/calendar.php @@ -545,6 +545,10 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); +
+ + +
@@ -560,7 +564,11 @@ echo mfh_get_hidden_fields_for_language(array('error_loading_events', 'event_updated', 'error_updating_event', 'ticket_due_date_updated', - 'error_updating_ticket_due_date')); + 'error_updating_ticket_due_date', + 'critical', + 'high', + 'medium', + 'low')); ?>

diff --git a/api/BusinessLogic/Calendar/CalendarEvent.php b/api/BusinessLogic/Calendar/CalendarEvent.php index 9e974b01..91a45761 100644 --- a/api/BusinessLogic/Calendar/CalendarEvent.php +++ b/api/BusinessLogic/Calendar/CalendarEvent.php @@ -18,6 +18,4 @@ class CalendarEvent extends AbstractEvent { public $reminderValue; public $reminderUnits; - - public $recurringRule; } \ No newline at end of file diff --git a/api/BusinessLogic/Calendar/TicketEvent.php b/api/BusinessLogic/Calendar/TicketEvent.php index e2e7102f..95bf621d 100644 --- a/api/BusinessLogic/Calendar/TicketEvent.php +++ b/api/BusinessLogic/Calendar/TicketEvent.php @@ -15,4 +15,6 @@ class TicketEvent extends AbstractEvent { public $owner; public $priority; + + public $status; } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index 2c84270a..4b7ab9cd 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -5,6 +5,7 @@ namespace Controllers\Calendar; use BusinessLogic\Calendar\CalendarEvent; use BusinessLogic\Calendar\CalendarHandler; +use BusinessLogic\Calendar\RecurringRule; use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Categories\CategoryHandler; @@ -16,6 +17,7 @@ use BusinessLogic\ValidationModel; use Controllers\JsonRetriever; use DataAccess\Settings\ModsForHeskSettingsGateway; use RRule\RRule; +use RRule\RSet; class CalendarController extends \BaseClass { function get() { @@ -118,7 +120,6 @@ class CalendarController extends \BaseClass { $event->categoryId = Helpers::safeArrayGet($json, 'categoryId'); $event->reminderValue = Helpers::safeArrayGet($json, 'reminderValue'); $event->reminderUnits = ReminderUnit::getByName(Helpers::safeArrayGet($json, 'reminderUnits')); - $event->recurringRule = Helpers::safeArrayGet($json, 'recurringRule'); return $event; } diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index ddb263e6..1693e23d 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -86,13 +86,16 @@ class CalendarGateway extends CommonDao { $sql = "SELECT `tickets`.`id` AS `id`, `trackid`, `subject`, `due_date`, `category`, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, CASE WHEN `due_date` < '{$currentDate}' THEN 1 ELSE 0 END AS `overdue`, `owner`.`name` AS `owner_name`, `tickets`.`owner` AS `owner_id`, - `tickets`.`priority` AS `priority` + `tickets`.`priority` AS `priority`, `text_to_status_xref`.`text` AS `status_name` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` AS `tickets` INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` ON `categories`.`id` = `tickets`.`category` AND `categories`.`usage` <> 2 LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner` ON `tickets`.`owner` = `owner`.`id` + LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "text_to_status_xref` AS `text_to_status_xref` + ON `tickets`.`status` = `text_to_status_xref`.`status_id` + AND `text_to_status_xref`.`language` = '" . hesk_dbEscape($heskSettings['language']) . "' WHERE `due_date` >= {$startTimeSql} AND `due_date` <= {$endTimeSql} AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) @@ -129,6 +132,7 @@ class CalendarGateway extends CommonDao { $event->displayBorder = Helpers::boolval($row['display_border']); $event->owner = $row['owner_name']; $event->priority = Priority::getByValue($row['priority']); + $event->status = $row['status_name']; $events[] = $event; } diff --git a/js/calendar/mods-for-hesk-calendar-admin-readonly.js b/js/calendar/mods-for-hesk-calendar-admin-readonly.js index 7290189e..51f2b763 100644 --- a/js/calendar/mods-for-hesk-calendar-admin-readonly.js +++ b/js/calendar/mods-for-hesk-calendar-admin-readonly.js @@ -62,7 +62,8 @@ $(document).ready(function() { .find('.popover-owner span').text(event.owner).end() .find('.popover-subject span').text(event.subject).end() .find('.popover-category span').text(event.categoryName).end() - .find('.popover-priority span').text(event.priority); + .find('.popover-priority span').text(event.priority) + .find('.popover-status span').text(event.status).end(); } else { if (event.location === '') { $contents.find('.popover-location').hide(); @@ -125,7 +126,13 @@ $(document).ready(function() { }); function buildEvent(id, dbObject) { - if (dbObject.type == 'TICKET') { + var priorities = []; + priorities['CRITICAL'] = mfhLang.text('critical'); + priorities['HIGH'] = mfhLang.text('high'); + priorities['MEDIUM'] = mfhLang.text('medium'); + priorities['LOW'] = mfhLang.text('low'); + + if (dbObject.type === 'TICKET') { return { title: dbObject.title, subject: dbObject.subject, @@ -141,8 +148,9 @@ function buildEvent(id, dbObject) { categoryName: dbObject.categoryName, className: 'category-' + dbObject.categoryId, owner: dbObject.owner, - priority: dbObject.priority, - fontIconMarkup: getIcon(dbObject) + priority: priorities[dbObject.priority], + fontIconMarkup: getIcon(dbObject), + status: dbObject.status }; } diff --git a/js/calendar/mods-for-hesk-calendar.js b/js/calendar/mods-for-hesk-calendar.js index 48fac68f..7551e2d7 100644 --- a/js/calendar/mods-for-hesk-calendar.js +++ b/js/calendar/mods-for-hesk-calendar.js @@ -66,7 +66,8 @@ $(document).ready(function() { .find('.popover-owner span').text(event.owner).end() .find('.popover-subject span').text(event.subject).end() .find('.popover-category span').text(event.categoryName).end() - .find('.popover-priority span').text(event.priority); + .find('.popover-priority span').text(event.priority).end() + .find('.popover-status span').text(event.status).end(); } else { if (event.allDay) { endDate = event.end.clone(); @@ -298,6 +299,13 @@ function removeFromCalendar(id) { } function buildEvent(id, dbObject) { + var priorities = []; + priorities['CRITICAL'] = mfhLang.text('critical'); + priorities['HIGH'] = mfhLang.text('high'); + priorities['MEDIUM'] = mfhLang.text('medium'); + priorities['LOW'] = mfhLang.text('low'); + + if (dbObject.type === 'TICKET') { return { id: id, @@ -315,8 +323,9 @@ function buildEvent(id, dbObject) { categoryName: dbObject.categoryName, className: 'category-' + dbObject.categoryId, owner: dbObject.owner, - priority: dbObject.priority, - fontIconMarkup: getIcon(dbObject) + priority: priorities[dbObject.priority], + fontIconMarkup: getIcon(dbObject), + status: dbObject.status }; } From 1a66485d48478f1b228d83920adef0ae107368ab Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Tue, 23 Jan 2018 22:14:25 -0500 Subject: [PATCH 17/20] Working on adding audit trail to events --- .../Calendar/CalendarHandler.php | 35 +++++++++++++++++-- .../Tickets/AuditTrailEntityType.php | 1 + .../Calendar/CalendarController.php | 3 +- api/DataAccess/Calendar/CalendarGateway.php | 32 +++++++++++++++++ language/en/text.php | 4 +++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/api/BusinessLogic/Calendar/CalendarHandler.php b/api/BusinessLogic/Calendar/CalendarHandler.php index ad5a1775..2c4967d1 100644 --- a/api/BusinessLogic/Calendar/CalendarHandler.php +++ b/api/BusinessLogic/Calendar/CalendarHandler.php @@ -3,14 +3,20 @@ namespace BusinessLogic\Calendar; +use BusinessLogic\DateTimeHelpers; use BusinessLogic\Security\UserContext; +use BusinessLogic\Tickets\AuditTrailEntityType; +use DataAccess\AuditTrail\AuditTrailGateway; use DataAccess\Calendar\CalendarGateway; class CalendarHandler extends \BaseClass { private $calendarGateway; + private $auditTrailGateway; - public function __construct(CalendarGateway $calendarGateway) { + public function __construct(CalendarGateway $calendarGateway, + AuditTrailGateway $auditTrailGateway) { $this->calendarGateway = $calendarGateway; + $this->auditTrailGateway = $auditTrailGateway; } public function getEventsForStaff($searchEventsFilter, $heskSettings) { @@ -37,10 +43,25 @@ class CalendarHandler extends \BaseClass { throw new \Exception("Expected exactly 1 event, found: " . count($events)); } - return $events[0]; + $event = $events[0]; + + $this->auditTrailGateway->insertAuditTrailRecord($event->id, + AuditTrailEntityType::CALENDAR_EVENT, + 'audit_event_updated', + DateTimeHelpers::heskDate($heskSettings), + array(0 => $userContext->name . ' (' . $userContext->username . ')'), $heskSettings); + + return $event; } + /** + * @param $calendarEvent CalendarEvent + * @param $userContext UserContext + * @param $heskSettings array + * @return AbstractEvent + * @throws \Exception + */ public function createEvent($calendarEvent, $userContext, $heskSettings) { $this->calendarGateway->createEvent($calendarEvent, $userContext, $heskSettings); @@ -54,7 +75,15 @@ class CalendarHandler extends \BaseClass { throw new \Exception("Expected exactly 1 event, found: " . count($events)); } - return $events[0]; + $event = $events[0]; + + $this->auditTrailGateway->insertAuditTrailRecord($event->id, + AuditTrailEntityType::CALENDAR_EVENT, + 'audit_event_created', + DateTimeHelpers::heskDate($heskSettings), + array(0 => $userContext->name . ' (' . $userContext->username . ')'), $heskSettings); + + return $event; } public function deleteEvent($id, $userContext, $heskSettings) { diff --git a/api/BusinessLogic/Tickets/AuditTrailEntityType.php b/api/BusinessLogic/Tickets/AuditTrailEntityType.php index feea16f6..dafcad42 100644 --- a/api/BusinessLogic/Tickets/AuditTrailEntityType.php +++ b/api/BusinessLogic/Tickets/AuditTrailEntityType.php @@ -5,4 +5,5 @@ namespace BusinessLogic\Tickets; class AuditTrailEntityType extends \BaseClass { const TICKET = 'TICKET'; + const CALENDAR_EVENT = 'CALENDAR_EVENT'; } \ No newline at end of file diff --git a/api/Controllers/Calendar/CalendarController.php b/api/Controllers/Calendar/CalendarController.php index 4b7ab9cd..0440f54a 100644 --- a/api/Controllers/Calendar/CalendarController.php +++ b/api/Controllers/Calendar/CalendarController.php @@ -69,6 +69,7 @@ class CalendarController extends \BaseClass { function post() { /* @var $userContext UserContext */ + /* @var $hesk_settings array */ global $applicationContext, $hesk_settings, $userContext; $json = JsonRetriever::getJsonData(); @@ -78,7 +79,7 @@ class CalendarController extends \BaseClass { /* @var $calendarHandler CalendarHandler */ $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); - return output($calendarHandler->createEvent($event, $userContext, $hesk_settings)); + return output($calendarHandler->createEvent($event, $userContext, $hesk_settings), 201); } function put($id) { diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 1693e23d..705651d0 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -10,6 +10,8 @@ use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Calendar\TicketEvent; use BusinessLogic\Helpers; use BusinessLogic\Security\UserContext; +use BusinessLogic\Tickets\AuditTrail; +use BusinessLogic\Tickets\AuditTrailEntityType; use Core\Constants\Priority; use DataAccess\CommonDao; use DataAccess\Logging\LoggingGateway; @@ -73,6 +75,36 @@ class CalendarGateway extends CommonDao { $event->reminderValue = $row['reminder_value'] === null ? null : floatval($row['reminder_value']); $event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']); + $auditTrailSql = "SELECT `at`.`id` AS `id`, `at`.`entity_id`, `at`.`language_key`, `at`.`date`, + `values`.`replacement_index`, `values`.`replacement_values` + FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail` AS `at` + INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail_to_replacement_values` AS `values` + ON `at`.`id` = `values`.`audit_trail_id` + WHERE `entity_id` = " . intval($event->id) . " + AND `entity_type` = '" . AuditTrailEntityType::CALENDAR_EVENT . "'"; + $auditTrailRs = hesk_dbFetchAssoc($auditTrailSql); + $auditTrailEntry = null; + while ($row = hesk_dbFetchAssoc($rs)) { + if ($auditTrailEntry == null || intval($auditTrailEntry['id']) !== intval($row['id'])) { + if ($auditTrailEntry !== null) { + //$audit_records[] = $auditTrailEntry; + } + + $auditTrailEntry = new AuditTrail(); + $auditTrailEntry->id = $row['id']; + $auditTrailEntry->entityId = $row['entity_id']; + $auditTrailEntry->entityType = AuditTrailEntityType::CALENDAR_EVENT; + $auditTrailEntry->languageKey = $row['language_key']; + $auditTrailEntry->date = $row['date']; + $auditTrailEntry->replacementValues = array(); + } + $auditTrailEntry->replacementValues[intval($row['replacement_index'])] = $row['replacement_value']; + } + + if ($auditTrailEntry !== null) { + //$event->auditTrail[] = $audiTrailEntry; + } + $events[] = $event; } diff --git a/language/en/text.php b/language/en/text.php index e55cd0e4..6f5e9838 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -2214,5 +2214,9 @@ $hesklang['audit_due_date_changed'] = '%s changed due date to %s'; $hesklang['audit_linked_ticket'] = '%s linked ticket %s to this ticket'; $hesklang['audit_unlinked_ticket'] = '%s unlinked ticket %s'; +// Added or modified in Mods for HESK 3.3.0 +$hesklang['audit_event_created'] = '%s created event'; +$hesklang['audit_event_updated'] = '%s updated event'; + // DO NOT CHANGE BELOW if (!defined('IN_SCRIPT')) die('PHP syntax OK!'); From ad63bcac0298a35c182cb87e168ba7f7e6a963b5 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 24 Jan 2018 13:01:23 -0500 Subject: [PATCH 18/20] Fixed a couple issues with the audit trail changes --- api/BusinessLogic/Calendar/CalendarEvent.php | 5 +++++ api/DataAccess/Calendar/CalendarGateway.php | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/api/BusinessLogic/Calendar/CalendarEvent.php b/api/BusinessLogic/Calendar/CalendarEvent.php index 91a45761..967ae3ea 100644 --- a/api/BusinessLogic/Calendar/CalendarEvent.php +++ b/api/BusinessLogic/Calendar/CalendarEvent.php @@ -3,6 +3,8 @@ namespace BusinessLogic\Calendar; +use BusinessLogic\Tickets\AuditTrail; + class CalendarEvent extends AbstractEvent { public $type = 'CALENDAR'; @@ -18,4 +20,7 @@ class CalendarEvent extends AbstractEvent { public $reminderValue; public $reminderUnits; + + /* @var $auditTrail AuditTrail[] */ + public $auditTrail = array(); } \ No newline at end of file diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index 705651d0..3561631c 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -76,23 +76,24 @@ class CalendarGateway extends CommonDao { $event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']); $auditTrailSql = "SELECT `at`.`id` AS `id`, `at`.`entity_id`, `at`.`language_key`, `at`.`date`, - `values`.`replacement_index`, `values`.`replacement_values` + `values`.`replacement_index`, `values`.`replacement_value` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail` AS `at` INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail_to_replacement_values` AS `values` ON `at`.`id` = `values`.`audit_trail_id` WHERE `entity_id` = " . intval($event->id) . " AND `entity_type` = '" . AuditTrailEntityType::CALENDAR_EVENT . "'"; - $auditTrailRs = hesk_dbFetchAssoc($auditTrailSql); + $auditTrailRs = hesk_dbQuery($auditTrailSql); + /* @var $auditTrailEntry AuditTrail */ $auditTrailEntry = null; - while ($row = hesk_dbFetchAssoc($rs)) { - if ($auditTrailEntry == null || intval($auditTrailEntry['id']) !== intval($row['id'])) { + while ($row = hesk_dbFetchAssoc($auditTrailRs)) { + if ($auditTrailEntry == null || intval($auditTrailEntry->id) !== intval($row['id'])) { if ($auditTrailEntry !== null) { - //$audit_records[] = $auditTrailEntry; + $event->auditTrail[] = $auditTrailEntry; } $auditTrailEntry = new AuditTrail(); - $auditTrailEntry->id = $row['id']; - $auditTrailEntry->entityId = $row['entity_id']; + $auditTrailEntry->id = intval($row['id']); + $auditTrailEntry->entityId = intval($row['entity_id']); $auditTrailEntry->entityType = AuditTrailEntityType::CALENDAR_EVENT; $auditTrailEntry->languageKey = $row['language_key']; $auditTrailEntry->date = $row['date']; @@ -102,7 +103,7 @@ class CalendarGateway extends CommonDao { } if ($auditTrailEntry !== null) { - //$event->auditTrail[] = $audiTrailEntry; + $event->auditTrail[] = $auditTrailEntry; } $events[] = $event; From 401e335e5f976045a2c82e97977d48aad79ae8fe Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 24 Jan 2018 22:00:10 -0500 Subject: [PATCH 19/20] Adding history to modal --- admin/calendar.php | 285 +++++++++++++++++++++++++-------------------- 1 file changed, 156 insertions(+), 129 deletions(-) diff --git a/admin/calendar.php b/admin/calendar.php index 4fc81a57..b9be4bab 100644 --- a/admin/calendar.php +++ b/admin/calendar.php @@ -334,147 +334,174 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');