Skip to content

Commit

Permalink
[#487][#491] Improve locked date management in task updates
Browse files Browse the repository at this point in the history
Merge pull request #499 from Igalia/i491-enforce-locked-dates
  • Loading branch information
jaragunde authored Sep 14, 2021
2 parents fdceece + 7c84020 commit 2e9e9b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/admin/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To install PhpReport in your system, you will need the following software:

* PostgreSQL database server (tested with PostgreSQL 9)

* PHP 7.0 or higher
* PHP 7.3 or higher

* Support for PostgreSQL

Expand Down
5 changes: 3 additions & 2 deletions model/dao/TaskDAO/PostgreSQLTaskDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,22 +794,23 @@ private function checkOverlappingWithDBTasks($tasks) {
$tasksByDate = array();
$updatedTaskIds = array();
foreach ($tasks as $task) {
$date = $task->getDate()->format('Y-m-d');
//add normal task
if ($task->isNew()) {
$date = $task->getDate()->format('Y-m-d');
$tasksByDate[$date][] = $task;
}
//update dirty task
else if ($task->isDirty()) {
$originalTask = $this->getById($task->getId());
$originalTask->updateFrom($task);
$date = $originalTask->getDate()->format('Y-m-d');
$tasksByDate[$date][] = $originalTask;
$updatedTaskIds[] = $task->getId();
}
}

//evaluate every date independently
$userId = $tasks[0]->getUserId();
$userId = $tasks[array_key_first($tasks)]->getUserId();
foreach (array_keys($tasksByDate) as $index) {
$date = $tasksByDate[$index][0]->getDate();

Expand Down
15 changes: 13 additions & 2 deletions model/facade/action/PartialUpdateTasksAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ protected function doExecute() {

//first check permission on task write
foreach ($this->tasks as $i => $task) {
if(!$configDao->isWriteAllowedForDate($task->getDate()) ||
// Do not allow assigning a task to a locked date
if ($task->isDateDirty()) {
if(!$configDao->isWriteAllowedForDate($task->getDate())) {
$discardedTasks[] = $task;
unset($this->tasks[$i]);
continue;
}
}

// Do not allow updating tasks saved in locked dates or belonging
// to a different user
$oldTask = $taskDao->getById($task->getId());
if(!$configDao->isWriteAllowedForDate($oldTask->getDate()) ||
(!$taskDao->checkTaskUserId(
$task->getId(), $task->getUserId()))) {
$discardedTasks[] = $task;
Expand All @@ -103,7 +115,6 @@ protected function doExecute() {
}

// Do not allow updating tasks which belong to inactive projects
$oldTask = $taskDao->getById($task->getId());
$projectId = $oldTask->getProjectId();
$projectVO = $projectDAO->getById($projectId);
if (!$projectVO || !$projectVO->getActivation()) {
Expand Down

0 comments on commit 2e9e9b7

Please sign in to comment.