WIP: add bbox endpoint for forms, dataviews, and merged datasets#3072
Open
FrankApiyo wants to merge 6 commits into
Open
WIP: add bbox endpoint for forms, dataviews, and merged datasets#3072FrankApiyo wants to merge 6 commits into
FrankApiyo wants to merge 6 commits into
Conversation
5 tasks
f15ba67 to
b28ade6
Compare
Adds GET /api/v1/forms/{id}/bbox, /dataviews/{id}/bbox, and
/merged-datasets/{id}/bbox returning {"bbox": [min_lng, min_lat, max_lng,
max_lat] | null} — the extent of geolocated submissions.
Motivation: Zonkey's tile-based map view (Martin + form_tiles()) cannot
compute bounds client-side since features are paged per MVT tile. A
dedicated endpoint lets the frontend fit the viewport on load without
fetching the full submission set.
Implementation:
- onadata/libs/utils/bbox_tools.py: shared `compute_instance_bbox` helper
using Django GIS Extent aggregate. Mirrors the filter shape of the
`form_tiles()` PostGIS function (non-deleted, geom non-null, optional
dataview query filter) so the fit matches the data Martin serves.
- Three viewset @action methods (XForm/DataView/MergedXForm) wrapping the
helper. Permissions inherit from the existing viewset class.
- Tests:
* XForm: extent with the gps fixture, null when no geoms
* DataView + MergedXForm: null-shape verification (helper itself is
covered by the XForm extent test since all three viewset actions
share it)
Returns null rather than 404 when a target has no geolocated rows so
callers can fall back to a default view cleanly.
Move filter_to_field_lookup, get_field_lookup, get_filter_kwargs, and apply_filters from dataview_viewset into onadata/libs/utils/dataview_filters so bbox_tools can import them at module top level instead of lazily. Resolves prospector cyclic-import and import-outside-toplevel findings between dataview_viewset and bbox_tools.
…ER_AUTH Pins ona-oidc to the HEAD of feat/per-provider-target-url-after-auth (PR onaio/ona-oidc#122) so we can stage-test the per-provider TARGET_URL_AFTER_AUTH fallback before the upstream PR merges. Will be re-pinned to a release tag once #122 lands.
… proxy Picks up onaio/ona-oidc#124 — adds proxy endpoints for Keycloak's Account REST API (sessions, linked-accounts, credentials), plus a ``logout`` action that takes generic ``extra_params`` instead of the per-param ``id_token_hint`` kwarg. Required for the zonkey SPA's Account-tab work landing on ``feat/email-otp-auth-flows``. Pinned to the branch tip (still open as PR #124 against ona-oidc main); fold the pin to the merged main SHA once that lands.
Pulls in the fix that reshapes Keycloak's
``userCredentialMetadatas[].credential`` response into the flat
``credentials[{id,userLabel?,createdDate?}]`` array the zonkey SPA
reads — without it users with a TOTP credential saw "Authenticator
app — Not set up" because the SPA's lookup hit Keycloak's nested
wire shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
GET /api/v1/forms/{id}/bbox,/api/v1/dataviews/{id}/bbox, and/api/v1/merged-datasets/{id}/bbox.Each returns
{"bbox": [min_lng, min_lat, max_lng, max_lat] | null}— the extent of geolocated submissions (null when the target has no geolocated rows, so callers can fall back to a default view cleanly).Motivation
Zonkey's tile-based map view (Martin +
form_tiles()) cannot compute bounds client-side since features are paged per MVT tile. A dedicated endpoint lets the frontend fit the viewport on first load without fetching the full submission set.Design
onadata/libs/utils/bbox_tools.py— sharedcompute_instance_bbox(xform_ids, dataview=None)helper using Django GISExtentaggregateform_tiles()PostGIS function (non-deleted, geom non-null, optional dataview query filter) so the fit matches the data Martin serves@actionmethods (XFormViewSet,DataViewViewSet,MergedXFormViewSet) wrap the helper; permissions inherit from each viewset's existing classTest plan
test_bbox_returns_extent_of_geolocated_submissions— XForm with the gps fixture returns a valid 4-tuple bboxtest_bbox_null_when_no_geolocated_submissions— returns{"bbox": null}for forms without geomsConsumers
TileMapView) →useFormBboxhook →fitBoundson map load. Work in progress on the martin branch of zonkey.Why WIP
Marking WIP pending:
bbox_toolshelper should live inlibs/utils/or somewhere closer to the logger modelsReplaces #3066 (rebased onto main, branch renamed from
wip/bbox-endpointtobbox-endpoint).