-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endpoint to conflate the submission with osm data #1594
Conversation
src/backend/app/db/postgis_utils.py
Outdated
@@ -777,3 +785,160 @@ def parse_featcol(features: Union[Feature, FeatCol, MultiPolygon, Polygon]): | |||
elif isinstance(features, Feature): | |||
feat_col = geojson.FeatureCollection([feat_col]) | |||
return feat_col | |||
|
|||
|
|||
def request_snapshot(geometry): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function and the poll_task_status
function can be replaced with osm_fieldwork.PostgresClient.
There is already functionality in place to get a data extract using provided config π
Example:
fmtm/src/backend/app/projects/project_crud.py
Line 449 in 319f65e
pg = PostgresClient( |
@@ -524,3 +530,45 @@ async def get_submission_detail( | |||
odk_form.getSubmissions(project.odkid, db_xform.odk_form_id, submission_id) | |||
) | |||
return submission.get("value", [])[0] | |||
|
|||
|
|||
async def get_submission_geojson( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed we already have central_crud.convert_odk_submission_json_to_geojson and submission_routes.download_submission_geojson that all basically do the same thing.
Could we refactor to only have the logic once, then reuse the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if i want geojson only for the conflation, then this function won't work since it returns submission in bytes. like you said, we can refactor the download_submission
endpoint to use convert_odk_submission_json_to_geojson
. Or we can update this function to return geojson and convert it into bytes wherever necessary instead of returning bytes from this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second option sounds best in the spirit of DRY code.
A single function to return a geojson, then encode as bytes where specifically needed.
If absolutely necessary it's also possible to decode bytes back to geojson using .decode("utf--8")
π
json.load would probably also do that
) | ||
|
||
|
||
def conflate_features( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
We can merge this for now as initial functionality π In the long term we should look into integrating this (after some good testing): osm-merge/osm-merge#9 |
updates:
|
src/backend/app/db/postgis_utils.py
Outdated
geometry, | ||
extra_params={ | ||
"fileName": ( | ||
f"fmtm/{settings.FMTM_DOMAIN}/data_extract" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing - the folder structure starting with fmtm/...
should only be used if we want to keep the data extract.
Raw data api has a rule if we use auth and a set structure, the file is retained for the project.
In this case we could remove this param as we only need a temp extract π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
if settings.RAW_DATA_API_AUTH_TOKEN | ||
else "fmtm_extract" | ||
), | ||
"outputType": "geojson", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe bind zip true and geojson are defaults on raw data api, but no harm being explicit π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its better to mention, as we won't know what are the default values.
Updates:
|
src/backend/app/auth/roles.py
Outdated
@@ -242,6 +242,12 @@ async def wrap_check_access( | |||
role: ProjectRole, | |||
) -> ProjectUserDict: | |||
"""Wrap check_access call with HTTPException.""" | |||
# If project is public, skip permission check | |||
if project.visibility == ProjectVisibility.PUBLIC: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this logic here means that all users have access to all endpoints if the project is public.
So they could delete the project, modify anything, etc.
It's currently only present in the mapper
permission, as we only want to bypass the auth if the endpoint requires mapper
role only:
fmtm/src/backend/app/auth/roles.py
Line 327 in fd11d08
if project.visibility == ProjectVisibility.PUBLIC: |
Was this logic needed for the code in this PR to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else is all set to merge!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a minor update, fixing the return type on the mapper
role if ProjectVisibility.PUBLIC
.
I'm going to merge as this PR has been open a while - let me know if any issues!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh I totally missed that. Yes , you are right. I changed that in order to get ProjectUserDict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh I totally missed that. Yes , you are right. I changed that in order to get ProjectUserDict.
What type of PR is this? (check all applicable)
Related Issue
Describe this PR
This PR creates a new endpoint in order to conflate the submission data with osm features.
Response
Alternative Approaches Considered
Did you attempt any other approaches that are not documented in code?
Review Guide
Notes for the reviewer. How to test this change?
Checklist before requesting a review
[optional] What gif best describes this PR or how it makes you feel?