Merge pull request #705 from guillegiu/master
add owner filter to ticketSearch BE
This commit is contained in:
commit
ae34631bca
|
@ -27,6 +27,7 @@ DataValidator::with('CustomValidations', true);
|
||||||
* @apiParam {String} query A string to find into a ticket to make a custom search.
|
* @apiParam {String} query A string to find into a ticket to make a custom search.
|
||||||
* @apiParam {Number} page The number of the page of the tickets.
|
* @apiParam {Number} page The number of the page of the tickets.
|
||||||
* @apiParam {Object} orderBy A object {value, asc}with string and boolean to make a especific order of the search.
|
* @apiParam {Object} orderBy A object {value, asc}with string and boolean to make a especific order of the search.
|
||||||
|
* @apiParam {Number[]} owners The ids of the owners to make a custom search.
|
||||||
*
|
*
|
||||||
* @apiUse NO_PERMISSION
|
* @apiUse NO_PERMISSION
|
||||||
* @apiUse INVALID_TAG_FILTER
|
* @apiUse INVALID_TAG_FILTER
|
||||||
|
@ -86,6 +87,10 @@ class SearchController extends Controller {
|
||||||
'validation' => DataValidator::oneOf(DataValidator::validAuthorsId(),DataValidator::nullType()),
|
'validation' => DataValidator::oneOf(DataValidator::validAuthorsId(),DataValidator::nullType()),
|
||||||
'error' => ERRORS::INVALID_AUTHOR_FILTER
|
'error' => ERRORS::INVALID_AUTHOR_FILTER
|
||||||
],
|
],
|
||||||
|
'owners' => [
|
||||||
|
'validation' => DataValidator::oneOf(DataValidator::validOwnersId(),DataValidator::nullType()),
|
||||||
|
'error' => ERRORS::INVALID_OWNER_FILTER
|
||||||
|
],
|
||||||
'assigned' => [
|
'assigned' => [
|
||||||
'validation' => DataValidator::oneOf(DataValidator::in(['0','1']),DataValidator::nullType()),
|
'validation' => DataValidator::oneOf(DataValidator::in(['0','1']),DataValidator::nullType()),
|
||||||
'error' => ERRORS::INVALID_ASSIGNED_FILTER
|
'error' => ERRORS::INVALID_ASSIGNED_FILTER
|
||||||
|
@ -107,6 +112,7 @@ class SearchController extends Controller {
|
||||||
'dateRange' => json_decode(Controller::request('dateRange')),
|
'dateRange' => json_decode(Controller::request('dateRange')),
|
||||||
'departments' => json_decode(Controller::request('departments')),
|
'departments' => json_decode(Controller::request('departments')),
|
||||||
'authors' => json_decode(Controller::request('authors'),true),
|
'authors' => json_decode(Controller::request('authors'),true),
|
||||||
|
'owners' => json_decode(Controller::request('owners')),
|
||||||
'assigned' => Controller::request('assigned'),
|
'assigned' => Controller::request('assigned'),
|
||||||
'query' => Controller::request('query'),
|
'query' => Controller::request('query'),
|
||||||
'orderBy' => json_decode(Controller::request('orderBy'),true),
|
'orderBy' => json_decode(Controller::request('orderBy'),true),
|
||||||
|
@ -177,6 +183,7 @@ class SearchController extends Controller {
|
||||||
$this->setDepartmentFilter($inputs['departments'],$inputs['allowedDepartments'], $inputs['staffId'], $filters);
|
$this->setDepartmentFilter($inputs['departments'],$inputs['allowedDepartments'], $inputs['staffId'], $filters);
|
||||||
}
|
}
|
||||||
if(array_key_exists('authors',$inputs)) $this->setAuthorFilter($inputs['authors'], $filters);
|
if(array_key_exists('authors',$inputs)) $this->setAuthorFilter($inputs['authors'], $filters);
|
||||||
|
if(array_key_exists('owners',$inputs)) $this->setOwnerFilter($inputs['owners'], $filters);
|
||||||
if(array_key_exists('query',$inputs)) $this->setStringFilter($inputs['query'], $filters);
|
if(array_key_exists('query',$inputs)) $this->setStringFilter($inputs['query'], $filters);
|
||||||
if($filters != "") $filters = " WHERE " . $filters;
|
if($filters != "") $filters = " WHERE " . $filters;
|
||||||
}
|
}
|
||||||
|
@ -289,9 +296,27 @@ class SearchController extends Controller {
|
||||||
$filters .= "ticket.author_id = " . $author['id'];
|
$filters .= "ticket.author_id = " . $author['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$filters .= ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setOwnerFilter($owners, &$filters){
|
||||||
|
if($owners){
|
||||||
|
$first = TRUE;
|
||||||
|
if ($filters != "") $filters .= " and ";
|
||||||
|
|
||||||
|
foreach($owners as $owner){
|
||||||
|
|
||||||
|
if($first){
|
||||||
|
$filters .= "(";
|
||||||
|
$first = FALSE;
|
||||||
|
} else {
|
||||||
|
$filters .= " or ";
|
||||||
|
}
|
||||||
|
$filters .= "ticket.owner_id = " . $owner;
|
||||||
|
}
|
||||||
|
|
||||||
$filters .= ")";
|
$filters .= ")";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,46 @@
|
||||||
* @apiDefine INVALID_QUERY
|
* @apiDefine INVALID_QUERY
|
||||||
* @apiError {String} INVALID_QUERY The query is invalid.
|
* @apiError {String} INVALID_QUERY The query is invalid.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_TAG_FILTER
|
||||||
|
* @apiError {String} INVALID_TAG_FILTER The tag filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_CLOSED_FILTER
|
||||||
|
* @apiError {String} INVALID_CLOSED_FILTER The closed filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_UNREAD_STAFF_FILTER
|
||||||
|
* @apiError {String} INVALID_UNREAD_STAFF_FILTER The unread-staff filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_PRIORITY_FILTER
|
||||||
|
* @apiError {String} INVALID_PRIORITY_FILTER The priority filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_DATE_RANGE_FILTER
|
||||||
|
* @apiError {String} INVALID_DATE_RANGE_FILTER The date-range filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_DEPARTMENT_FILTER
|
||||||
|
* @apiError {String} INVALID_DEPARTMENT_FILTER The department filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_AUTHOR_FILTER
|
||||||
|
* @apiError {String} INVALID_AUTHOR_FILTER The author filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_OWNER_FILTER
|
||||||
|
* @apiError {String} INVALID_OWNER_FILTER The owner filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_ASSIGNED_FILTER
|
||||||
|
* @apiError {String} INVALID_ASSIGNED_FILTER The assigned filter is invalid.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @apiDefine INVALID_ORDER_BY
|
||||||
|
* @apiError {String} INVALID_ORDER_BY The order-by is invalid.
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* @apiDefine INVALID_TOPIC
|
* @apiDefine INVALID_TOPIC
|
||||||
* @apiError {String} INVALID_TOPIC The topic is invalid.
|
* @apiError {String} INVALID_TOPIC The topic is invalid.
|
||||||
|
@ -288,6 +328,7 @@ class ERRORS {
|
||||||
const INVALID_DATE_RANGE_FILTER = 'INVALID_DATE_RANGE_FILTER';
|
const INVALID_DATE_RANGE_FILTER = 'INVALID_DATE_RANGE_FILTER';
|
||||||
const INVALID_DEPARTMENT_FILTER = 'INVALID_DEPARTMENT_FILTER';
|
const INVALID_DEPARTMENT_FILTER = 'INVALID_DEPARTMENT_FILTER';
|
||||||
const INVALID_AUTHOR_FILTER = 'INVALID_AUTHOR_FILTER';
|
const INVALID_AUTHOR_FILTER = 'INVALID_AUTHOR_FILTER';
|
||||||
|
const INVALID_OWNER_FILTER = 'INVALID_OWNER_FILTER';
|
||||||
const INVALID_ASSIGNED_FILTER = 'INVALID_ASSIGNED_FILTER';
|
const INVALID_ASSIGNED_FILTER = 'INVALID_ASSIGNED_FILTER';
|
||||||
const INVALID_ORDER_BY = 'INVALID_ORDER_BY';
|
const INVALID_ORDER_BY = 'INVALID_ORDER_BY';
|
||||||
const INVALID_TOPIC = 'INVALID_TOPIC';
|
const INVALID_TOPIC = 'INVALID_TOPIC';
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace CustomValidations;
|
||||||
|
|
||||||
|
use Respect\Validation\Rules\AbstractRule;
|
||||||
|
|
||||||
|
class ValidOwnersId extends AbstractRule {
|
||||||
|
|
||||||
|
public function validate($owners) {
|
||||||
|
if(is_array(json_decode($owners))){
|
||||||
|
foreach (json_decode($owners) as $owner) {
|
||||||
|
$author = \Staff::getDataStore($owner);
|
||||||
|
if($author->isNull()) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -169,6 +169,29 @@ class SearchControllerTest extends TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOwnerFilter() {
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->searchController->getSQLQuery([
|
||||||
|
'owners' => [1,2]
|
||||||
|
]),
|
||||||
|
'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE (ticket.owner_id = 1 or ticket.owner_id = 2) GROUP BY ticket.id'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->searchController->getSQLQuery([
|
||||||
|
'owners' => [6,1,9]
|
||||||
|
]),
|
||||||
|
'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) WHERE (ticket.owner_id = 6 or ticket.owner_id = 1 or ticket.owner_id = 9) GROUP BY ticket.id'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->searchController->getSQLQuery([
|
||||||
|
'owners' => []
|
||||||
|
]),
|
||||||
|
'FROM (ticket LEFT JOIN tag_ticket ON tag_ticket.ticket_id = ticket.id LEFT JOIN ticketevent ON ticketevent.ticket_id = ticket.id) GROUP BY ticket.id'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDepartmentsFilter() {
|
public function testDepartmentsFilter() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->searchController->getSQLQuery([
|
$this->searchController->getSQLQuery([
|
||||||
|
|
Loading…
Reference in New Issue