Add new automatic action to assign tasks to its creator

This commit is contained in:
Frederic Guillot
2017-06-03 11:32:24 -04:00
parent 6251ac62d4
commit 43e4662b84
32 changed files with 316 additions and 92 deletions

View File

@@ -1,3 +1,10 @@
Version 1.0.45 (unreleased)
---------------------------
New features:
* Automatic action to assign tasks to its creator
Version 1.0.44 (May 28, 2017)
-----------------------------

View File

@@ -0,0 +1,98 @@
<?php
namespace Kanboard\Action;
use Kanboard\Model\TaskModel;
/**
* Assign a task to the creator
*
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCreator extends Base
{
/**
* Get automatic action description
*
* @access public
* @return string
*/
public function getDescription()
{
return t('Assign the task to its creator');
}
/**
* Get the list of compatible events
*
* @access public
* @return array
*/
public function getCompatibleEvents()
{
return array(
TaskModel::EVENT_MOVE_COLUMN,
);
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
return array(
'column_id' => t('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',
'creator_id',
),
);
}
/**
* Execute the action
*
* @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'],
'owner_id' => $data['task']['creator_id'],
);
return $this->taskModificationModel->update($values);
}
/**
* 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('column_id');
}
}

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
'[DUPLICATE]' => '[DUPLICATE]',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1332,4 +1332,7 @@ return array(
// '%d subtask' => '',
// 'Only moving task between those columns is permitted for tasks assigned to the current user' => '',
'[DUPLICATE]' => '[KOPIE]',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
'[DUPLICATE]' => '[COPIE]',
'DKK - Danish Krona' => 'DKK - Couronne danoise',
'Remove user from group' => 'Supprimer cet utilisateur du groupe',
'Assign the task to its creator' => 'Assigner une tâche à son créateur',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
'[DUPLICATE]' => '[Duplikált]',
'DKK - Danish Krona' => 'Dán korona',
'Remove user from group' => 'Felhasználó eltávolítása a csoportból',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
'[DUPLICATE]' => '[DUPLICADO]',
'DKK - Danish Krona' => 'DKK - Coroa Dinamarquesa',
'Remove user from group' => 'Remover usuário do grupo',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -1334,4 +1334,5 @@ return array(
// '[DUPLICATE]' => '',
// 'DKK - Danish Krona' => '',
// 'Remove user from group' => '',
// 'Assign the task to its creator' => '',
);

View File

@@ -19,6 +19,7 @@ use Kanboard\Action\TaskAssignColorCategory;
use Kanboard\Action\TaskAssignColorColumn;
use Kanboard\Action\TaskAssignColorLink;
use Kanboard\Action\TaskAssignColorUser;
use Kanboard\Action\TaskAssignCreator;
use Kanboard\Action\TaskAssignCurrentUser;
use Kanboard\Action\TaskAssignCurrentUserColumn;
use Kanboard\Action\TaskAssignSpecificUser;
@@ -69,6 +70,7 @@ class ActionProvider implements ServiceProviderInterface
$container['actionManager']->register(new TaskAssignColorLink($container));
$container['actionManager']->register(new TaskAssignColorUser($container));
$container['actionManager']->register(new TaskAssignColorPriority($container));
$container['actionManager']->register(new TaskAssignCreator($container));
$container['actionManager']->register(new TaskAssignCurrentUser($container));
$container['actionManager']->register(new TaskAssignCurrentUserColumn($container));
$container['actionManager']->register(new TaskAssignSpecificUser($container));

View File

@@ -0,0 +1,89 @@
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Action\TaskAssignCreator;
use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskModel;
class TaskAssignCreatorTest extends Base
{
public function testChangeUser()
{
$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', 'owner_id' => 0)));
$event = new TaskEvent(array(
'task_id' => 1,
'task' => array(
'project_id' => 1,
'column_id' => 2,
'creator_id' => 1,
)
));
$action = new TaskAssignCreator($this->container);
$action->setProjectId(1);
$action->setParam('column_id', 2);
$this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN));
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['owner_id']);
}
public function testWithoutCreator()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0)));
$event = new TaskEvent(array(
'task_id' => 1,
'task' => array(
'project_id' => 1,
'column_id' => 2,
)
));
$action = new TaskAssignCreator($this->container);
$action->setProjectId(1);
$action->setParam('column_id', 2);
$this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN));
}
public function testWithWrongColumn()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$event = new TaskEvent(array(
'task_id' => 1,
'task' => array(
'project_id' => 1,
'column_id' => 3,
'creator_id' => 1,
)
));
$action = new TaskAssignCreator($this->container);
$action->setProjectId(1);
$action->setParam('column_id', 2);
$this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN));
}
}

View File

@@ -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;