From 022922313f5429431e192923ea6dd202e8da98e4 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Fri, 14 Jun 2019 00:06:38 +0500 Subject: [PATCH] Allow promoting tasks to the top level --- project_amber/helpers/task.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/project_amber/helpers/task.py b/project_amber/helpers/task.py index 6f0d953..e56dbaf 100644 --- a/project_amber/helpers/task.py +++ b/project_amber/helpers/task.py @@ -65,13 +65,18 @@ def updateTask(task_id: int, uid: int, **kwargs) -> int: if "status" in kwargs and not kwargs["status"] is None: task.status = kwargs["status"] if "parent_id" in kwargs and not kwargs["parent_id"] is None: - # TODO: we limit changing parent IDs to prevent circular deps, - # can this be done better? - new_parent = getTask(kwargs["parent_id"], uid) - if new_parent.gen > task.gen and task.is_child(): - raise BadRequest(MSG_TASK_DANGEROUS) - task.parent_id = new_parent.id - updateChildren(task.id) + if kwargs["parent_id"] == 0: + # promote task to the top level + task.parent_id = None + updateChildren(task.id) + else: + # TODO: we limit changing parent IDs to prevent circular deps, + # can this be done better? + new_parent = getTask(kwargs["parent_id"], uid) + if new_parent.gen > task.gen and task.is_child(): + raise BadRequest(MSG_TASK_DANGEROUS) + task.parent_id = new_parent.id + updateChildren(task.id) task.last_mod_time = time() db.session.commit() return task_id