From 23c750e6b9f87af75a9b7fb421ea8f7cad242db7 Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Thu, 23 Jan 2020 16:48:18 -0300 Subject: [PATCH 1/5] fix priorities empty array problem --- server/controllers/ticket/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/ticket/search.php b/server/controllers/ticket/search.php index 09d2a020..8bcb85ca 100644 --- a/server/controllers/ticket/search.php +++ b/server/controllers/ticket/search.php @@ -207,7 +207,7 @@ class SearchController extends Controller { } } private function setPriorityFilter($priorities, &$filters){ - if($priorities !== null){ + if($priorities){ $first = TRUE; if ($filters != "") $filters .= " and "; foreach(array_unique($priorities) as $priority) { From b5639051f426b24830a33b3384c375f035ddb271 Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Thu, 23 Jan 2020 16:51:26 -0300 Subject: [PATCH 2/5] throw error when try to change title for a blank string --- server/controllers/ticket/edit-title.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/controllers/ticket/edit-title.php b/server/controllers/ticket/edit-title.php index f407d28d..19ec61c4 100644 --- a/server/controllers/ticket/edit-title.php +++ b/server/controllers/ticket/edit-title.php @@ -35,7 +35,7 @@ class EditTitleController extends Controller { 'permission' => 'user', 'requestData' => [ 'title' => [ - 'validation' => DataValidator::length(1, 200), + 'validation' => DataValidator::notBlank()->length(1, 200), 'error' => ERRORS::INVALID_TITLE ], 'ticketNumber' => [ @@ -49,7 +49,7 @@ class EditTitleController extends Controller { 'permission' => 'any', 'requestData' => [ 'title' => [ - 'validation' => DataValidator::length(1, 200), + 'validation' => DataValidator::notBlank()->length(1, 200), 'error' => ERRORS::INVALID_TITLE ], 'ticketNumber' => [ From c55d8ea964e62066b7823fbc99ce225c96c3e794 Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Thu, 23 Jan 2020 16:52:16 -0300 Subject: [PATCH 3/5] update lodash --- client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index a53f832c..9b71111e 100644 --- a/client/package.json +++ b/client/package.json @@ -73,7 +73,7 @@ "html-to-text": "^4.0.0", "keycode": "^2.1.4", "localStorage": "^1.0.3", - "lodash": "^3.10.0", + "lodash": "^4.17.15", "messageformat": "^0.2.2", "qs": "^6.5.2", "quill-image-resize-module-react": "^3.0.0", From b28e744ff73dc8ea3c1d2ee892de5f15363ab467 Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Thu, 23 Jan 2020 16:54:17 -0300 Subject: [PATCH 4/5] change any lodash function --- client/src/app-components/ticket-viewer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/app-components/ticket-viewer.js b/client/src/app-components/ticket-viewer.js index 7bb38a61..bd173f81 100644 --- a/client/src/app-components/ticket-viewer.js +++ b/client/src/app-components/ticket-viewer.js @@ -671,14 +671,14 @@ class TicketViewer extends React.Component { {content: 'None', id: 0} ]; - if(_.any(userDepartments, {id: ticketDepartmentId})) { + if(_.some(userDepartments, {id: ticketDepartmentId})) { staffAssignmentItems.push({content: i18n('ASSIGN_TO_ME'), id: userId}); } staffAssignmentItems = staffAssignmentItems.concat( _.map( _.filter(staffMembers, ({id, departments}) => { - return (id != userId) && _.any(departments, {id: ticketDepartmentId}); + return (id != userId) && _.some(departments, {id: ticketDepartmentId}); }), ({id, name}) => ({content: name, id}) ) From 9cff8cd78948260c4bd949a636a97880a55dacbf Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Thu, 23 Jan 2020 19:39:22 -0300 Subject: [PATCH 5/5] fix ticket search unitary tests --- server/controllers/ticket/search.php | 9 +++++---- server/tests/controllers/ticket/searchTest.php | 9 ++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/server/controllers/ticket/search.php b/server/controllers/ticket/search.php index 8bcb85ca..1f9c37f6 100644 --- a/server/controllers/ticket/search.php +++ b/server/controllers/ticket/search.php @@ -112,6 +112,7 @@ class SearchController extends Controller { 'orderBy' => json_decode(Controller::request('orderBy'),true), 'page' => Controller::request('page'), 'allowedDepartments' => Controller::getLoggedUser()->sharedDepartmentList->toArray(), + 'staffId' => Controller::getLoggedUser()->id ]; @@ -172,7 +173,9 @@ class SearchController extends Controller { if(array_key_exists('unreadStaff',$inputs)) $this->setSeenFilter($inputs['unreadStaff'], $filters); if(array_key_exists('priority',$inputs)) $this->setPriorityFilter($inputs['priority'], $filters); if(array_key_exists('dateRange',$inputs)) $this->setDateFilter($inputs['dateRange'], $filters); - if(array_key_exists('departments',$inputs)) $this->setDepartmentFilter($inputs['departments'],$inputs['allowedDepartments'], $filters); + if(array_key_exists('departments',$inputs) && array_key_exists('allowedDepartments',$inputs) && array_key_exists('staffId',$inputs)){ + $this->setDepartmentFilter($inputs['departments'],$inputs['allowedDepartments'], $inputs['staffId'], $filters); + } if(array_key_exists('authors',$inputs)) $this->setAuthorFilter($inputs['authors'], $filters); if(array_key_exists('query',$inputs)) $this->setStringFilter($inputs['query'], $filters); if($filters != "") $filters = " WHERE " . $filters; @@ -244,8 +247,7 @@ class SearchController extends Controller { } } - private function setDepartmentFilter($departments,$allowedDepartments, &$filters){ - $idStaff = Controller::getLoggedUser()->id ; + private function setDepartmentFilter($departments,$allowedDepartments, $idStaff, &$filters){ if ($filters != "") $filters .= " and "; $validDepartments = $this->generateValidDepartmentList($departments, $allowedDepartments); @@ -265,7 +267,6 @@ class SearchController extends Controller { $filters .= "("; } $filters .= "ticket.author_staff_id = " . $idStaff . ")"; - } private function setAuthorFilter($authors, &$filters){ diff --git a/server/tests/controllers/ticket/searchTest.php b/server/tests/controllers/ticket/searchTest.php index 6f74449a..35e7f574 100644 --- a/server/tests/controllers/ticket/searchTest.php +++ b/server/tests/controllers/ticket/searchTest.php @@ -173,6 +173,7 @@ class SearchControllerTest extends TestCase { $this->assertEquals( $this->searchController->getSQLQuery([ 'departments' => null, + 'staffId' => 1, 'allowedDepartments' => [ [ 'id' => 2 @@ -185,12 +186,13 @@ class SearchControllerTest extends TestCase { ] ] ]), - 'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE ( ticket.department_id = 2 or ticket.department_id = 1 or ticket.department_id = 3) GROUP BY ticket.id' + 'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE ( ticket.department_id = 2 or ticket.department_id = 1 or ticket.department_id = 3 or ticket.author_staff_id = 1) GROUP BY ticket.id' ); $this->assertEquals( $this->searchController->getSQLQuery([ 'departments' => [1], + 'staffId' => 1, 'allowedDepartments' => [ [ 'id' => 2 @@ -203,12 +205,13 @@ class SearchControllerTest extends TestCase { ] ] ]), - 'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE ( ticket.department_id = 1) GROUP BY ticket.id' + 'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE ( ticket.department_id = 1 or ticket.author_staff_id = 1) GROUP BY ticket.id' ); $this->assertEquals( $this->searchController->getSQLQuery([ 'departments' => [1,2,3], + 'staffId' => 1, 'allowedDepartments' => [ [ 'id' => 2 @@ -221,7 +224,7 @@ class SearchControllerTest extends TestCase { ] ] ]), - 'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE ( ticket.department_id = 1 or ticket.department_id = 2 or ticket.department_id = 3) GROUP BY ticket.id' + 'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE ( ticket.department_id = 1 or ticket.department_id = 2 or ticket.department_id = 3 or ticket.author_staff_id = 1) GROUP BY ticket.id' ); }