summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrafacamargo123 <rafacamargo123@gmail.com>2018-12-27 17:44:49 -0200
committerfguillot <fred@kanboard.net>2018-12-27 11:44:49 -0800
commit30e9c221399c80696d6e317af1470868589dcd13 (patch)
treea61b35d8cf0dc8ae210537c83faceca4645eae9b
parent44c69863ebaf107ba3eeec4dbdba015829e453cb (diff)
Fix import of automatic actions when parameters are "unassigned" or "no category"
-rw-r--r--app/Model/ActionParameterModel.php6
-rw-r--r--tests/units/Model/ProjectDuplicationModelTest.php60
2 files changed, 66 insertions, 0 deletions
diff --git a/app/Model/ActionParameterModel.php b/app/Model/ActionParameterModel.php
index cdac396e..66c7adb4 100644
--- a/app/Model/ActionParameterModel.php
+++ b/app/Model/ActionParameterModel.php
@@ -147,6 +147,9 @@ class ActionParameterModel extends Base
case 'project_id':
return $value != $project_id ? $value : false;
case 'category_id':
+ if ($value == 0) {
+ return 0;
+ }
return $this->categoryModel->getIdByName($project_id, $this->categoryModel->getNameById($value)) ?: false;
case 'src_column_id':
case 'dest_column_id':
@@ -156,6 +159,9 @@ class ActionParameterModel extends Base
return empty($column) ? false : $this->columnModel->getColumnIdByTitle($project_id, $column['title']) ?: false;
case 'user_id':
case 'owner_id':
+ if ($value == 0) {
+ return 0;
+ }
return $this->projectPermissionModel->isAssignable($project_id, $value) ? $value : false;
case 'swimlane_id':
$column = $this->swimlaneModel->getById($value);
diff --git a/tests/units/Model/ProjectDuplicationModelTest.php b/tests/units/Model/ProjectDuplicationModelTest.php
index d27e9491..ac93d67c 100644
--- a/tests/units/Model/ProjectDuplicationModelTest.php
+++ b/tests/units/Model/ProjectDuplicationModelTest.php
@@ -386,6 +386,13 @@ class ProjectDuplicationModelTest extends Base
'params' => array('color_id' => 'blue', 'category_id' => 2),
)));
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignColorCategory',
+ 'params' => array('color_id' => 'red', 'category_id' => 0),
+ )));
+
$this->assertEquals(2, $projectDuplicationModel->duplicate(1));
$actions = $actionModel->getAllByProject(2);
@@ -395,8 +402,61 @@ class ProjectDuplicationModelTest extends Base
$this->assertNotEmpty($actions[0]['params']);
$this->assertEquals('blue', $actions[0]['params']['color_id']);
$this->assertEquals(5, $actions[0]['params']['category_id']);
+
+ $this->assertEquals('TaskAssignColorCategory', $actions[1]['action_name']);
+ $this->assertNotEmpty($actions[1]['params']);
+ $this->assertEquals('red', $actions[1]['params']['color_id']);
+ $this->assertEquals(0, $actions[1]['params']['category_id']);
}
+ public function testCloneProjectWithActionTaskAssignSpecificUser()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_VIEWER));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignSpecificUser',
+ 'params' => array('column_id' => 1, 'user_id' => 3),
+ )));
+
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignSpecificUser',
+ 'params' => array('column_id' => 2, 'user_id' => 0),
+ )));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $actions = $actionModel->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignSpecificUser', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals(5, $actions[0]['params']['column_id']);
+ $this->assertEquals(3, $actions[0]['params']['user_id']);
+
+ $this->assertEquals('TaskAssignSpecificUser', $actions[1]['action_name']);
+ $this->assertNotEmpty($actions[1]['params']);
+ $this->assertEquals(6, $actions[1]['params']['column_id']);
+ $this->assertEquals(0, $actions[1]['params']['user_id']);
+ }
+
public function testCloneProjectWithSwimlanes()
{
$projectModel = new ProjectModel($this->container);