Skip to content

Commit

Permalink
Bulk action being applied for all tasks fixed, due date exception han…
Browse files Browse the repository at this point in the history
…dled and queries bbox geojson serialized
  • Loading branch information
prabinoid committed Oct 22, 2024
1 parent c5896d1 commit ec7a03b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
3 changes: 2 additions & 1 deletion backend/api/projects/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def get_project(
finally:
# this will try to unlock tasks that have been locked too long
try:
# TODO
await ProjectService.auto_unlock_tasks(project_id, db)
except Exception as e:
logger.critical(str(e))
Expand Down Expand Up @@ -827,7 +828,7 @@ async def get(
)
try:
geojson = await ProjectSearchService.get_projects_geojson(search_dto, db)
return geojson, 200
return JSONResponse(content=geojson, status_code=200)
except BBoxTooBigError as e:
return JSONResponse(
content={"Error": str(e).split("-")[1], "SubCode": str(e).split("-")[0]},
Expand Down
6 changes: 4 additions & 2 deletions backend/models/postgis/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ async def update(self, project_dto: ProjectDTO, db: Database):
self.private = project_dto.private
self.difficulty = ProjectDifficulty[project_dto.difficulty.upper()].value
self.changeset_comment = project_dto.changeset_comment
self.due_date = project_dto.due_date.replace(tzinfo=None)
self.due_date = (
project_dto.due_date.replace(tzinfo=None) if project_dto.due_date else None
)
self.imagery = project_dto.imagery
self.josm_preset = project_dto.josm_preset
self.id_presets = project_dto.id_presets
Expand Down Expand Up @@ -1359,7 +1361,7 @@ async def get_project_summary(
ProjectTeamDTO(
team_id=team["team_id"],
team_name=team["team_name"],
role=TeamRoles(team["role"]).value,
role=TeamRoles(team["role"]),
)
for team in teams
]
Expand Down
56 changes: 40 additions & 16 deletions backend/models/postgis/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ async def auto_unlock_tasks(project_id: int, session):
for old_task_id in old_tasks:
task = await session.get(Task, (old_task_id, project_id))
if task:
await task.auto_unlock_expired_tasks(
await Task.auto_unlock_expired_tasks(
expiry_date, lock_duration, session
)

Expand Down Expand Up @@ -1104,13 +1104,14 @@ async def reset_task(task_id: int, project_id: int, user_id: int, db: Database):
mapped_by = NULL,
validated_by = NULL,
locked_by = NULL
WHERE id = :task_id
WHERE id = :task_id AND project_id = :project_id
"""
await db.execute(
query=update_task_query,
values={
"task_id": task_id,
"ready_status": TaskStatus.READY.value,
"project_id": project_id,
},
)

Expand Down Expand Up @@ -1228,22 +1229,29 @@ async def unlock_task(
update_query = """
UPDATE tasks
SET validated_by = NULL
WHERE id = :task_id
WHERE id = :task_id AND project_id = :project_id
"""
await db.execute(query=update_query, values={"task_id": task_id})
await db.execute(
query=update_query,
values={"task_id": task_id, "project_id": project_id},
)
elif new_state == TaskStatus.READY:
update_query = """
UPDATE tasks
SET mapped_by = NULL
WHERE id = :task_id
WHERE id = :task_id AND project_id = :project_id
"""
await db.execute(query=update_query, values={"task_id": task_id})
await db.execute(
query=update_query,
values={"task_id": task_id, "project_id": project_id},
)
else:
current_status_query = """
SELECT task_status FROM tasks WHERE id = :task_id
SELECT task_status FROM tasks WHERE id = :task_id AND project_id = :project_id
"""
current_status_result = await db.fetch_one(
query=current_status_query, values={"task_id": task_id}
query=current_status_query,
values={"task_id": task_id, "project_id": project_id},
)
current_status = TaskStatus(current_status_result["task_status"])
# Handle specific state changes
Expand All @@ -1254,10 +1262,15 @@ async def unlock_task(
update_query = """
UPDATE tasks
SET validated_by = :user_id
WHERE id = :task_id
WHERE id = :task_id AND project_id = :project_id
"""
await db.execute(
query=update_query, values={"user_id": user_id, "task_id": task_id}
query=update_query,
values={
"user_id": user_id,
"task_id": task_id,
"project_id": project_id,
},
)

elif new_state == TaskStatus.INVALIDATED:
Expand All @@ -1267,21 +1280,28 @@ async def unlock_task(
update_query = """
UPDATE tasks
SET mapped_by = NULL, validated_by = NULL
WHERE id = :task_id
WHERE id = :task_id AND project_id = :project_id
"""
await db.execute(query=update_query, values={"task_id": task_id})
await db.execute(
query=update_query,
values={"task_id": task_id, "project_id": project_id},
)

# Set `mapped_by` for MAPPED or BADIMAGERY states when not locked for validation
elif new_state in [TaskStatus.MAPPED, TaskStatus.BADIMAGERY]:
if current_status != TaskStatus.LOCKED_FOR_VALIDATION:
update_query = """
UPDATE tasks
SET mapped_by = :user_id
WHERE id = :task_id
WHERE id = :task_id AND project_id = :project_id
"""
await db.execute(
query=update_query,
values={"user_id": user_id, "task_id": task_id},
values={
"user_id": user_id,
"task_id": task_id,
"project_id": project_id,
},
)

# Update task locked duration in the history when `undo` is False
Expand All @@ -1293,11 +1313,15 @@ async def unlock_task(
final_update_query = """
UPDATE tasks
SET task_status = :new_status, locked_by = NULL
WHERE id = :task_id
WHERE id = :task_id AND project_id = :project_id
"""
await db.execute(
query=final_update_query,
values={"new_status": new_state.value, "task_id": task_id},
values={
"new_status": new_state.value,
"task_id": task_id,
"project_id": project_id,
},
)

@staticmethod
Expand Down
1 change: 0 additions & 1 deletion backend/services/validator_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ async def invalidate_all_tasks(project_id: int, user_id: int, db: Database):
"validated_status": TaskStatus.VALIDATED.value,
},
)

for task in validated_tasks:
await Task.lock_task_for_validating(task["id"], project_id, user_id, db)
await Task.unlock_task(
Expand Down

0 comments on commit ec7a03b

Please sign in to comment.