Skip to content

Commit

Permalink
Merge branch 'development' of github.com:hotosm/fmtm into feat-projec…
Browse files Browse the repository at this point in the history
…t-details-geolocation-integration
  • Loading branch information
NSUWAL123 committed Mar 21, 2024
2 parents 0c8d545 + e9ecfdd commit dff1d3f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/backend/app/central/central_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions src/backend/app/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
35 changes: 34 additions & 1 deletion src/backend/app/submissions/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions src/backend/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down

0 comments on commit dff1d3f

Please sign in to comment.