Skip to content

Commit

Permalink
Fix import of automatic actions when parameters are "unassigned" or "…
Browse files Browse the repository at this point in the history
…no category"
  • Loading branch information
rafacamargo123 authored and fguillot committed Dec 27, 2018
1 parent 44c6986 commit 30e9c22
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Model/ActionParameterModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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);
Expand Down
60 changes: 60 additions & 0 deletions tests/units/Model/ProjectDuplicationModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 30e9c22

Please sign in to comment.