Add new automatic action to move a task to another column when closed

This commit is contained in:
Frederic Guillot 2016-07-23 18:33:31 -04:00
parent 2a42e0e1aa
commit 9b2a32af78
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
35 changed files with 236 additions and 39 deletions

View File

@ -6,6 +6,7 @@ New features:
* New automated actions:
- Close tasks without activity in a specific column
- Set due date automatically
- Move a task to another column when closed
* Added internal task links to activity stream
* Added new event for removed comments
* Added search filter for task priority

View File

@ -7,7 +7,7 @@ use Kanboard\Event\GenericEvent;
/**
* Base class for automatic actions
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
abstract class Base extends \Kanboard\Core\Base

View File

@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Create automatically a comment from a webhook
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class CommentCreation extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Add a comment of the triggering event to the task description.
*
* @package action
* @package Kanboard\Action
* @author Oren Ben-Kiki
*/
class CommentCreationMoveTaskColumn extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Set a category automatically according to the color
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCategoryColor extends Base

View File

@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Set a category automatically according to a label
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCategoryLabel extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskLinkModel;
/**
* Set a category automatically according to a task link
*
* @package action
* @package Kanboard\Action
* @author Olivier Maridat
* @author Frederic Guillot
*/

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a specific category
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorCategory extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorColumn extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskLinkModel;
/**
* Assign a color to a specific task link
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorLink extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a priority
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorPriority extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a specific user
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorUser extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a task to the logged user
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCurrentUser extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a task to the logged user on column change
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCurrentUserColumn extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Set the due date of task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignDueDateOnCreation extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a task to a specific user
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignSpecificUser extends Base

View File

@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Assign a task to someone
*
* @package action
* @package Kanboard\Actionv
* @author Frederic Guillot
*/
class TaskAssignUser extends Base

View File

@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Close automatically a task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskClose extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Close automatically a task in a specific column
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCloseColumn extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Close automatically a task after when inactive
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCloseNoActivity extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Close automatically a task after inactive and in an defined column
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCloseNoActivityColumn extends Base

View File

@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Create automatically a task from a webhook
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCreation extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Duplicate a task to another project
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskDuplicateAnotherProject extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Email a task to someone
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskEmail extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Email a task with no activity
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskEmailNoActivity extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another project
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskMoveAnotherProject extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another column when an assignee is set
*
* @package action
* @package Kanboard\Action
* @author Francois Ferrand
*/
class TaskMoveColumnAssigned extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another column when the category is changed
*
* @package action
* @package Kanboard\Action
* @author Francois Ferrand
*/
class TaskMoveColumnCategoryChange extends Base

View File

@ -0,0 +1,102 @@
<?php
namespace Kanboard\Action;
use Kanboard\Model\TaskModel;
/**
* Move a task to another column when the task is closed
*
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskMoveColumnClosed extends Base
{
/**
* Get automatic action description
*
* @access public
* @return string
*/
public function getDescription()
{
return t('Move the task to another column when closed');
}
/**
* Get the list of compatible events
*
* @access public
* @return array
*/
public function getCompatibleEvents()
{
return array(
TaskModel::EVENT_CLOSE,
);
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
return array(
'dest_column_id' => t('Destination column'),
);
}
/**
* Get the required parameter for the event
*
* @access public
* @return string[]
*/
public function getEventRequiredParameters()
{
return array(
'task_id',
'task' => array(
'project_id',
'column_id',
'swimlane_id',
'is_active',
)
);
}
/**
* Execute the action (move the task to another column)
*
* @access public
* @param array $data Event data dictionary
* @return bool True if the action was executed or false when not executed
*/
public function doAction(array $data)
{
return $this->taskPositionModel->movePosition(
$data['task']['project_id'],
$data['task']['id'],
$this->getParam('dest_column_id'),
1,
$data['task']['swimlane_id'],
false,
false
);
}
/**
* Check if the event data meet the action condition
*
* @access public
* @param array $data Event data dictionary
* @return bool
*/
public function hasRequiredCondition(array $data)
{
return $data['task']['column_id'] != $this->getParam('dest_column_id') && $data['task']['is_active'] == 0;
}
}

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another column when an assignee is cleared
*
* @package action
* @package Kanboard\Action
* @author Francois Ferrand
*/
class TaskMoveColumnUnAssigned extends Base

View File

@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Open automatically a task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskOpen extends Base

View File

@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Set the start date of task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskUpdateStartDate extends Base

View File

@ -22,9 +22,10 @@ class TaskPositionModel extends Base
* @param integer $position Position (must be >= 1)
* @param integer $swimlane_id Swimlane id
* @param boolean $fire_events Fire events
* @return boolean
* @param bool $onlyOpen Do not move closed tasks
* @return bool
*/
public function movePosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0, $fire_events = true)
public function movePosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0, $fire_events = true, $onlyOpen = true)
{
if ($position < 1) {
return false;
@ -32,7 +33,7 @@ class TaskPositionModel extends Base
$task = $this->taskFinderModel->getById($task_id);
if ($task['is_active'] == TaskModel::STATUS_CLOSED) {
if ($onlyOpen && $task['is_active'] == TaskModel::STATUS_CLOSED) {
return true;
}

View File

@ -4,6 +4,7 @@ namespace Kanboard\ServiceProvider;
use Kanboard\Action\TaskAssignColorPriority;
use Kanboard\Action\TaskAssignDueDateOnCreation;
use Kanboard\Action\TaskMoveColumnClosed;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Kanboard\Core\Action\ActionManager;
@ -78,6 +79,7 @@ class ActionProvider implements ServiceProviderInterface
$container['actionManager']->register(new TaskMoveAnotherProject($container));
$container['actionManager']->register(new TaskMoveColumnAssigned($container));
$container['actionManager']->register(new TaskMoveColumnCategoryChange($container));
$container['actionManager']->register(new TaskMoveColumnClosed($container));
$container['actionManager']->register(new TaskMoveColumnUnAssigned($container));
$container['actionManager']->register(new TaskOpen($container));
$container['actionManager']->register(new TaskUpdateStartDate($container));

View File

@ -0,0 +1,91 @@
<?php
use Kanboard\Action\TaskMoveColumnClosed;
use Kanboard\EventBuilder\TaskEventBuilder;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskModel;
require_once __DIR__.'/../Base.php';
class TaskMoveColumnClosedTest extends Base
{
public function testSuccess()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0)));
$event = TaskEventBuilder::getInstance($this->container)
->withTaskId(1)
->buildEvent();
$action = new TaskMoveColumnClosed($this->container);
$action->setProjectId(1);
$action->setParam('dest_column_id', 2);
$this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE));
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals('test', $task['title']);
$this->assertEquals(2, $task['column_id']);
}
public function testWhenTaskIsOpen()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$event = TaskEventBuilder::getInstance($this->container)
->withTaskId(1)
->buildEvent();
$action = new TaskMoveColumnClosed($this->container);
$action->setProjectId(1);
$action->setParam('dest_column_id', 2);
$this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals('test', $task['title']);
$this->assertEquals(1, $task['column_id']);
}
public function testWhenTaskIsAlreadyInDestinationColumn()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0, 'column_id' => 2)));
$event = TaskEventBuilder::getInstance($this->container)
->withTaskId(1)
->buildEvent();
$action = new TaskMoveColumnClosed($this->container);
$action->setProjectId(1);
$action->setParam('dest_column_id', 2);
$this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals('test', $task['title']);
$this->assertEquals(2, $task['column_id']);
}
}