Skip to content

Commit 0d15a4e

Browse files
authored
Merge pull request #19 from TaskarCenterAtUW/feature-changeset-submit
added Route to submit Changesets for task
2 parents 8920979 + 47e272c commit 0d15a4e

4 files changed

Lines changed: 119 additions & 31 deletions

File tree

api/src/tasking/tasks/dtos.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,25 @@ class FeedbackInput(WireModel):
110110

111111

112112
class SubmitRequest(WireModel):
113-
osm_changeset_id: int = PydField(ge=1)
113+
# osm_changeset_id: int = PydField(ge=1)
114114
done: bool
115115
feedback: Optional[FeedbackInput] = None
116116

117117

118+
class SubmitTaskChangeset(WireModel):
119+
osm_changeset_id: int = PydField(ge=1)
120+
121+
122+
class SubmitTaskChangesetResponse(WireModel):
123+
osm_changeset_id: int = PydField(ge=1)
124+
task_number: int
125+
project_id: int
126+
workspace_id: int
127+
inserted_id: Optional[int] = (
128+
None # ID of the newly inserted changeset row, if applicable
129+
)
130+
131+
118132
class ExistingLockSummary(WireModel):
119133
task_number: int
120134
task_status: TaskStatus

api/src/tasking/tasks/repository.py

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -972,29 +972,29 @@ async def submit(
972972

973973
now = datetime.now()
974974

975-
# Record the changeset row.
976-
cs = TaskingChangeset(
977-
task_id=task.id, # type: ignore[arg-type]
978-
project_id=project_id,
979-
lock_id=lock.id, # type: ignore[arg-type]
980-
user_auth_uid=str(current_user.user_uuid),
981-
osm_changeset_id=body.osm_changeset_id,
982-
submitted_at=now,
983-
)
984-
self.session.add(cs)
985-
await self.session.flush()
986-
987-
await self._audit(
988-
event_type=AuditEventType.CHANGESET_SUBMITTED,
989-
project_id=project_id,
990-
task_id=task.id,
991-
actor_uuid=current_user.user_uuid,
992-
details={
993-
"taskNumber": task.task_number,
994-
"osmChangesetId": body.osm_changeset_id,
995-
"done": body.done,
996-
},
997-
)
975+
# # Record the changeset row.
976+
# cs = TaskingChangeset(
977+
# task_id=task.id, # type: ignore[arg-type]
978+
# project_id=project_id,
979+
# lock_id=lock.id, # type: ignore[arg-type]
980+
# user_auth_uid=str(current_user.user_uuid),
981+
# osm_changeset_id=body.osm_changeset_id,
982+
# submitted_at=now,
983+
# )
984+
# self.session.add(cs)
985+
# await self.session.flush()
986+
987+
# await self._audit(
988+
# event_type=AuditEventType.CHANGESET_SUBMITTED,
989+
# project_id=project_id,
990+
# task_id=task.id,
991+
# actor_uuid=current_user.user_uuid,
992+
# details={
993+
# "taskNumber": task.task_number,
994+
# "osmChangesetId": body.osm_changeset_id,
995+
# "done": body.done,
996+
# },
997+
# )
998998

999999
if not body.done:
10001000
# Slide lock expiry from submitted_at + lock_timeout_hours.
@@ -1111,5 +1111,49 @@ async def submit(
11111111
refreshed = await self._get_task(project_id, task_number)
11121112
return await self._to_task_response(refreshed)
11131113

1114+
async def submit_changeset(
1115+
self,
1116+
workspace_id: int,
1117+
project_id: int,
1118+
task_number: int,
1119+
current_user: UserInfo,
1120+
changesetId: int,
1121+
) -> int:
1122+
project = await self._get_project(workspace_id, project_id)
1123+
task = await self._get_task(project_id, task_number)
1124+
lock = await self._get_active_lock(task.id) # type: ignore[arg-type]
1125+
if lock is None or lock.user_auth_uid != str(current_user.user_uuid):
1126+
raise ForbiddenException("Caller does not hold the active lock")
1127+
now = datetime.now()
1128+
1129+
# Record the changeset row.
1130+
cs = TaskingChangeset(
1131+
task_id=task.id, # type: ignore[arg-type]
1132+
project_id=project_id,
1133+
lock_id=lock.id, # type: ignore[arg-type]
1134+
user_auth_uid=str(current_user.user_uuid),
1135+
osm_changeset_id=changesetId,
1136+
submitted_at=now,
1137+
)
1138+
self.session.add(cs)
1139+
await self.session.flush()
1140+
# Get the id of the newly inserted changeset row
1141+
changeset_row_id = cs.id # type: ignore[assignment]
1142+
print(f"Inserted changeset row with ID: {changeset_row_id}")
1143+
1144+
# Audit record for changeset submission
1145+
await self._audit(
1146+
event_type=AuditEventType.CHANGESET_SUBMITTED,
1147+
project_id=project_id,
1148+
task_id=task.id,
1149+
actor_uuid=current_user.user_uuid,
1150+
details={
1151+
"taskNumber": task.task_number,
1152+
"osmChangesetId": changesetId,
1153+
},
1154+
)
1155+
await self.session.commit()
1156+
return cs.id # Return the ID of the newly inserted changeset row
1157+
11141158

11151159
__all__ = ["TaskingTaskRepository"]

api/src/tasking/tasks/routes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
SaveTasksRequest,
2222
SaveTasksResponse,
2323
SubmitRequest,
24+
SubmitTaskChangeset,
25+
SubmitTaskChangesetResponse,
2426
TaskBoundariesFeatureCollection,
2527
TaskListResponse,
2628
TaskResponse,
@@ -273,3 +275,32 @@ async def submit_task(
273275
return await task_repo.submit(
274276
workspace_id, project_id, task_number, current_user, body
275277
)
278+
279+
280+
@router.post(
281+
"/tasks/{task_number}/submit-changeset", response_model=SubmitTaskChangesetResponse
282+
)
283+
async def submit_changeset(
284+
workspace_id: int,
285+
project_id: int,
286+
task_number: int,
287+
changeset_model: SubmitTaskChangeset,
288+
current_user: UserInfo = Depends(validate_token),
289+
workspace_repo: WorkspaceRepository = Depends(get_workspace_repo),
290+
task_repo: TaskingTaskRepository = Depends(get_task_repo),
291+
):
292+
await assert_workspace_visible(workspace_id, current_user, workspace_repo)
293+
cs_id = await task_repo.submit_changeset(
294+
workspace_id,
295+
project_id,
296+
task_number,
297+
current_user,
298+
changeset_model.osm_changeset_id,
299+
)
300+
return SubmitTaskChangesetResponse(
301+
osm_changeset_id=changeset_model.osm_changeset_id,
302+
task_number=task_number,
303+
project_id=project_id,
304+
workspace_id=workspace_id,
305+
inserted_id=cs_id,
306+
)

tests/integration/test_tasks_flow.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ async def test_02_contributor_lock_and_submit_done(
653653

654654
r = await client.post(
655655
f"{API.format(wid=seeded_workspace_id)}/{self.project_id}/tasks/1/submit",
656-
json={"osm_changeset_id": 1001, "done": True},
656+
json={"done": True},
657657
)
658658
assert r.status_code == 200, r.text
659659
body = r.json()
@@ -688,7 +688,7 @@ async def test_05_validator_submit_done_no_feedback_completes(
688688
override_user(self.validator)
689689
r = await client.post(
690690
f"{API.format(wid=seeded_workspace_id)}/{self.project_id}/tasks/1/submit",
691-
json={"osm_changeset_id": 1002, "done": True},
691+
json={"done": True},
692692
)
693693
assert r.status_code == 200, r.text
694694
body = r.json()
@@ -732,7 +732,7 @@ async def test_submit_done_false_slides_expiry(
732732

733733
r = await client.post(
734734
f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/submit",
735-
json={"osm_changeset_id": 5001, "done": False},
735+
json={"done": False},
736736
)
737737
assert r.status_code == 200, r.text
738738
body = r.json()
@@ -774,7 +774,7 @@ async def test_remap_loop(
774774
await client.post(f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/lock")
775775
r = await client.post(
776776
f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/submit",
777-
json={"osm_changeset_id": 7001, "done": True},
777+
json={"done": True},
778778
)
779779
assert r.json()["status"] == "to_review"
780780

@@ -784,7 +784,6 @@ async def test_remap_loop(
784784
r = await client.post(
785785
f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/submit",
786786
json={
787-
"osm_changeset_id": 7002,
788787
"done": True,
789788
"feedback": {
790789
"reason_category": "incomplete_mapping",
@@ -838,7 +837,7 @@ async def test_validator_cannot_validate_own_last_mapping(
838837
await client.post(f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/lock")
839838
await client.post(
840839
f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/submit",
841-
json={"osm_changeset_id": 9001, "done": True},
840+
json={"done": True},
842841
)
843842

844843
# Now they try to validate their own work → 403.
@@ -880,7 +879,7 @@ async def test_reset_releases_lock_and_resets_status(
880879
await client.post(f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/lock")
881880
await client.post(
882881
f"{API.format(wid=seeded_workspace_id)}/{pid}/tasks/1/submit",
883-
json={"osm_changeset_id": 11001, "done": True},
882+
json={"done": True},
884883
)
885884
# Validator picks it up.
886885
override_user(validator)

0 commit comments

Comments
 (0)