From fb7381c90900d0e15a820e58614e478ad6da6d25 Mon Sep 17 00:00:00 2001 From: Sujan Adhikari <109404840+Sujanadh@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:04:12 +0545 Subject: [PATCH] Api to update the review state of submission (#1350) * feat: api to update the review state of submission * feat: updated the version of osm-fieldwork=0.5.4 --------- Co-authored-by: sujanadh --- src/backend/app/central/central_crud.py | 9 +++++ src/backend/app/models/enums.py | 8 +++++ .../app/submissions/submission_routes.py | 35 ++++++++++++++++++- src/backend/pdm.lock | 12 +++---- src/backend/pyproject.toml | 2 +- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/backend/app/central/central_crud.py b/src/backend/app/central/central_crud.py index 4d90d58595..0a2210976d 100644 --- a/src/backend/app/central/central_crud.py +++ b/src/backend/app/central/central_crud.py @@ -52,6 +52,15 @@ def get_odk_project(odk_central: Optional[project_schemas.ODKCentralDecrypted] = try: log.debug(f"Connecting to ODKCentral: url={url} user={user}") project = OdkProject(url, user, pw) + + except ValueError as e: + log.error(e) + raise HTTPException( + status_code=401, + detail=""" + ODK credentials are invalid, or may have been updated. Please update them. + """, + ) from e except Exception as e: log.exception(e) raise HTTPException( diff --git a/src/backend/app/models/enums.py b/src/backend/app/models/enums.py index 01defea55f..62912f6938 100644 --- a/src/backend/app/models/enums.py +++ b/src/backend/app/models/enums.py @@ -296,3 +296,11 @@ class CommunityType(IntEnum, Enum): NON_PROFIT = 2 UNIVERSITY = 3 OTHER = 4 + + +class ReviewStateEnum(StrEnum, Enum): + """Enum describing review states of submission.""" + + hasissues = "hasIssues" + approved = "approved" + rejected = "rejected" diff --git a/src/backend/app/submissions/submission_routes.py b/src/backend/app/submissions/submission_routes.py index 3946ea2ff5..7b957d52e2 100644 --- a/src/backend/app/submissions/submission_routes.py +++ b/src/backend/app/submissions/submission_routes.py @@ -21,7 +21,7 @@ import os from typing import Optional -from fastapi import APIRouter, BackgroundTasks, Depends, Query, Response +from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Query, Response from fastapi.concurrency import run_in_threadpool from fastapi.responses import FileResponse, JSONResponse from osm_fieldwork.odk_merge import OdkMerge @@ -33,6 +33,7 @@ from app.central import central_crud from app.config import settings from app.db import database, db_models +from app.models.enums import ReviewStateEnum from app.projects import project_crud, project_deps, project_schemas from app.submissions import submission_crud, submission_schemas from app.tasks import tasks_crud @@ -471,3 +472,35 @@ async def task_submissions( response = submission_detail.get("value", [])[0] return response + + +@router.post("/update_review_state/{project_id}") +async def update_review_state( + project_id: int, + instance_id: str, + review_state: ReviewStateEnum, + task_id: int, + db: Session = Depends(database.get_db), +): + """Updates the review state of a project submission. + + Args: + project_id (int): The ID of the project. + instance_id (str): The ID of the submission instance. + review_state (ReviewStateEnum): The new review state to be set. + task_id (int): The ID of the task associated with the submission. + db (Session): The database session dependency. + """ + try: + project = await project_crud.get_project(db, project_id) + odk_creds = await project_deps.get_odk_credentials(db, project_id) + odk_project = central_crud.get_odk_project(odk_creds) + response = odk_project.updateReviewState( + project.odkid, + f"{project.project_name_prefix}_task_{task_id}", + instance_id, + {"reviewState": review_state}, + ) + return response + except Exception as e: + raise HTTPException(status_code=400, detail=str(e)) from e diff --git a/src/backend/pdm.lock b/src/backend/pdm.lock index a34fc076dd..9c924613f4 100644 --- a/src/backend/pdm.lock +++ b/src/backend/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "debug", "dev", "docs", "test"] strategy = ["cross_platform"] lock_version = "4.4.1" -content_hash = "sha256:4d3933cac47b9ccb3beb04e8f1f6ea36e591e5d801a18f1192f4b0c70c5f8940" +content_hash = "sha256:5698f651398e9a571f298da76c7d0dd93392be5255711523e460021ebf58164f" [[package]] name = "annotated-types" @@ -1032,7 +1032,7 @@ files = [ name = "mergedeep" version = "1.3.4" requires_python = ">=3.6" -summary = "A deep merge function for 🐍." +summary = "A deep merge function for ğŸ��." files = [ {file = "mergedeep-1.3.4-py3-none-any.whl", hash = "sha256:70775750742b25c0d8f36c55aed03d24c3384d17c951b3175d898bd778ef0307"}, {file = "mergedeep-1.3.4.tar.gz", hash = "sha256:0096d52e9dad9939c3d975a774666af186eda617e6ca84df4c94dec30004f2a8"}, @@ -1270,7 +1270,7 @@ files = [ [[package]] name = "osm-fieldwork" -version = "0.5.3" +version = "0.5.4" requires_python = ">=3.10" summary = "Processing field data from OpenDataKit to OpenStreetMap format." dependencies = [ @@ -1294,8 +1294,8 @@ dependencies = [ "xmltodict>=0.13.0", ] files = [ - {file = "osm-fieldwork-0.5.3.tar.gz", hash = "sha256:95d827d80c53d4a9584cf4ff17153ed540b504dedc73a283e7b45c71a4fa99ea"}, - {file = "osm_fieldwork-0.5.3-py3-none-any.whl", hash = "sha256:64c3209ed35d83d7fd90bed63e731388666c2173663a3cbf6c84185ffd434b18"}, + {file = "osm-fieldwork-0.5.4.tar.gz", hash = "sha256:5ff6b2c53a661836116fab565c6387b947710386b7efeab460917f276da59ab8"}, + {file = "osm_fieldwork-0.5.4-py3-none-any.whl", hash = "sha256:692f9146789b98bb7513aee4fa811afff9529b85fb0672d6d39bfc314bd0ff51"}, ] [[package]] @@ -1952,7 +1952,7 @@ files = [ name = "questionary" version = "2.0.1" requires_python = ">=3.8" -summary = "Python library to build pretty command line user prompts ⭐️" +summary = "Python library to build pretty command line user prompts â­�ï¸�" dependencies = [ "prompt-toolkit<=3.0.36,>=2.0", ] diff --git a/src/backend/pyproject.toml b/src/backend/pyproject.toml index 4e85fbb0fe..6a62cd5c02 100644 --- a/src/backend/pyproject.toml +++ b/src/backend/pyproject.toml @@ -47,7 +47,7 @@ dependencies = [ "cryptography>=42.0.1", "defusedxml>=0.7.1", "osm-login-python==1.0.1", - "osm-fieldwork==0.5.3", + "osm-fieldwork==0.5.4", "osm-rawdata==0.2.3", "fmtm-splitter==1.2.0", ]