From ec67586cbc586402bd7d315e4651a9794d8d87f2 Mon Sep 17 00:00:00 2001 From: Rick van der Zwet Date: Tue, 5 Sep 2023 21:20:08 +0000 Subject: [PATCH] Fix update priority on task does not apply to taskwrapper The task object priority is servering asl 'dummy' for normal tasks. Related taskwrapper object should be updated as well, since the 'real' priority scheduling is done using the Taskwrapper object. Fixes: #989 --- ci/apiv2/test_task.py | 14 +++++++++++++- src/inc/apiv2/model/tasks.routes.php | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ci/apiv2/test_task.py b/ci/apiv2/test_task.py index 09c99f6d3..61b9fc0f2 100644 --- a/ci/apiv2/test_task.py +++ b/ci/apiv2/test_task.py @@ -1,4 +1,4 @@ -from hashtopolis import Task +from hashtopolis import Task, TaskWrapper from utils import BaseTest @@ -75,3 +75,15 @@ def test_task_with_file(self): task = self.create_task(hashlist, extra_payload=extra_payload) obj = Task.objects.get(pk=task.id, expand='files') self.assertListEqual([x.id for x in files], [x.id for x in obj.files_set]) + + def test_task_update_priority(self): + task = self.create_test_object() + obj = TaskWrapper.objects.get(pk=task.taskWrapperId) + self.assertEqual(task.priority, obj.priority) + + new_priority = task.priority + 1234 + task.priority = new_priority + task.save() + + obj = TaskWrapper.objects.get(pk=task.taskWrapperId) + self.assertEqual(new_priority, obj.priority) \ No newline at end of file diff --git a/src/inc/apiv2/model/tasks.routes.php b/src/inc/apiv2/model/tasks.routes.php index 24f7986cd..8199d6cf2 100644 --- a/src/inc/apiv2/model/tasks.routes.php +++ b/src/inc/apiv2/model/tasks.routes.php @@ -104,6 +104,13 @@ public function updateObject(object $object, $data, $processed = []): void { TaskUtils::archiveTask($object->getId(), $this->getCurrentUser()); } + /* Update connected TaskWrapper priority as well */ + $key = Task::PRIORITY; + if (array_key_exists($key, $data)) { + array_push($processed, $key); + TaskUtils::updatePriority($object->getId(), $data[Task::PRIORITY], $this->getCurrentUser()); + } + parent::updateObject($object, $data, $processed); } }