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", 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}) ) 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' => [ diff --git a/server/controllers/ticket/search.php b/server/controllers/ticket/search.php index 09d2a020..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; @@ -207,7 +210,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) { @@ -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' ); }