Added a new automatic action to set due date
This commit is contained in:
parent
e0d330dda8
commit
2a42e0e1aa
|
|
@ -3,7 +3,9 @@ Version 1.0.32 (unreleased)
|
|||
|
||||
New features:
|
||||
|
||||
* New automated action to close tasks without activity in a specific column
|
||||
* New automated actions:
|
||||
- Close tasks without activity in a specific column
|
||||
- Set due date automatically
|
||||
* Added internal task links to activity stream
|
||||
* Added new event for removed comments
|
||||
* Added search filter for task priority
|
||||
|
|
@ -11,6 +13,7 @@ New features:
|
|||
|
||||
Improvements:
|
||||
|
||||
* Internal events management refactoring
|
||||
* Handle header X-Real-IP to get IP address
|
||||
* Display project name for task auto-complete fields
|
||||
* Make search attributes not case sensitive
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Action;
|
||||
|
||||
use Kanboard\Model\TaskModel;
|
||||
|
||||
/**
|
||||
* Set the due date of task
|
||||
*
|
||||
* @package action
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskAssignDueDateOnCreation extends Base
|
||||
{
|
||||
/**
|
||||
* Get automatic action description
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return t('Automatically set the due date on task creation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
return array(
|
||||
TaskModel::EVENT_CREATE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required parameter for the action (defined by the user)
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getActionRequiredParameters()
|
||||
{
|
||||
return array(
|
||||
'duration' => t('Duration in days')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required parameter for the event
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getEventRequiredParameters()
|
||||
{
|
||||
return array(
|
||||
'task_id',
|
||||
'task' => array(
|
||||
'project_id',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the action (set the task color)
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$values = array(
|
||||
'id' => $data['task_id'],
|
||||
'date_due' => strtotime('+'.$this->getParam('duration').'days'),
|
||||
);
|
||||
|
||||
return $this->taskModificationModel->update($values, 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 true;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Kanboard\ServiceProvider;
|
||||
|
||||
use Kanboard\Action\TaskAssignColorPriority;
|
||||
use Kanboard\Action\TaskAssignDueDateOnCreation;
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
use Kanboard\Core\Action\ActionManager;
|
||||
|
|
@ -80,6 +81,7 @@ class ActionProvider implements ServiceProviderInterface
|
|||
$container['actionManager']->register(new TaskMoveColumnUnAssigned($container));
|
||||
$container['actionManager']->register(new TaskOpen($container));
|
||||
$container['actionManager']->register(new TaskUpdateStartDate($container));
|
||||
$container['actionManager']->register(new TaskAssignDueDateOnCreation($container));
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Kanboard\Action\TaskAssignDueDateOnCreation;
|
||||
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 TaskAssignDueDateOnCreationTest extends Base
|
||||
{
|
||||
public function testAction()
|
||||
{
|
||||
$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(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$event = TaskEventBuilder::getInstance($this->container)
|
||||
->withTaskId(1)
|
||||
->buildEvent();
|
||||
|
||||
$action = new TaskAssignDueDateOnCreation($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('duration', 4);
|
||||
|
||||
$this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE));
|
||||
|
||||
$task = $taskFinderModel->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(date('Y-m-d', strtotime('+4days')), date('Y-m-d', $task['date_due']));
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Kanboard\Event\GenericEvent;
|
||||
use Kanboard\Event\TaskEvent;
|
||||
use Kanboard\Model\TaskCreationModel;
|
||||
use Kanboard\Model\TaskFinderModel;
|
||||
|
|
@ -12,7 +11,7 @@ use Kanboard\Action\TaskUpdateStartDate;
|
|||
|
||||
class TaskUpdateStartDateTest extends Base
|
||||
{
|
||||
public function testClose()
|
||||
public function testAction()
|
||||
{
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
|
|
|
|||
Loading…
Reference in New Issue