From 756716766cb33da2c25544918574368b51cca26e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 21 Apr 2016 21:21:34 -0400 Subject: Added priority field to API procedures --- app/Api/Task.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/Api/Task.php') diff --git a/app/Api/Task.php b/app/Api/Task.php index 177a09c6..202e9bb5 100644 --- a/app/Api/Task.php +++ b/app/Api/Task.php @@ -75,7 +75,7 @@ class Task extends Base } public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, - $date_due = '', $description = '', $category_id = 0, $score = 0, $swimlane_id = 0, + $date_due = '', $description = '', $category_id = 0, $score = 0, $swimlane_id = 0, $priority = 0, $recurrence_status = 0, $recurrence_trigger = 0, $recurrence_factor = 0, $recurrence_timeframe = 0, $recurrence_basedate = 0, $reference = '') { @@ -107,6 +107,7 @@ class Task extends Base 'recurrence_timeframe' => $recurrence_timeframe, 'recurrence_basedate' => $recurrence_basedate, 'reference' => $reference, + 'priority' => $priority, ); list($valid, ) = $this->taskValidator->validateCreation($values); @@ -115,7 +116,7 @@ class Task extends Base } public function updateTask($id, $title = null, $color_id = null, $owner_id = null, - $date_due = null, $description = null, $category_id = null, $score = null, + $date_due = null, $description = null, $category_id = null, $score = null, $priority = null, $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null, $recurrence_timeframe = null, $recurrence_basedate = null, $reference = null) { @@ -146,6 +147,7 @@ class Task extends Base 'recurrence_timeframe' => $recurrence_timeframe, 'recurrence_basedate' => $recurrence_basedate, 'reference' => $reference, + 'priority' => $priority, ); foreach ($values as $key => $value) { -- cgit v1.2.3 From da1725c225c94bcdffe4dba4c068db8e1e11cbe7 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 22 Apr 2016 18:49:19 -0400 Subject: Added searchTasks API procedure --- ChangeLog | 1 + app/Api/Base.php | 1 + app/Api/Task.php | 7 +++++ doc/api-task-procedures.markdown | 59 ++++++++++++++++++++++++++++++++++++++++ tests/integration/TaskTest.php | 20 ++++++++++++++ 5 files changed, 88 insertions(+) (limited to 'app/Api/Task.php') diff --git a/ChangeLog b/ChangeLog index 99ddca45..898d2b00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ New features: Improvements: +* Added tasks search with the API * Added priority field to API procedures * Added API procedure "getMemberGroups" * Added parameters for overdue tasks notifications: group by projects and send only to managers diff --git a/app/Api/Base.php b/app/Api/Base.php index 0959817e..2cc62da8 100644 --- a/app/Api/Base.php +++ b/app/Api/Base.php @@ -40,6 +40,7 @@ abstract class Base extends \Kanboard\Core\Base 'getBoard', 'getProjectActivity', 'getOverdueTasksByProject', + 'searchTasks', ); public function checkProcedurePermission($is_user, $procedure) diff --git a/app/Api/Task.php b/app/Api/Task.php index 202e9bb5..1d1211f2 100644 --- a/app/Api/Task.php +++ b/app/Api/Task.php @@ -2,6 +2,7 @@ namespace Kanboard\Api; +use Kanboard\Filter\TaskProjectFilter; use Kanboard\Model\Task as TaskModel; /** @@ -12,6 +13,12 @@ use Kanboard\Model\Task as TaskModel; */ class Task extends Base { + public function searchTasks($project_id, $query) + { + $this->checkProjectPermission($project_id); + return $this->taskLexer->build($query)->withFilter(new TaskProjectFilter($project_id))->toArray(); + } + public function getTask($task_id) { $this->checkTaskPermission($task_id); diff --git a/doc/api-task-procedures.markdown b/doc/api-task-procedures.markdown index d994d662..934b1e09 100644 --- a/doc/api-task-procedures.markdown +++ b/doc/api-task-procedures.markdown @@ -636,3 +636,62 @@ Response example: "result": 6 } ``` + +## searchTasks + +- Purpose: **Find tasks by using the search engine** +- Parameters: + - **project_id** (integer, required) + - **query** (string, required) +- Result on success: **list of tasks** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "searchTasks", + "id": 1468511716, + "params": { + "project_id": 2, + "query": "assignee:nobody" + } +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 1468511716, + "result": [ + { + "nb_comments": "0", + "nb_files": "0", + "nb_subtasks": "0", + "nb_completed_subtasks": "0", + "nb_links": "0", + "nb_external_links": "0", + "is_milestone": null, + "id": "3", + "reference": "", + "title": "T3", + "description": "", + "date_creation": "1461365164", + "date_modification": "1461365164", + "date_completed": null, + "date_started": null, + "date_due": "0", + "color_id": "yellow", + "project_id": "2", + "column_id": "5", + "swimlane_id": "0", + "owner_id": "0", + "creator_id": "0" + // ... + } + ] +} +``` diff --git a/tests/integration/TaskTest.php b/tests/integration/TaskTest.php index 39fe41bf..0c398761 100644 --- a/tests/integration/TaskTest.php +++ b/tests/integration/TaskTest.php @@ -4,6 +4,26 @@ require_once __DIR__.'/Base.php'; class TaskTest extends Base { + public function testSearchTasks() + { + $project_id1 = $this->app->createProject('My project'); + $project_id2 = $this->app->createProject('My project'); + $this->assertNotFalse($project_id1); + $this->assertNotFalse($project_id2); + + $this->assertNotFalse($this->app->createTask(array('project_id' => $project_id1, 'title' => 'T1'))); + $this->assertNotFalse($this->app->createTask(array('project_id' => $project_id1, 'title' => 'T2'))); + $this->assertNotFalse($this->app->createTask(array('project_id' => $project_id2, 'title' => 'T3'))); + + $tasks = $this->app->searchTasks($project_id1, 't2'); + $this->assertCount(1, $tasks); + $this->assertEquals('T2', $tasks[0]['title']); + + $tasks = $this->app->searchTasks(array('project_id' => $project_id2, 'query' => 'assignee:nobody')); + $this->assertCount(1, $tasks); + $this->assertEquals('T3', $tasks[0]['title']); + } + public function testPriorityAttribute() { $project_id = $this->app->createProject('My project'); -- cgit v1.2.3