Improve automatic actions (check for compatible events/actions/parameters)
This commit is contained in:
parent
0c8de6a3f5
commit
03fa01ac7b
|
|
@ -3,12 +3,17 @@
|
|||
namespace Action;
|
||||
|
||||
use Core\Listener;
|
||||
use Core\Registry;
|
||||
use Core\Tool;
|
||||
|
||||
/**
|
||||
* Base class for automatic actions
|
||||
*
|
||||
* @package action
|
||||
* @author Frederic Guillot
|
||||
*
|
||||
* @property \Model\Acl $acl
|
||||
* @property \Model\Task $task
|
||||
*/
|
||||
abstract class Base implements Listener
|
||||
{
|
||||
|
|
@ -28,6 +33,22 @@ abstract class Base implements Listener
|
|||
*/
|
||||
private $params = array();
|
||||
|
||||
/**
|
||||
* Attached event name
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $event_name = '';
|
||||
|
||||
/**
|
||||
* Registry instance
|
||||
*
|
||||
* @access protected
|
||||
* @var \Core\Registry
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
*
|
||||
|
|
@ -56,15 +77,60 @@ abstract class Base implements Listener
|
|||
*/
|
||||
abstract public function getEventRequiredParameters();
|
||||
|
||||
/**
|
||||
* Get the compatible events
|
||||
*
|
||||
* @abstract
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getCompatibleEvents();
|
||||
|
||||
/**
|
||||
* Check if the event data meet the action condition
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function hasRequiredCondition(array $data);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Core\Registry $registry Regsitry instance
|
||||
* @param integer $project_id Project id
|
||||
* @param string $event_name Attached event name
|
||||
*/
|
||||
public function __construct($project_id)
|
||||
public function __construct(Registry $registry, $project_id, $event_name)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
$this->project_id = $project_id;
|
||||
$this->event_name = $event_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load automatically models
|
||||
*
|
||||
* @access public
|
||||
* @param string $name Model name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return Tool::loadModel($this->registry, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -101,11 +167,34 @@ abstract class Base implements Listener
|
|||
*/
|
||||
public function isExecutable(array $data)
|
||||
{
|
||||
if (isset($data['project_id']) && $data['project_id'] == $this->project_id && $this->hasRequiredParameters($data)) {
|
||||
return true;
|
||||
}
|
||||
return $this->hasCompatibleEvent() &&
|
||||
$this->hasRequiredProject($data) &&
|
||||
$this->hasRequiredParameters($data) &&
|
||||
$this->hasRequiredCondition($data);
|
||||
}
|
||||
|
||||
return false;
|
||||
/**
|
||||
* Check if the event is compatible with the action
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCompatibleEvent()
|
||||
{
|
||||
return in_array($this->event_name, $this->getCompatibleEvents());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the event data has the required project
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRequiredProject(array $data)
|
||||
{
|
||||
return isset($data['project_id']) && $data['project_id'] == $this->project_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -118,7 +207,9 @@ abstract class Base implements Listener
|
|||
public function hasRequiredParameters(array $data)
|
||||
{
|
||||
foreach ($this->getEventRequiredParameters() as $parameter) {
|
||||
if (! isset($data[$parameter])) return false;
|
||||
if (! isset($data[$parameter])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -139,15 +230,4 @@ abstract class Base implements Listener
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return class information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,16 @@ use Model\Task;
|
|||
class TaskAssignCategoryColor extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
return array(
|
||||
Task::EVENT_CREATE_UPDATE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +54,7 @@ class TaskAssignCategoryColor extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
* Execute the action (change the category)
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
|
|
@ -70,16 +62,23 @@ class TaskAssignCategoryColor extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['color_id'] == $this->getParam('color_id')) {
|
||||
$values = array(
|
||||
'id' => $data['task_id'],
|
||||
'category_id' => $this->getParam('category_id'),
|
||||
);
|
||||
|
||||
$this->task->update(array(
|
||||
'id' => $data['task_id'],
|
||||
'category_id' => $this->getParam('category_id'),
|
||||
), false);
|
||||
return $this->task->update($values, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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['color_id'] == $this->getParam('color_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,16 @@ use Model\Task;
|
|||
class TaskAssignColorCategory extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
return array(
|
||||
Task::EVENT_CREATE_UPDATE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +54,7 @@ class TaskAssignColorCategory extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
* Execute the action (change the task color)
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
|
|
@ -70,16 +62,23 @@ class TaskAssignColorCategory extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['category_id'] == $this->getParam('category_id')) {
|
||||
$values = array(
|
||||
'id' => $data['task_id'],
|
||||
'color_id' => $this->getParam('color_id'),
|
||||
);
|
||||
|
||||
$this->task->update(array(
|
||||
'id' => $data['task_id'],
|
||||
'color_id' => $this->getParam('color_id'),
|
||||
), false);
|
||||
return $this->task->update($values, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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['category_id'] == $this->getParam('category_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,17 @@ use Model\Task;
|
|||
class TaskAssignColorUser extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
return array(
|
||||
Task::EVENT_CREATE,
|
||||
Task::EVENT_ASSIGNEE_CHANGE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +55,7 @@ class TaskAssignColorUser extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
* Execute the action (change the task color)
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
|
|
@ -70,16 +63,23 @@ class TaskAssignColorUser extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['owner_id'] == $this->getParam('user_id')) {
|
||||
$values = array(
|
||||
'id' => $data['task_id'],
|
||||
'color_id' => $this->getParam('color_id'),
|
||||
);
|
||||
|
||||
$this->task->update(array(
|
||||
'id' => $data['task_id'],
|
||||
'color_id' => $this->getParam('color_id'),
|
||||
), false);
|
||||
return $this->task->update($values, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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['owner_id'] == $this->getParam('user_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace Action;
|
||||
|
||||
use Model\Task;
|
||||
use Model\Acl;
|
||||
|
||||
/**
|
||||
* Assign a task to the logged user
|
||||
|
|
@ -14,34 +13,17 @@ use Model\Acl;
|
|||
class TaskAssignCurrentUser extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Acl model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Acl
|
||||
*/
|
||||
private $acl;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @param \Model\Acl $acl Acl model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task, Acl $acl)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
$this->acl = $acl;
|
||||
return array(
|
||||
Task::EVENT_CREATE,
|
||||
Task::EVENT_MOVE_COLUMN,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,16 +62,23 @@ class TaskAssignCurrentUser extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['column_id'] == $this->getParam('column_id')) {
|
||||
$values = array(
|
||||
'id' => $data['task_id'],
|
||||
'owner_id' => $this->acl->getUserId(),
|
||||
);
|
||||
|
||||
$this->task->update(array(
|
||||
'id' => $data['task_id'],
|
||||
'owner_id' => $this->acl->getUserId(),
|
||||
), false);
|
||||
return $this->task->update($values, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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['column_id'] == $this->getParam('column_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,17 @@ use Model\Task;
|
|||
class TaskAssignSpecificUser extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
return array(
|
||||
Task::EVENT_CREATE_UPDATE,
|
||||
Task::EVENT_MOVE_COLUMN,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +55,7 @@ class TaskAssignSpecificUser extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
* Execute the action (assign the given user)
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
|
|
@ -70,16 +63,23 @@ class TaskAssignSpecificUser extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['column_id'] == $this->getParam('column_id')) {
|
||||
$values = array(
|
||||
'id' => $data['task_id'],
|
||||
'owner_id' => $this->getParam('user_id'),
|
||||
);
|
||||
|
||||
$this->task->update(array(
|
||||
'id' => $data['task_id'],
|
||||
'owner_id' => $this->getParam('user_id'),
|
||||
), false);
|
||||
return $this->task->update($values, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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['column_id'] == $this->getParam('column_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Action;
|
||||
|
||||
use Model\GithubWebhook;
|
||||
use Model\Task;
|
||||
|
||||
/**
|
||||
|
|
@ -13,24 +14,17 @@ use Model\Task;
|
|||
class TaskClose extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
return array(
|
||||
Task::EVENT_MOVE_COLUMN,
|
||||
GithubWebhook::EVENT_COMMIT,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,9 +35,12 @@ class TaskClose extends Base
|
|||
*/
|
||||
public function getActionRequiredParameters()
|
||||
{
|
||||
return array(
|
||||
'column_id' => t('Column'),
|
||||
);
|
||||
switch ($this->event_name) {
|
||||
case GithubWebhook::EVENT_COMMIT:
|
||||
return array();
|
||||
default:
|
||||
return array('column_id' => t('Column'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,14 +51,16 @@ class TaskClose extends Base
|
|||
*/
|
||||
public function getEventRequiredParameters()
|
||||
{
|
||||
return array(
|
||||
'task_id',
|
||||
'column_id',
|
||||
);
|
||||
switch ($this->event_name) {
|
||||
case GithubWebhook::EVENT_COMMIT:
|
||||
return array('task_id');
|
||||
default:
|
||||
return array('task_id', 'column_id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
* Execute the action (close the task)
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
|
|
@ -69,11 +68,23 @@ class TaskClose extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['column_id'] == $this->getParam('column_id')) {
|
||||
$this->task->close($data['task_id']);
|
||||
return true;
|
||||
}
|
||||
return $this->task->close($data['task_id']);
|
||||
}
|
||||
|
||||
return 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)
|
||||
{
|
||||
switch ($this->event_name) {
|
||||
case GithubWebhook::EVENT_COMMIT:
|
||||
return true;
|
||||
default:
|
||||
return $data['column_id'] == $this->getParam('column_id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,17 @@ use Model\Task;
|
|||
class TaskDuplicateAnotherProject extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
return array(
|
||||
Task::EVENT_MOVE_COLUMN,
|
||||
Task::EVENT_CLOSE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,7 +56,7 @@ class TaskDuplicateAnotherProject extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
* Execute the action (duplicate the task to another project)
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
|
|
@ -71,14 +64,20 @@ class TaskDuplicateAnotherProject extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['column_id'] == $this->getParam('column_id') && $data['project_id'] != $this->getParam('project_id')) {
|
||||
$task = $this->task->getById($data['task_id']);
|
||||
$this->task->duplicateToAnotherProject($this->getParam('project_id'), $task);
|
||||
return true;
|
||||
}
|
||||
|
||||
$task = $this->task->getById($data['task_id']);
|
||||
$this->task->duplicateToAnotherProject($this->getParam('project_id'), $task);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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['column_id'] == $this->getParam('column_id') && $data['project_id'] != $this->getParam('project_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,17 @@ use Model\Task;
|
|||
class TaskMoveAnotherProject extends Base
|
||||
{
|
||||
/**
|
||||
* Task model
|
||||
*
|
||||
* @accesss private
|
||||
* @var \Model\Task
|
||||
*/
|
||||
private $task;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param \Model\Task $task Task model instance
|
||||
* @return array
|
||||
*/
|
||||
public function __construct($project_id, Task $task)
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
parent::__construct($project_id);
|
||||
$this->task = $task;
|
||||
return array(
|
||||
Task::EVENT_MOVE_COLUMN,
|
||||
Task::EVENT_CLOSE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,7 +56,7 @@ class TaskMoveAnotherProject extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Execute the action
|
||||
* Execute the action (move the task to another project)
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
|
|
@ -71,14 +64,20 @@ class TaskMoveAnotherProject extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
if ($data['column_id'] == $this->getParam('column_id') && $data['project_id'] != $this->getParam('project_id')) {
|
||||
$task = $this->task->getById($data['task_id']);
|
||||
$this->task->moveToAnotherProject($this->getParam('project_id'), $task);
|
||||
return true;
|
||||
}
|
||||
|
||||
$task = $this->task->getById($data['task_id']);
|
||||
$this->task->moveToAnotherProject($this->getParam('project_id'), $task);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 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['column_id'] == $this->getParam('column_id') && $data['project_id'] != $this->getParam('project_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,30 @@ class Action extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Define action parameters (step 2)
|
||||
* Choose the event according to the action (step 2)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function event()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$values = $this->request->getValues();
|
||||
|
||||
if (empty($values['action_name']) || empty($values['project_id'])) {
|
||||
$this->response->redirect('?controller=action&action=index&project_id='.$project['id']);
|
||||
}
|
||||
|
||||
$this->response->html($this->projectLayout('action_event', array(
|
||||
'values' => $values,
|
||||
'project' => $project,
|
||||
'events' => $this->action->getCompatibleEvents($values['action_name']),
|
||||
'menu' => 'projects',
|
||||
'title' => t('Automatic actions')
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define action parameters (step 3)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
|
@ -45,14 +68,27 @@ class Action extends Base
|
|||
{
|
||||
$project = $this->getProject();
|
||||
$values = $this->request->getValues();
|
||||
$action = $this->action->load($values['action_name'], $values['project_id']);
|
||||
|
||||
if (empty($values['action_name']) || empty($values['project_id']) || empty($values['event_name'])) {
|
||||
$this->response->redirect('?controller=action&action=index&project_id='.$project['id']);
|
||||
}
|
||||
|
||||
$action = $this->action->load($values['action_name'], $values['project_id'], $values['event_name']);
|
||||
$action_params = $action->getActionRequiredParameters();
|
||||
|
||||
if (empty($action_params)) {
|
||||
$this->doCreation($project, $values + array('params' => array()));
|
||||
}
|
||||
|
||||
$projects_list = $this->project->getList(false);
|
||||
unset($projects_list[$project['id']]);
|
||||
|
||||
$this->response->html($this->projectLayout('action_params', array(
|
||||
'values' => $values,
|
||||
'action_params' => $action->getActionRequiredParameters(),
|
||||
'action_params' => $action_params,
|
||||
'columns_list' => $this->board->getColumnsList($project['id']),
|
||||
'users_list' => $this->projectPermission->getUsersList($project['id']),
|
||||
'projects_list' => $this->project->getList(false),
|
||||
'projects_list' => $projects_list,
|
||||
'colors_list' => $this->color->getList(),
|
||||
'categories_list' => $this->category->getList($project['id']),
|
||||
'project' => $project,
|
||||
|
|
@ -68,9 +104,18 @@ class Action extends Base
|
|||
*/
|
||||
public function create()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$values = $this->request->getValues();
|
||||
$this->doCreation($this->getProject(), $this->request->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the action
|
||||
*
|
||||
* @access private
|
||||
* @param array $project Project properties
|
||||
* @param array $values Form values
|
||||
*/
|
||||
private function doCreation(array $project, array $values)
|
||||
{
|
||||
list($valid,) = $this->action->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
'[%s][Position Change] %s (#%d)' => '[%s][Cambia Posición] %s (#%d)',
|
||||
'[%s][Assignee Change] %s (#%d)' => '[%s][Cambia Persona Asignada] %s (#%d)',
|
||||
'New password for the user "%s"' => 'Nueva contraseña para el usuario "%s"',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
'[%s][Position Change] %s (#%d)' => '[%s][Changement de position] %s (#%d)',
|
||||
'[%s][Assignee Change] %s (#%d)' => '[%s][Changement d\'assigné] %s (#%d)',
|
||||
'New password for the user "%s"' => 'Nouveau mot de passe pour l\'utilisateur « %s »',
|
||||
'Choose an event' => 'Choisir un événement',
|
||||
'Github commit received' => '« Commit » reçu via Github',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -503,4 +503,6 @@ return array(
|
|||
// '[%s][Position Change] %s (#%d)' => '',
|
||||
// '[%s][Assignee Change] %s (#%d)' => '',
|
||||
// 'New password for the user "%s"' => '',
|
||||
// 'Choose an event' => '',
|
||||
// 'Github commit received' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Action extends Base
|
|||
public function getAvailableActions()
|
||||
{
|
||||
return array(
|
||||
'TaskClose' => t('Close the task'),
|
||||
'TaskClose' => t('Close a task'),
|
||||
'TaskAssignSpecificUser' => t('Assign the task to a specific user'),
|
||||
'TaskAssignCurrentUser' => t('Assign the task to the person who does the action'),
|
||||
'TaskDuplicateAnotherProject' => t('Duplicate the task to another project'),
|
||||
|
|
@ -58,7 +58,6 @@ class Action extends Base
|
|||
{
|
||||
return array(
|
||||
Task::EVENT_MOVE_COLUMN => t('Move a task to another column'),
|
||||
Task::EVENT_MOVE_POSITION => t('Move a task to another position in the same column'),
|
||||
Task::EVENT_UPDATE => t('Task modification'),
|
||||
Task::EVENT_CREATE => t('Task creation'),
|
||||
Task::EVENT_OPEN => t('Open a closed task'),
|
||||
|
|
@ -69,6 +68,28 @@ class Action extends Base
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name and description of compatible actions
|
||||
*
|
||||
* @access public
|
||||
* @param string $action_name Action name
|
||||
* @return array
|
||||
*/
|
||||
public function getCompatibleEvents($action_name)
|
||||
{
|
||||
$action = $this->load($action_name, 0, '');
|
||||
$compatible_events = $action->getCompatibleEvents();
|
||||
$events = array();
|
||||
|
||||
foreach ($this->getAvailableEvents() as $event_name => $event_description) {
|
||||
if (in_array($event_name, $compatible_events)) {
|
||||
$events[$event_name] = $event_description;
|
||||
}
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return actions and parameters for a given project
|
||||
*
|
||||
|
|
@ -116,7 +137,7 @@ class Action extends Base
|
|||
|
||||
foreach ($this->getAll() as $action) {
|
||||
|
||||
$action = $this->load($action['action_name'], $action['project_id']);
|
||||
$action = $this->load($action['action_name'], $action['project_id'], $action['event_name']);
|
||||
$params += $action->getActionRequiredParameters();
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +223,7 @@ class Action extends Base
|
|||
{
|
||||
foreach ($this->getAll() as $action) {
|
||||
|
||||
$listener = $this->load($action['action_name'], $action['project_id']);
|
||||
$listener = $this->load($action['action_name'], $action['project_id'], $action['event_name']);
|
||||
|
||||
foreach ($action['params'] as $param) {
|
||||
$listener->setParam($param['name'], $param['value']);
|
||||
|
|
@ -216,21 +237,15 @@ class Action extends Base
|
|||
* Load an action
|
||||
*
|
||||
* @access public
|
||||
* @param string $name Action class name
|
||||
* @param integer $project_id Project id
|
||||
* @throws \LogicException
|
||||
* @return \Core\Listener Action Instance
|
||||
* @param string $name Action class name
|
||||
* @param integer $project_id Project id
|
||||
* @param string $event Event name
|
||||
* @return \Core\Listener Action instance
|
||||
*/
|
||||
public function load($name, $project_id)
|
||||
public function load($name, $project_id, $event)
|
||||
{
|
||||
$className = '\Action\\'.$name;
|
||||
|
||||
if ($name === 'TaskAssignCurrentUser') {
|
||||
return new $className($project_id, new Task($this->registry), new Acl($this->registry));
|
||||
}
|
||||
else {
|
||||
return new $className($project_id, new Task($this->registry));
|
||||
}
|
||||
return new $className($this->registry, $project_id, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -690,6 +690,9 @@ class Task extends Base
|
|||
$values['position'] = $this->countByColumnId($project_id, $values['column_id']) + 1;
|
||||
$values['project_id'] = $project_id;
|
||||
|
||||
// The task will be open (close event binding)
|
||||
$values['is_active'] = 1;
|
||||
|
||||
if ($this->db->table(self::TABLE)->eq('id', $task['id'])->update($values)) {
|
||||
return $task['id'];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<div class="page-header">
|
||||
<h2><?= t('Automatic actions for the project "%s"', $project['name']) ?></h2>
|
||||
</div>
|
||||
|
||||
<h3><?= t('Choose an event') ?></h3>
|
||||
<form method="post" action="?controller=action&action=params&project_id=<?= $project['id'] ?>" autocomplete="off">
|
||||
<?= Helper\form_csrf() ?>
|
||||
<?= Helper\form_hidden('project_id', $values) ?>
|
||||
<?= Helper\form_hidden('action_name', $values) ?>
|
||||
|
||||
<?= Helper\form_label(t('Event'), 'event_name') ?>
|
||||
<?= Helper\form_select('event_name', $events, $values) ?><br/>
|
||||
|
||||
<div class="form-help">
|
||||
<?= t('When the selected event occurs execute the corresponding action.') ?>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?= t('Next step') ?>" class="btn btn-blue"/>
|
||||
<?= t('or') ?> <a href="?controller=action&action=index&project_id=<?= $project['id'] ?>"><?= t('cancel') ?></a>
|
||||
</div>
|
||||
</form>
|
||||
|
|
@ -50,20 +50,13 @@
|
|||
<?php endif ?>
|
||||
|
||||
<h3><?= t('Add an action') ?></h3>
|
||||
<form method="post" action="?controller=action&action=params&project_id=<?= $project['id'] ?>" autocomplete="off">
|
||||
<form method="post" action="?controller=action&action=event&project_id=<?= $project['id'] ?>" autocomplete="off">
|
||||
<?= Helper\form_csrf() ?>
|
||||
<?= Helper\form_hidden('project_id', $values) ?>
|
||||
|
||||
<?= Helper\form_label(t('Event'), 'event_name') ?>
|
||||
<?= Helper\form_select('event_name', $available_events, $values) ?><br/>
|
||||
|
||||
<?= Helper\form_label(t('Action'), 'action_name') ?>
|
||||
<?= Helper\form_select('action_name', $available_actions, $values) ?><br/>
|
||||
|
||||
<div class="form-help">
|
||||
<?= t('When the selected event occurs execute the corresponding action.') ?>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?= t('Next step') ?>" class="btn btn-blue"/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
<div class="page-header">
|
||||
<h2><?= t('Automatic actions for the project "%s"', $project['name']) ?></h2>
|
||||
</div>
|
||||
<section>
|
||||
|
||||
<h3><?= t('Define action parameters') ?></h3>
|
||||
<form method="post" action="?controller=action&action=create&project_id=<?= $project['id'] ?>" autocomplete="off">
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class ActionTaskAssignColorCategory extends Base
|
|||
{
|
||||
public function testBadProject()
|
||||
{
|
||||
$action = new Action\TaskAssignColorCategory(3, new Task($this->registry));
|
||||
$action = new Action\TaskAssignColorCategory($this->registry, 3, Task::EVENT_CREATE_UPDATE);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 2,
|
||||
|
|
@ -24,7 +24,7 @@ class ActionTaskAssignColorCategory extends Base
|
|||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new Action\TaskAssignColorCategory(1, new Task($this->registry));
|
||||
$action = new Action\TaskAssignColorCategory($this->registry, 1, Task::EVENT_CREATE_UPDATE);
|
||||
$action->setParam('category_id', 1);
|
||||
$action->setParam('color_id', 'blue');
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class ActionTaskAssignColorUser extends Base
|
|||
{
|
||||
public function testBadProject()
|
||||
{
|
||||
$action = new Action\TaskAssignColorUser(3, new Task($this->registry));
|
||||
$action = new Action\TaskAssignColorUser($this->registry, 3, Task::EVENT_CREATE);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 2,
|
||||
|
|
@ -23,7 +23,7 @@ class ActionTaskAssignColorUser extends Base
|
|||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new Action\TaskAssignColorUser(1, new Task($this->registry));
|
||||
$action = new Action\TaskAssignColorUser($this->registry, 1, Task::EVENT_ASSIGNEE_CHANGE);
|
||||
$action->setParam('user_id', 1);
|
||||
$action->setParam('color_id', 'blue');
|
||||
|
||||
|
|
@ -33,11 +33,10 @@ class ActionTaskAssignColorUser extends Base
|
|||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green')));
|
||||
|
||||
// We create an event to move the task to the 2nd column with a user id 5
|
||||
// We change the assignee
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 2,
|
||||
'owner_id' => 5,
|
||||
);
|
||||
|
||||
|
|
@ -50,11 +49,10 @@ class ActionTaskAssignColorUser extends Base
|
|||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals('green', $task['color_id']);
|
||||
|
||||
// We create an event to move the task to the 2nd column with a user id 1
|
||||
// We change the assignee
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 2,
|
||||
'owner_id' => 1,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class ActionTaskAssignCurrentUser extends Base
|
|||
{
|
||||
public function testBadProject()
|
||||
{
|
||||
$action = new Action\TaskAssignCurrentUser(3, new Task($this->registry), new Acl($this->registry));
|
||||
$action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -25,7 +25,7 @@ class ActionTaskAssignCurrentUser extends Base
|
|||
|
||||
public function testBadColumn()
|
||||
{
|
||||
$action = new Action\TaskAssignCurrentUser(3, new Task($this->registry), new Acl($this->registry));
|
||||
$action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -39,7 +39,7 @@ class ActionTaskAssignCurrentUser extends Base
|
|||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new Action\TaskAssignCurrentUser(1, new Task($this->registry), new Acl($this->registry));
|
||||
$action = new Action\TaskAssignCurrentUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 2);
|
||||
$_SESSION = array(
|
||||
'user' => array('id' => 5)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class ActionTaskAssignSpecificUser extends Base
|
|||
{
|
||||
public function testBadProject()
|
||||
{
|
||||
$action = new Action\TaskAssignSpecificUser(3, new Task($this->registry));
|
||||
$action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -24,7 +24,7 @@ class ActionTaskAssignSpecificUser extends Base
|
|||
|
||||
public function testBadColumn()
|
||||
{
|
||||
$action = new Action\TaskAssignSpecificUser(3, new Task($this->registry));
|
||||
$action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -38,7 +38,7 @@ class ActionTaskAssignSpecificUser extends Base
|
|||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new Action\TaskAssignSpecificUser(1, new Task($this->registry));
|
||||
$action = new Action\TaskAssignSpecificUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 2);
|
||||
$action->setParam('user_id', 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,51 @@ require_once __DIR__.'/Base.php';
|
|||
|
||||
use Model\Task;
|
||||
use Model\Project;
|
||||
use Model\GithubWebhook;
|
||||
|
||||
class ActionTaskCloseTest extends Base
|
||||
{
|
||||
public function testExecutable()
|
||||
{
|
||||
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 3,
|
||||
'task_id' => 3,
|
||||
'column_id' => 5,
|
||||
);
|
||||
|
||||
$this->assertTrue($action->isExecutable($event));
|
||||
|
||||
$action = new Action\TaskClose($this->registry, 3, GithubWebhook::EVENT_COMMIT);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 3,
|
||||
'task_id' => 3,
|
||||
);
|
||||
|
||||
$this->assertTrue($action->isExecutable($event));
|
||||
}
|
||||
|
||||
public function testBadEvent()
|
||||
{
|
||||
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_UPDATE);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 3,
|
||||
'task_id' => 3,
|
||||
'column_id' => 5,
|
||||
);
|
||||
|
||||
$this->assertFalse($action->isExecutable($event));
|
||||
$this->assertFalse($action->execute($event));
|
||||
}
|
||||
|
||||
public function testBadProject()
|
||||
{
|
||||
$action = new Action\TaskClose(3, new Task($this->registry));
|
||||
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -24,7 +63,7 @@ class ActionTaskCloseTest extends Base
|
|||
|
||||
public function testBadColumn()
|
||||
{
|
||||
$action = new Action\TaskClose(3, new Task($this->registry));
|
||||
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -38,7 +77,7 @@ class ActionTaskCloseTest extends Base
|
|||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new Action\TaskClose(1, new Task($this->registry));
|
||||
$action = new Action\TaskClose($this->registry, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 2);
|
||||
|
||||
// We create a task in the first column
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class ActionTaskDuplicateAnotherProject extends Base
|
|||
{
|
||||
public function testBadProject()
|
||||
{
|
||||
$action = new Action\TaskDuplicateAnotherProject(3, new Task($this->registry));
|
||||
$action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -24,7 +24,7 @@ class ActionTaskDuplicateAnotherProject extends Base
|
|||
|
||||
public function testBadColumn()
|
||||
{
|
||||
$action = new Action\TaskDuplicateAnotherProject(3, new Task($this->registry));
|
||||
$action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -38,7 +38,7 @@ class ActionTaskDuplicateAnotherProject extends Base
|
|||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new Action\TaskDuplicateAnotherProject(1, new Task($this->registry));
|
||||
$action = new Action\TaskDuplicateAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
|
||||
|
||||
// We create a task in the first column
|
||||
$t = new Task($this->registry);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class ActionTaskMoveAnotherProject extends Base
|
|||
{
|
||||
public function testBadProject()
|
||||
{
|
||||
$action = new Action\TaskMoveAnotherProject(3, new Task($this->registry));
|
||||
$action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -24,7 +24,7 @@ class ActionTaskMoveAnotherProject extends Base
|
|||
|
||||
public function testBadColumn()
|
||||
{
|
||||
$action = new Action\TaskMoveAnotherProject(3, new Task($this->registry));
|
||||
$action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 5);
|
||||
|
||||
$event = array(
|
||||
|
|
@ -38,7 +38,7 @@ class ActionTaskMoveAnotherProject extends Base
|
|||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new Action\TaskMoveAnotherProject(1, new Task($this->registry));
|
||||
$action = new Action\TaskMoveAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
|
||||
|
||||
// We create a task in the first column
|
||||
$t = new Task($this->registry);
|
||||
|
|
|
|||
|
|
@ -95,92 +95,6 @@ class ActionTest extends Base
|
|||
$this->assertEquals(0, $t1['is_active']);
|
||||
}
|
||||
|
||||
public function testEventMovePosition()
|
||||
{
|
||||
$task = new Task($this->registry);
|
||||
$board = new Board($this->registry);
|
||||
$project = new Project($this->registry);
|
||||
$action = new Action($this->registry);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $task->create(array(
|
||||
'title' => 'unit_test 0',
|
||||
'project_id' => 1,
|
||||
'owner_id' => 1,
|
||||
'color_id' => 'red',
|
||||
'column_id' => 1,
|
||||
'category_id' => 1,
|
||||
)));
|
||||
|
||||
$this->assertEquals(2, $task->create(array(
|
||||
'title' => 'unit_test 1',
|
||||
'project_id' => 1,
|
||||
'owner_id' => 1,
|
||||
'color_id' => 'yellow',
|
||||
'column_id' => 1,
|
||||
'category_id' => 1,
|
||||
)));
|
||||
|
||||
// We create a new action, when the category_id=2 then the color_id should be green
|
||||
$this->assertTrue($action->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_MOVE_POSITION,
|
||||
'action_name' => 'TaskAssignColorCategory',
|
||||
'params' => array(
|
||||
'category_id' => 1,
|
||||
'color_id' => 'green',
|
||||
)
|
||||
)));
|
||||
|
||||
// We bind events
|
||||
$action->attachEvents();
|
||||
|
||||
$this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskAssignColorCategory'));
|
||||
|
||||
// Our task should have the color red and position=1
|
||||
$t1 = $task->getById(1);
|
||||
$this->assertEquals(1, $t1['position']);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('red', $t1['color_id']);
|
||||
|
||||
$t1 = $task->getById(2);
|
||||
$this->assertEquals(2, $t1['position']);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('yellow', $t1['color_id']);
|
||||
|
||||
// We move our tasks
|
||||
$this->assertTrue($task->movePosition(1, 1, 1, 10)); // task #1 to the end of the column
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
|
||||
$t1 = $task->getById(1);
|
||||
$this->assertEquals(2, $t1['position']);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('green', $t1['color_id']);
|
||||
|
||||
$t1 = $task->getById(2);
|
||||
$this->assertEquals(1, $t1['position']);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('yellow', $t1['color_id']);
|
||||
|
||||
$this->registry->shared('event')->clearTriggeredEvents();
|
||||
$this->assertTrue($task->movePosition(1, 2, 1, 44)); // task #2 to position 1
|
||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
$this->assertEquals('Action\TaskAssignColorCategory', $this->registry->shared('event')->getLastListenerExecuted());
|
||||
|
||||
$t1 = $task->getById(1);
|
||||
$this->assertEquals(1, $t1['position']);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('green', $t1['color_id']);
|
||||
|
||||
$t1 = $task->getById(2);
|
||||
$this->assertEquals(2, $t1['position']);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals('green', $t1['color_id']);
|
||||
}
|
||||
|
||||
public function testExecuteMultipleActions()
|
||||
{
|
||||
$task = new Task($this->registry);
|
||||
|
|
|
|||
Loading…
Reference in New Issue