Skip to content

Commit ead59cb

Browse files
committed
Record task extension duration in action_text.
------------------ 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.
1 parent cb6990c commit ead59cb

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

backend/models/postgis/task.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,16 @@ def unlock_task(
784784
self, user_id, new_state=None, comment=None, undo=False, issues=None
785785
):
786786
"""Unlock task and ensure duration task locked is saved in History"""
787+
# If not undo, update the duration of the lock
788+
if not undo:
789+
last_history = TaskHistory.get_last_action(self.project_id, self.id)
790+
# To unlock a task the last action must have been either lock or extension
791+
last_action = TaskAction[last_history.action]
792+
TaskHistory.update_task_locked_with_duration(
793+
self.id, self.project_id, last_action, user_id
794+
)
795+
796+
# Only create new history after updating the duration since we need the last action to update the duration.
787797
if comment:
788798
self.set_task_history(
789799
action=TaskAction.COMMENT,
@@ -822,28 +832,26 @@ def unlock_task(
822832
self.mapped_by = None
823833
self.validated_by = None
824834

825-
if not undo:
826-
# Using a slightly evil side effect of Actions and Statuses having the same name here :)
827-
TaskHistory.update_task_locked_with_duration(
828-
self.id, self.project_id, TaskStatus(self.task_status), user_id
829-
)
830-
831835
self.task_status = new_state.value
832836
self.locked_by = None
833837
self.update()
834838

835839
def reset_lock(self, user_id, comment=None):
836840
"""Removes a current lock from a task, resets to last status and
837841
updates history with duration of lock"""
842+
last_history = TaskHistory.get_last_action(self.project_id, self.id)
843+
# To reset a lock the last action must have been either lock or extension
844+
last_action = TaskAction[last_history.action]
845+
TaskHistory.update_task_locked_with_duration(
846+
self.id, self.project_id, last_action, user_id
847+
)
848+
849+
# Only set task history after updating the duration since we need the last action to update the duration.
838850
if comment:
839851
self.set_task_history(
840852
action=TaskAction.COMMENT, comment=comment, user_id=user_id
841853
)
842854

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

849857
def clear_lock(self):

backend/services/mapping_service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,16 @@ def extend_task_lock_time(extend_dto: ExtendLockTimeDTO):
471471
if task.task_status == TaskStatus.LOCKED_FOR_VALIDATION:
472472
action = TaskAction.EXTENDED_FOR_VALIDATION
473473

474+
# Update the duration of the lock/extension before creating new history
475+
last_history = TaskHistory.get_last_action(task.project_id, task.id)
476+
# To reset a lock the last action must have been either lock or extension
477+
last_action = TaskAction[last_history.action]
474478
TaskHistory.update_task_locked_with_duration(
475479
task_id,
476480
extend_dto.project_id,
477-
TaskStatus(task.task_status),
481+
last_action,
478482
extend_dto.user_id,
479483
)
484+
480485
task.set_task_history(action, extend_dto.user_id)
481486
task.update()

0 commit comments

Comments
 (0)