@@ -59,22 +59,31 @@ def get_task_as_dto(
59
59
@staticmethod
60
60
def _is_task_undoable (logged_in_user_id : int , task : Task ) -> bool :
61
61
"""Determines if the current task status can be undone by the logged in user"""
62
- # Test to see if user can undo status on this task
63
- if logged_in_user_id and TaskStatus (task .task_status ) not in [
62
+ # Check if task status is in a state that can be undone
63
+ if TaskStatus (task .task_status ) in [
64
64
TaskStatus .LOCKED_FOR_MAPPING ,
65
65
TaskStatus .LOCKED_FOR_VALIDATION ,
66
66
TaskStatus .READY ,
67
67
]:
68
- last_action = TaskHistory .get_last_action (task .project_id , task .id )
69
-
70
- # User requesting task made the last change, so they are allowed to undo it.
71
- is_user_permitted , _ = ProjectService .is_user_permitted_to_validate (
72
- task .project_id , logged_in_user_id
73
- ) # FLAGGED: Make use of error_reason
74
- if last_action .user_id == int (logged_in_user_id ) or is_user_permitted :
75
- return True
68
+ raise MappingServiceError (
69
+ "UndoNotAllowed- Task is in a state that cannot be undone"
70
+ )
71
+ # Test to see if user can undo status on this task
72
+ last_action = TaskHistory .get_last_action (task .project_id , task .id )
76
73
77
- return False # FLAGGED: Split out for permission and state
74
+ # User requesting task made the last change, so they are allowed to undo it.
75
+ is_user_permitted , _ = ProjectService .is_user_permitted_to_validate (
76
+ task .project_id , logged_in_user_id
77
+ )
78
+ if last_action .user_id == int (logged_in_user_id ) or is_user_permitted :
79
+ return True
80
+ else :
81
+ raise Forbidden (
82
+ sub_code = "USER_NOT_VALIDATOR" ,
83
+ user_id = logged_in_user_id ,
84
+ project_id = task .project_id ,
85
+ task_id = task .id ,
86
+ )
78
87
79
88
@staticmethod
80
89
def lock_task_for_mapping (lock_task_dto : LockTaskDTO ) -> TaskDTO :
0 commit comments