diff --git a/app/Model/ActionParameterModel.php b/app/Model/ActionParameterModel.php index cdac396e5d..66c7adb464 100644 --- a/app/Model/ActionParameterModel.php +++ b/app/Model/ActionParameterModel.php @@ -147,6 +147,9 @@ private function resolveParameter($project_id, $name, $value) 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 @@ private function resolveParameter($project_id, $name, $value) 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 d27e94919e..ac93d67cc1 100644 --- a/tests/units/Model/ProjectDuplicationModelTest.php +++ b/tests/units/Model/ProjectDuplicationModelTest.php @@ -386,6 +386,13 @@ public function testCloneProjectWithActionTaskAssignColorCategory() '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 @@ public function testCloneProjectWithActionTaskAssignColorCategory() $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);