Skip to content

refactor(geo): use research area search across admin - #135

Merged
p3t3r67x0 merged 1 commit into
devfrom
feat/shared-admin-area-search
Sep 27, 2026
Merged

p3t3r67x0 merged 1 commit into
devfrom
feat/shared-admin-area-search

Conversation

@p3t3r67x0

Copy link
Copy Markdown
Collaborator

Summary

Uses the persisted municipality/kommune catalog introduced in #134 as the canonical administrative-area search for Research and Operations. Selecting Flensburg now uses the same admin.research_area.id and polygon in both workspaces.

The shared accessible combobox provides bounded catalog search, country/region labels, 300 ms debounce, keyboard selection, cancellation and stale-response protection. A small read-only GET /api/v1/research/areas/{id}/metadata endpoint hydrates selected values without loading dossier aggregates or boundary polygons.

Before

  • Operations: live Nominatim discovery → separate admin.geo_area import.
  • Research: persisted admin.research_area catalog.

After

  • Both municipality selectors read admin.research_area; ordinary Operations search does not call Nominatim or create a Geo row.
  • All existing spatial Operations surfaces use the canonical polygon through the shared resolver: events, venues, spaces, organizations, activity, findings, dashboard, statistics and graph root search.
  • Existing ST_Covers, boundary-point behavior, effective venue/space inheritance and per-view semantics remain intact. Operations organization location and Research organization event activity remain distinct questions.
  • Nominatim remains available for imports, address geocoding and explicit provider-backed discovery workflows.

Compatibility

Uses option A: Operations retains geo_scope_id as its compatible query parameter, carrying the exact Research UUID. Research retains area_id. This preserves existing endpoint, cursor, provenance and bookmark contracts without introducing competing Operations parameters.

Legacy Geo UUIDs with a matching OSM relation resolve to the canonical Research polygon; the browser replaces the old UUID in the URL while preserving other filters. Unmatched arbitrary cached boundaries remain usable. Explicit legacy imports also reuse existing canonical municipalities without another provider request or duplicate geometry.

No migration, grant changes or data cleanup are needed; Alembic head remains 0016. Existing admin.geo_area records are preserved. The in-memory preference store retains metadata only, with URL precedence and session clearing unchanged.

Security

No authorization widening: Research catalog/metadata reads allow system admins or journalists; Operations remains system-admin-only. Nitro explicitly allowlists the UUID metadata route, GET only, without query passthrough. No Uranus writes, runtime grants, public geocoder fallback or new dependency.

Verification

  • Backend, from backend/:
    • .venv/bin/ruff check . — passed.
    • .venv/bin/ruff format --check . — 261 files passed; changed provenance files also rechecked after the final fix.
    • .venv/bin/mypy — 179 source files passed.
    • .venv/bin/pytest -q with TEST_DATABASE_URL pointing at the isolated PostGIS database — 2,095 passed, one provenance projection mismatch found. Both explicit projection lists were corrected to include area_id; .venv/bin/pytest -q tests/test_sql_provenance.py then passed all 59 tests. The entire backend suite was not repeated after this narrowly scoped fix. No integration skips.
    • Focused Geo/Research/Geocoding/auth integration run: .venv/bin/pytest -q tests/test_geo.py tests/test_geo_analytics.py tests/test_research_areas.py tests/test_geocode.py tests/test_auth.py — 229 passed before the final additional venue-boundary cases; those cases passed in the full run.
    • .venv/bin/alembic heads — 0016 (head).
  • Frontend, from frontend/:
    • pnpm lint — passed, four pre-existing warnings.
    • pnpm typecheck and pnpm build — passed.
    • pnpm test — 881 tests in 64 files passed. After the final focus/scroll adjustment, pnpm exec vitest run tests/unit/administrative-area-select.test.ts tests/unit/geo.test.ts also passed all 18 tests.
    • pnpm exec playwright test tests/e2e/geo-scope.spec.ts tests/e2e/research.spec.ts --workers=2 --output=/tmp/shared-area-e2e-dev-final — 44 passed after updating old searchbox assertions to the new combobox role. Geo analytics and geocoding also passed in the earlier combined development run; two production-only CSP cases were skipped there.
    • TEST_PRODUCTION=1 pnpm exec playwright test tests/e2e/geo-scope.spec.ts tests/e2e/geo-analytics.spec.ts tests/e2e/research.spec.ts tests/e2e/geocoding.spec.ts --workers=2 --output=/tmp/shared-area-e2e-production — all 66 passed, no skips.
  • git diff --check — passed. OpenAPI regenerated from create_app(...).openapi() and checked by the backend contract test.

Coverage includes canonical and legacy identity resolution, canonical polygon precedence, inside/outside/boundary venue membership, Operations endpoints without Nominatim configuration, unchanged effective-location regression tests, read-only metadata authorization, keyboard search, cancellation, stale response suppression, hydration, URL reload, legacy bookmark normalization, clearing, Research export/dossiers and geocoding CSP.

The integration database is disposable PostgreSQL 17/PostGIS, separate from application databases. Browser tests use synthetic fixtures; no production import or deployment was performed.

@p3t3r67x0 p3t3r67x0 self-assigned this Sep 27, 2026
@p3t3r67x0
p3t3r67x0 merged commit 2e074e8 into dev Sep 27, 2026
21 checks passed
@p3t3r67x0
p3t3r67x0 deleted the feat/shared-admin-area-search branch September 27, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant