Skip to content

Commit

Permalink
Record task extension duration in action_text.
Browse files Browse the repository at this point in the history
------------------

In the previous implementation, there was an issue where the duration of a task extension was not being recorded when a task was extended and then unlocked/stopped. Prior to the implementation of the task lock extension feature, the last recorded action for a task was always either "LOCKED_FOR_MAPPING" or "LOCKED_FOR_VALIDATION," which matched the task status. To update the duration, we used the current task status as the last action to filter the task history and update the last entry with the lock duration.

However, after the task extension feature was introduced, two additional last actions were possible: "EXTENDED_FOR_MAPPING" and "EXTENDED_FOR_VALIDATION." This introduced a discrepancy between the last recorded action and the task status. For example, the task status could still be "LOCKED_FOR_MAPPING" even when a user had extended the task. As a result, the entry with the action "EXTENDED_FOR_MAPPING" in the task history was not being updated with the correct duration.

To address this issue, this commit fixed the problem by retrieving the last task action and using it as the filter criteria for updating the task history, rather than relying on the task status as the last action.
  • Loading branch information
Aadesh-Baral committed Sep 1, 2023
1 parent cb6990c commit ead59cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
28 changes: 18 additions & 10 deletions backend/models/postgis/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,16 @@ def unlock_task(
self, user_id, new_state=None, comment=None, undo=False, issues=None
):
"""Unlock task and ensure duration task locked is saved in History"""
# If not undo, update the duration of the lock
if not undo:
last_history = TaskHistory.get_last_action(self.project_id, self.id)
# To unlock a task the last action must have been either lock or extension
last_action = TaskAction[last_history.action]
TaskHistory.update_task_locked_with_duration(
self.id, self.project_id, last_action, user_id
)

# Only create new history after updating the duration since we need the last action to update the duration.
if comment:
self.set_task_history(
action=TaskAction.COMMENT,
Expand Down Expand Up @@ -822,28 +832,26 @@ def unlock_task(
self.mapped_by = None
self.validated_by = None

if not undo:
# Using a slightly evil side effect of Actions and Statuses having the same name here :)
TaskHistory.update_task_locked_with_duration(
self.id, self.project_id, TaskStatus(self.task_status), user_id
)

self.task_status = new_state.value
self.locked_by = None
self.update()

def reset_lock(self, user_id, comment=None):
"""Removes a current lock from a task, resets to last status and
updates history with duration of lock"""
last_history = TaskHistory.get_last_action(self.project_id, self.id)
# To reset a lock the last action must have been either lock or extension
last_action = TaskAction[last_history.action]
TaskHistory.update_task_locked_with_duration(
self.id, self.project_id, last_action, user_id
)

# Only set task history after updating the duration since we need the last action to update the duration.
if comment:
self.set_task_history(
action=TaskAction.COMMENT, comment=comment, user_id=user_id
)

# Using a slightly evil side effect of Actions and Statuses having the same name here :)
TaskHistory.update_task_locked_with_duration(
self.id, self.project_id, TaskStatus(self.task_status), user_id
)
self.clear_lock()

def clear_lock(self):
Expand Down
7 changes: 6 additions & 1 deletion backend/services/mapping_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,16 @@ def extend_task_lock_time(extend_dto: ExtendLockTimeDTO):
if task.task_status == TaskStatus.LOCKED_FOR_VALIDATION:
action = TaskAction.EXTENDED_FOR_VALIDATION

# Update the duration of the lock/extension before creating new history
last_history = TaskHistory.get_last_action(task.project_id, task.id)
# To reset a lock the last action must have been either lock or extension
last_action = TaskAction[last_history.action]
TaskHistory.update_task_locked_with_duration(
task_id,
extend_dto.project_id,
TaskStatus(task.task_status),
last_action,
extend_dto.user_id,
)

task.set_task_history(action, extend_dto.user_id)
task.update()

0 comments on commit ead59cb

Please sign in to comment.