From 5b7c2f7ec7afbf553005f74c13616c9e1f92ae56 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sat, 9 Sep 2017 22:03:42 -0400 Subject: [PATCH] Remove all manager usages --- README.md | 1 - admin/admin_reply_ticket.php | 6 +-- admin/admin_ticket.php | 51 ++++--------------- admin/change_status.php | 6 +-- admin/edit_post.php | 13 ++--- admin/manage_users.php | 36 ------------- api/BusinessLogic/Categories/Category.php | 5 -- .../Security/UserToTicketChecker.php | 6 --- .../Categories/CategoryController.php | 1 - api/DataAccess/Categories/CategoryGateway.php | 6 +-- api/DataAccess/Security/UserGateway.php | 21 -------- .../Security/UserToTicketCheckerTest.php | 19 ------- inc/common.inc.php | 1 - install/mods-for-hesk/database-validation.php | 1 - language/en/text.php | 4 -- 15 files changed, 19 insertions(+), 158 deletions(-) diff --git a/README.md b/README.md index a53bd5d5..ea4cdd5d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,6 @@ Mods for HESK is a set of modifications for [HESK](https://www.hesk.com) v2.7.x,
  • Custom service message icons
  • Permission templates
  • Request users location in tickets
  • -
  • Category managers
  • Show number of merged tickets in ticket search view
  • Enable / disable staff members
  • More-restricted settings page access
  • diff --git a/admin/admin_reply_ticket.php b/admin/admin_reply_ticket.php index 96ab9f9f..aa373e96 100644 --- a/admin/admin_reply_ticket.php +++ b/admin/admin_reply_ticket.php @@ -39,9 +39,7 @@ hesk_dbConnect(); hesk_isLoggedIn(); /* Check permissions for this feature */ -if (!isset($_REQUEST['isManager']) || !$_REQUEST['isManager']) { - hesk_checkPermission('can_reply_tickets'); -} +hesk_checkPermission('can_reply_tickets'); /* A security check */ # hesk_token_check('POST'); @@ -281,7 +279,7 @@ if ($time_worked == '00:00:00') { $sql .= ",`time_worked` = ADDTIME(`time_worked`,'" . hesk_dbEscape($time_worked) . "') "; } -if (!empty($_POST['assign_self']) && (hesk_checkPermission('can_assign_self', 0) || (isset($_REQUEST['isManager']) && $_REQUEST['isManager']))) { +if (!empty($_POST['assign_self']) && (hesk_checkPermission('can_assign_self', 0))) { $revision = sprintf($hesklang['thist2'], hesk_date(), $_SESSION['name'] . ' (' . $_SESSION['user'] . ')', $_SESSION['name'] . ' (' . $_SESSION['user'] . ')'); $sql .= " , `owner`=" . intval($_SESSION['id']) . ", `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') "; } diff --git a/admin/admin_ticket.php b/admin/admin_ticket.php index 899d37e6..3f7dfbf5 100644 --- a/admin/admin_ticket.php +++ b/admin/admin_ticket.php @@ -107,33 +107,14 @@ if ($ticket['lastreplier']) { } /* Get category name and ID */ -$result = hesk_dbQuery("SELECT `id`, `name`, `manager` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` WHERE `id`='" . intval($ticket['category']) . "' LIMIT 1"); +$result = hesk_dbQuery("SELECT `id`, `name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` WHERE `id`='" . intval($ticket['category']) . "' LIMIT 1"); /* If this category has been deleted use the default category with ID 1 */ if (hesk_dbNumRows($result) != 1) { - $result = hesk_dbQuery("SELECT `id`, `name`, `manager` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` WHERE `id`='1' LIMIT 1"); + $result = hesk_dbQuery("SELECT `id`, `name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` WHERE `id`='1' LIMIT 1"); } $category = hesk_dbFetchAssoc($result); -$managerRS = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'users` WHERE `id` = ' . intval($_SESSION['id'])); -$managerRow = hesk_dbFetchAssoc($managerRS); -$isManager = $managerRow['id'] == $category['manager']; -if ($isManager) { - $can_del_notes = - $can_reply = - $can_delete = - $can_edit = - $can_archive = - $can_assign_self = - $can_view_unassigned = - $can_change_own_cat = - $can_change_cat = - $can_ban_emails = - $can_unban_emails = - $can_ban_ips = - $can_unban_ips = - $can_resolve = true; -} /* Is this user allowed to view tickets inside this category? */ hesk_okCategory($category['id']); @@ -973,9 +954,6 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); '; - if ($isManager) { - echo ''; - } echo ' @@ -999,15 +977,12 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); '; - if ($isManager) { - echo ''; - } echo ' '; echo '

    ' . $hesklang['owner'] . '

    '; - if (hesk_checkPermission('can_assign_others', 0) || $isManager) { + if (hesk_checkPermission('can_assign_others', 0)) { echo '
    @@ -1250,15 +1225,14 @@ require_once(HESK_PATH . 'inc/footer.inc.php'); function hesk_getAdminButtons($category_id) { - global $hesk_settings, $hesklang, $modsForHesk_settings, $ticket, $reply, $trackingID, $can_edit, $can_archive, $can_delete, $can_resolve, $isManager; + global $hesk_settings, $hesklang, $modsForHesk_settings, $ticket, $reply, $trackingID, $can_edit, $can_archive, $can_delete, $can_resolve; $options = ''; /* Edit post */ if ($can_edit) { $tmp = $reply ? '&reply=' . $reply['id'] : ''; - $mgr = $isManager ? '&isManager=true' : ''; - $options .= ' ' . $hesklang['edit'] . ' '; + $options .= ' ' . $hesklang['edit'] . ' '; } @@ -1304,13 +1278,12 @@ function hesk_getAdminButtons($category_id) $isTicketClosed = $isTicketClosedRow['IsClosed']; $isClosable = $isTicketClosedRow['Closable'] == 'yes' || $isTicketClosedRow['Closable'] == 'sonly'; - $mgr = $isManager ? '&isManager=1' : ''; if ($isTicketClosed == 0 && $isClosable && $can_resolve) // Ticket is still open { - $options .= ' + $options .= ' ' . $hesklang['close_action'] . ' '; } elseif ($isTicketClosed == 1) { - $options .= ' + $options .= ' ' . $hesklang['open_action'] . ' '; } @@ -1496,7 +1469,7 @@ function hesk_getAdminButtons($category_id) function hesk_getAdminButtonsInTicket($reply = 0, $white = 1) { - global $hesk_settings, $hesklang, $ticket, $reply, $trackingID, $can_edit, $can_archive, $can_delete, $isManager; + global $hesk_settings, $hesklang, $ticket, $reply, $trackingID, $can_edit, $can_archive, $can_delete; $options = $reply ? '' : '
    '; @@ -1519,8 +1492,7 @@ function hesk_getAdminButtonsInTicket($reply = 0, $white = 1) /* Edit post */ if ($can_edit) { $tmp = $reply ? '&reply=' . $reply['id'] : ''; - $mgr = $isManager ? '&isManager=true' : ''; - $options .= ' ' . $hesklang['edtt'] . ' '; + $options .= ' ' . $hesklang['edtt'] . ' '; } @@ -1834,7 +1806,7 @@ function hesk_printTicketReplies() function hesk_printReplyForm() { - global $hesklang, $hesk_settings, $ticket, $admins, $can_options, $can_resolve, $options, $can_assign_self, $isManager, $modsForHesk_settings; + global $hesklang, $hesk_settings, $ticket, $admins, $can_options, $can_resolve, $options, $can_assign_self, $modsForHesk_settings; // Force assigning a ticket before allowing to reply? if ($hesk_settings['require_owner'] && ! $ticket['owner']) @@ -2056,9 +2028,6 @@ function hesk_printReplyForm()
    - - -
    diff --git a/admin/change_status.php b/admin/change_status.php index 42d002f1..d1d6551a 100644 --- a/admin/change_status.php +++ b/admin/change_status.php @@ -26,10 +26,8 @@ hesk_isLoggedIn(); $modsForHesk_settings = mfh_getSettings(); /* Check permissions for this feature */ -if (!isset($_REQUEST['isManager']) || !$_REQUEST['isManager']) { - hesk_checkPermission('can_view_tickets'); - hesk_checkPermission('can_reply_tickets'); -} +hesk_checkPermission('can_view_tickets'); +hesk_checkPermission('can_reply_tickets'); /* A security check */ hesk_token_check(); diff --git a/admin/edit_post.php b/admin/edit_post.php index ee3a9e19..7dcdda44 100644 --- a/admin/edit_post.php +++ b/admin/edit_post.php @@ -32,10 +32,8 @@ hesk_dbConnect(); hesk_isLoggedIn(); /* Check permissions for this feature */ -if (!isset($_REQUEST['isManager']) || !$_REQUEST['isManager']) { - hesk_checkPermission('can_view_tickets'); - hesk_checkPermission('can_edit_tickets'); -} +hesk_checkPermission('can_view_tickets'); +hesk_checkPermission('can_edit_tickets'); $modsForHesk_settings = mfh_getSettings(); /* Ticket ID */ @@ -61,9 +59,7 @@ if (defined('HESK_DEMO')) { } /* Is this user allowed to view tickets inside this category? */ -if (!isset($_REQUEST['isManager']) || !$_REQUEST['isManager']) { - hesk_okCategory($ticket['category']); -} +hesk_okCategory($ticket['category']); if (hesk_isREQUEST('reply')) { $tmpvar['id'] = intval(hesk_REQUEST('reply')) or die($hesklang['id_not_valid']); @@ -630,9 +626,6 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); ?> - - - diff --git a/admin/manage_users.php b/admin/manage_users.php index 2ed5999a..4159d638 100644 --- a/admin/manage_users.php +++ b/admin/manage_users.php @@ -621,31 +621,6 @@ function update_user() hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `owner`=0 WHERE `owner`='" . intval($myuser['id']) . "' AND `category` NOT IN (" . $myuser['categories'] . ")"); } - // Find the list of categories they are manager of. If they no longer have access to the category, revoke their manager permission. - if ($myuser['isadmin']) { - // Admins can't be managers - hesk_dbQuery('UPDATE `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'categories` SET `manager` = 0 WHERE `manager` = ' . intval($myuser['id'])); - } else { - $currentCatRs = hesk_dbQuery("SELECT `categories` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `id` = '" . intval($myuser['id']) . "' LIMIT 1"); - $rowOfCategories = hesk_dbFetchAssoc($currentCatRs); - $cats = $rowOfCategories['categories']; - $currentCategories = explode(',', $cats); - $newCategories = explode(',', $myuser['categories']); - - // If any any elements are in current but not in new, add them to the revoke array - $revokeCats = array(); - foreach ($currentCategories as $currentCategory) { - if (!in_array($currentCategory, $newCategories) && $currentCategory != '') { - array_push($revokeCats, $currentCategory); - } - } - - if (count($revokeCats) > 0) { - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` SET `manager` = 0 WHERE `id` IN (" . implode(',', $revokeCats) . ")"); - } - } - - hesk_dbQuery( "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `user`='" . hesk_dbEscape($myuser['user']) . "', @@ -676,11 +651,6 @@ function update_user() `default_calendar_view`=" . intval($myuser['default_calendar_view']) . " WHERE `id`='" . intval($myuser['id']) . "'"); - // If they are now inactive, remove any manager rights - if (!$myuser['active']) { - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` SET `manager` = 0 WHERE `manager` = " . intval($myuser['id'])); - } - unset($_SESSION['save_userdata']); unset($_SESSION['userdata']); @@ -844,9 +814,6 @@ function remove() hesk_process_messages($hesklang['cant_del_own'], './manage_users.php'); } - // Revoke manager rights - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` SET `manager` = 0 WHERE `manager` = " . intval($myuser)); - /* Un-assign all tickets for this user */ $res = hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `owner`=0 WHERE `owner`='" . intval($myuser) . "'"); @@ -910,9 +877,6 @@ function toggle_active() $active = 0; $tmp = $hesklang['user_deactivated']; - // Revoke any manager rights - hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` SET `manager` = 0 WHERE `manager` = " . intval($myuser)); - $notificationSql = ", `autoassign` = '0', `notify_new_unassigned` = '0', `notify_new_my` = '0', `notify_reply_unassigned` = '0', `notify_reply_my` = '0', `notify_assigned` = '0', `notify_pm` = '0', `notify_note` = '0', `notify_note_unassigned` = '0', `notify_overdue_unassigned` = '0'"; } diff --git a/api/BusinessLogic/Categories/Category.php b/api/BusinessLogic/Categories/Category.php index e2c3db9b..bf17c56e 100644 --- a/api/BusinessLogic/Categories/Category.php +++ b/api/BusinessLogic/Categories/Category.php @@ -51,11 +51,6 @@ class Category { */ public $priority; - /** - * @var int|null The manager for the Categories, if applicable - */ - public $manager; - /** * @var bool Indication if the user has access to the Categories */ diff --git a/api/BusinessLogic/Security/UserToTicketChecker.php b/api/BusinessLogic/Security/UserToTicketChecker.php index 9a2f9c90..0f21d785 100644 --- a/api/BusinessLogic/Security/UserToTicketChecker.php +++ b/api/BusinessLogic/Security/UserToTicketChecker.php @@ -31,12 +31,6 @@ class UserToTicketChecker { return false; } - $categoryManagerId = $this->userGateway->getManagerForCategory($ticket->categoryId, $heskSettings); - - if ($user->id === $categoryManagerId) { - return true; - } - $extraPermissions[] = UserPrivilege::CAN_VIEW_TICKETS; foreach ($extraPermissions as $permission) { diff --git a/api/Controllers/Categories/CategoryController.php b/api/Controllers/Categories/CategoryController.php index e72f680b..0ef2bf75 100644 --- a/api/Controllers/Categories/CategoryController.php +++ b/api/Controllers/Categories/CategoryController.php @@ -63,7 +63,6 @@ class CategoryController { $category->description = Helpers::safeArrayGet($json, 'description'); $category->displayBorder = Helpers::safeArrayGet($json, 'displayBorder'); $category->foregroundColor = Helpers::safeArrayGet($json, 'foregroundColor'); - $category->manager = Helpers::safeArrayGet($json, 'manager'); $category->name = Helpers::safeArrayGet($json, 'name'); $category->priority = Helpers::safeArrayGet($json, 'priority'); $category->type = Helpers::safeArrayGet($json, 'type'); diff --git a/api/DataAccess/Categories/CategoryGateway.php b/api/DataAccess/Categories/CategoryGateway.php index 2191373d..1a4c0d1c 100644 --- a/api/DataAccess/Categories/CategoryGateway.php +++ b/api/DataAccess/Categories/CategoryGateway.php @@ -41,7 +41,6 @@ class CategoryGateway extends CommonDao { $category->foregroundColor = $row['foreground_color']; $category->displayBorder = $row['display_border_outline'] === '1'; $category->priority = intval($row['priority']); - $category->manager = intval($row['manager']) == 0 ? NULL : intval($row['manager']); $category->description = $row['mfh_description']; $category->numberOfTickets = intval($row['number_of_tickets']); $results[] = $category; @@ -64,11 +63,11 @@ class CategoryGateway extends CommonDao { $newOrder = hesk_dbFetchAssoc($newOrderRs); $sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` - (`name`, `cat_order`, `autoassign`, `type`, `priority`, `manager`, `background_color`, `usage`, + (`name`, `cat_order`, `autoassign`, `type`, `priority`, `background_color`, `usage`, `foreground_color`, `display_border_outline`, `mfh_description`) VALUES ('" . hesk_dbEscape($category->name) . "', " . intval($newOrder['cat_order']) . ", '" . ($category->autoAssign ? 1 : 0) . "', '" . intval($category->type) . "', - '" . intval($category->priority) . "', " . ($category->manager === null ? 0 : intval($category->manager)) . ", + '" . intval($category->priority) . "', '" . hesk_dbEscape($category->backgroundColor) . "', " . intval($category->usage) . ", '" . hesk_dbEscape($category->foregroundColor) . "', '" . ($category->displayBorder ? 1 : 0) . "', '" . hesk_dbEscape($category->description) . "')"; @@ -95,7 +94,6 @@ class CategoryGateway extends CommonDao { `autoassign` = '" . ($category->autoAssign ? 1 : 0) . "', `type` = '" . intval($category->type) . "', `priority` = '" . intval($category->priority) . "', - `manager` = " . ($category->manager === null ? 0 : intval($category->manager)) . ", `background_color` = '" . hesk_dbEscape($category->backgroundColor) . "', `usage` = " . intval($category->usage) . ", `foreground_color` = '" . hesk_dbEscape($category->foregroundColor) . "', diff --git a/api/DataAccess/Security/UserGateway.php b/api/DataAccess/Security/UserGateway.php index e836f18a..3ed4191b 100644 --- a/api/DataAccess/Security/UserGateway.php +++ b/api/DataAccess/Security/UserGateway.php @@ -99,25 +99,4 @@ class UserGateway extends CommonDao { return $users; } - - function getManagerForCategory($categoryId, $heskSettings) { - $this->init(); - - $rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` - WHERE `id` = ( - SELECT `manager` - FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` - WHERE `id` = " . intval($categoryId) . ")"); - - if (hesk_dbNumRows($rs) === 0) { - $this->close(); - return null; - } - - $user = UserContext::fromDataRow(hesk_dbFetchAssoc($rs)); - - $this->close(); - - return $user; - } } \ No newline at end of file diff --git a/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php b/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php index d3afb126..07318d66 100644 --- a/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php +++ b/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php @@ -92,23 +92,4 @@ class UserToTicketCheckerTest extends TestCase { //-- Assert self::assertThat($result, self::isFalse()); } - - function testItReturnsTrueWhenTheUserDoesNotHaveEditPermissionsButIsTheCategoryManager() { - //-- Arrange - $user = new UserContext(); - $user->admin = false; - $user->categories = array(1); - $user->permissions = array(UserPrivilege::CAN_VIEW_TICKETS, 'something else'); - $user->id = 1; - $this->userGateway->method('getManagerForCategory')->willReturn(1); - - $ticket = new Ticket(); - $ticket->categoryId = 1; - - //-- Act - $result = $this->userToTicketChecker->isTicketAccessibleToUser($user, $ticket, $this->heskSettings, array(UserPrivilege::CAN_EDIT_TICKETS)); - - //-- Assert - self::assertThat($result, self::isTrue()); - } } diff --git a/inc/common.inc.php b/inc/common.inc.php index 94f487dc..ec0ed464 100644 --- a/inc/common.inc.php +++ b/inc/common.inc.php @@ -2026,7 +2026,6 @@ function hesk_getFeatureArray() 'can_service_msg', /* User can manage service messages shown in customer interface */ 'can_email_tpl', /* User can manage email templates */ 'can_man_ticket_statuses', /* User can manage ticket statuses */ - 'can_set_manager', /* User can set category managers */ 'can_man_permission_tpl', /* User can manage permission templates */ 'can_man_settings', /* User can manage helpdesk settings */ 'can_change_notification_settings', /* User can change notification settings */ diff --git a/install/mods-for-hesk/database-validation.php b/install/mods-for-hesk/database-validation.php index 22c34c98..7f1534e8 100644 --- a/install/mods-for-hesk/database-validation.php +++ b/install/mods-for-hesk/database-validation.php @@ -93,7 +93,6 @@ hesk_dbConnect(); $all_good = $all_good & run_column_check('tickets', 'longitude'); $all_good = $all_good & run_column_check('stage_tickets', 'latitude'); $all_good = $all_good & run_column_check('stage_tickets', 'longitude'); - $all_good = $all_good & run_column_check('categories', 'manager'); $all_good = $all_good & run_column_check('users', 'permission_template'); $all_good = $all_good & run_table_check('permission_templates'); $all_good = $all_good & run_column_check('permission_templates', 'id'); diff --git a/language/en/text.php b/language/en/text.php index 743ed201..c7f35f4c 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -1831,10 +1831,6 @@ $hesklang['your_current_location'] = 'Your location'; $hesklang['requesting_location_ellipsis'] = 'Requesting location...'; $hesklang['unable_to_determine_location'] = 'Unable to determine your location, or you declined to share it.'; $hesklang['save_to_see_updated_address'] = 'Save the new location to see the updated address'; -$hesklang['manager'] = 'Manager'; -$hesklang['manager_updated'] = 'Category manager has been updated.'; -$hesklang['can_set_manager'] = 'Can set category managers'; -$hesklang['no_manager'] = 'No manager'; $hesklang['manage_permission_templates'] = 'Manage Permission Templates'; $hesklang['manage_permission_templates_help'] = 'Here you can create and edit permission templates. These templates will appear when creating/editing a user. Please note that if you change the permission template\'s settings, it will NOT change the permissions of any users that are set to this permission template.';