Do not override the creator_id with the current logged user if the task is imported

Fixes #5345
This commit is contained in:
Frédéric Guillot 2023-09-22 20:39:46 -07:00 committed by Frédéric Guillot
parent 4d9e108f45
commit b02133982a
2 changed files with 31 additions and 4 deletions

View File

@ -78,7 +78,8 @@ class TaskCreationModel extends Base
$values['title'] = t('Untitled');
}
if ($this->userSession->isLogged()) {
// Note: Do not override the creator_id if the task is imported
if (empty($values['creator_id']) && $this->userSession->isLogged()) {
$values['creator_id'] = $this->userSession->getId();
}

View File

@ -7,6 +7,7 @@ use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\UserModel;
class TaskCreationModelTest extends Base
{
@ -140,15 +141,40 @@ class TaskCreationModelTest extends Base
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$userModel = new UserModel($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'someone')));
$this->assertEquals(3, $userModel->create(array('username' => 'logged_user')));
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1)));
// Scenario 1: creator_id is defined and no logged user
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 2)));
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['creator_id']);
$this->assertEquals(2, $task['creator_id']);
// Scenario 2: creator_id is not defined and no logged user
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(2, $task['id']);
$this->assertEquals(0, $task['creator_id']);
// Scenario 3: creator_id is not defined and a user is logged
$_SESSION['user'] = array('id' => 3);
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$task = $taskFinderModel->getById(3);
$this->assertNotEmpty($task);
$this->assertEquals(3, $task['id']);
$this->assertEquals(3, $task['creator_id']);
// Scenario 4: creator_id is defined and it's different than the logged user
$this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 2)));
$task = $taskFinderModel->getById(4);
$this->assertNotEmpty($task);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['creator_id']);
}
public function testThatCreatorIsDefined()