Included Subtask when filtering Tasks by Assignee
I wrote some unit test specifing the behaviour. I think only Substask with a Status != Done and an assigned user should be taken into account. The search for "nobody" should not reveal tasks with assigned users when these tasks have a subtask without an user.
This commit is contained in:
@@ -313,10 +313,11 @@ class TaskFilter extends Base
|
|||||||
$this->query->beginOr();
|
$this->query->beginOr();
|
||||||
|
|
||||||
foreach ($values as $assignee) {
|
foreach ($values as $assignee) {
|
||||||
|
$subtaskQuery = $this->buildSubtaskQuery();
|
||||||
switch ($assignee) {
|
switch ($assignee) {
|
||||||
case 'me':
|
case 'me':
|
||||||
$this->query->eq(Task::TABLE.'.owner_id', $this->userSession->getId());
|
$this->query->eq(Task::TABLE.'.owner_id', $this->userSession->getId());
|
||||||
|
$subtaskQuery->eq(Subtask::TABLE.'user_id',$this->userSession->getId() );
|
||||||
break;
|
break;
|
||||||
case 'nobody':
|
case 'nobody':
|
||||||
$this->query->eq(Task::TABLE.'.owner_id', 0);
|
$this->query->eq(Task::TABLE.'.owner_id', 0);
|
||||||
@@ -324,6 +325,12 @@ class TaskFilter extends Base
|
|||||||
default:
|
default:
|
||||||
$this->query->ilike(User::TABLE.'.username', '%'.$assignee.'%');
|
$this->query->ilike(User::TABLE.'.username', '%'.$assignee.'%');
|
||||||
$this->query->ilike(User::TABLE.'.name', '%'.$assignee.'%');
|
$this->query->ilike(User::TABLE.'.name', '%'.$assignee.'%');
|
||||||
|
$subtaskQuery->ilike(User::TABLE.'.username', '%'.$assignee.'%');
|
||||||
|
$subtaskQuery->ilike(User::TABLE.'.name', '%'.$assignee.'%');
|
||||||
|
}
|
||||||
|
if ($assignee != 'nobody'){
|
||||||
|
$subtasks = $subtaskQuery->findAll();
|
||||||
|
$this->addTasksWithFoundSubtask($subtasks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -760,4 +767,25 @@ class TaskFilter extends Base
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildSubtaskQuery(){
|
||||||
|
return $this->db->table(Subtask::TABLE)
|
||||||
|
->columns(
|
||||||
|
Subtask::TABLE.'.user_id',
|
||||||
|
Subtask::TABLE.'.task_id',
|
||||||
|
User::TABLE.'.name',
|
||||||
|
User::TABLE.'.username')
|
||||||
|
->join(User::TABLE, 'id', 'user_id', Subtask::TABLE)
|
||||||
|
->beginOr()
|
||||||
|
->eq(Subtask::TABLE.'.status', Subtask::STATUS_TODO)
|
||||||
|
->eq(Subtask::TABLE.'.status', Subtask::STATUS_INPROGRESS)
|
||||||
|
->closeOr();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addTasksWithFoundSubtask($subtasks) {
|
||||||
|
foreach ($subtasks as $subtask) {
|
||||||
|
$this->query->eq(Task::TABLE.'.id',$subtask['task_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use Model\TaskFilter;
|
|||||||
use Model\TaskCreation;
|
use Model\TaskCreation;
|
||||||
use Model\DateParser;
|
use Model\DateParser;
|
||||||
use Model\Category;
|
use Model\Category;
|
||||||
|
use Model\Subtask;
|
||||||
|
|
||||||
class TaskFilterTest extends Base
|
class TaskFilterTest extends Base
|
||||||
{
|
{
|
||||||
@@ -418,6 +419,41 @@ class TaskFilterTest extends Base
|
|||||||
$this->assertEquals('Bob at work', $tasks[1]['title']);
|
$this->assertEquals('Bob at work', $tasks[1]['title']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSearchWithAssigneeIncludingSubtasks()
|
||||||
|
{
|
||||||
|
$p = new Project($this->container);
|
||||||
|
$u = new User($this->container);
|
||||||
|
$tc = new TaskCreation($this->container);
|
||||||
|
$s = new Subtask($this->container);
|
||||||
|
$tf = new TaskFilter($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||||
|
$this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan')));
|
||||||
|
$this->assertEquals(1,$tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'owner_id' => 2)));
|
||||||
|
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'status' => 1, 'another_subtask' => 'on', 'user_id' => 0)));
|
||||||
|
$this->assertEquals(2,$tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'owner_id' => 0)));
|
||||||
|
$this->assertEquals(2, $s->create(array('title' => 'subtask #1', 'task_id' => 2, 'status' => 1, 'another_subtask' => 'on', 'user_id' => 2)));
|
||||||
|
|
||||||
|
$tf->search('assignee:bob');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertNotEmpty($tasks);
|
||||||
|
$this->assertCount(2, $tasks);
|
||||||
|
$this->assertEquals('my task title is awesome', $tasks[0]['title']);
|
||||||
|
$this->assertEquals('my task title is amazing', $tasks[1]['title']);
|
||||||
|
|
||||||
|
|
||||||
|
$tf->search('assignee:nobody');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertNotEmpty($tasks);
|
||||||
|
$this->assertCount(1, $tasks);
|
||||||
|
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testCopy()
|
public function testCopy()
|
||||||
{
|
{
|
||||||
$tf = new TaskFilter($this->container);
|
$tf = new TaskFilter($this->container);
|
||||||
|
|||||||
Reference in New Issue
Block a user