Skip to content

feat: nested geofences — area_manager access to all child areas of a region - #112

Open
dadofsambonzuki wants to merge 1 commit into
masterfrom
feat/nested-geofences
Open

feat: nested geofences — area_manager access to all child areas of a region#112
dadofsambonzuki wants to merge 1 commit into
masterfrom
feat/nested-geofences

Conversation

@dadofsambonzuki

Copy link
Copy Markdown
Member

Closes #111

Summary

Replaces the flat-list geofence model with spatial nesting. Geofencing a country-level area now grants access to all communities within it — no more manual ID syncing.

What changed

check_geofence() (src/service/area.rs)

  • Direct ID match still works (backward compatible).
  • New: if the target area is not directly listed, it checks whether the area's centroid falls inside any geofenced parent's polygon. If so, access is granted.

add_area handler (src/rpc/area/add_area.rs)

  • Previously: any non-empty geofence blocked area creation entirely ("Cannot add new areas when your geofence is set").
  • New: area managers can create new areas if the new area's centroid falls inside a geofenced parent region. Areas outside all geofenced parents are still rejected.

Shared helpers

  • area_is_contained_in_geofence() — spatial check for existing areas (uses geometry centroid + polygon containment).
  • geo_json_is_within_geofence() — spatial check for incoming GeoJSON (used by add_area before the area exists in the DB).
  • inner_centroid_of_geometries() / point_is_inside_any() — reusable geometry utilities.

Tests (6 new/changed)

Test What it verifies
check_geofence_allows_nested_child_area_within_geofenced_parent Geofenced parent → accesses child by alias + numeric ID
geo_json_is_within_geofence_detects_containment Inline geo_json containment check
area_manager_can_create_area_inside_geofenced_parent add_area succeeds when within geofenced parent
area_manager_with_geofence_is_rejected_when_outside (renamed) add_area still rejected when outside
area_manager_with_geofence_cannot_delete_unfenced_area (fixed) Updated to use non-overlapping test areas

Backward compatibility

  • Existing flat-list geofences continue working — the spatial check is additive.
  • No schema changes.
  • All 761 existing tests pass.

Example: UK area manager

Before:

geofence = [364, 53, 79, 93, 98, 100, ...]  # 43 IDs

After:

geofence = [364]  # UK country — auto-grants all communities inside

Geofencing a country-level area now grants access to all
communities within it via polygon containment. No more manual
ID syncing required.

- check_geofence(): direct ID match still works; falls back to
  spatial check when target area is not directly listed
- add_area: area managers can create new areas inside their
  geofenced regions (previously blocked entirely)
- Shared helpers: area_is_contained_in_geofence(),
  geo_json_is_within_geofence(), point_is_inside_any(),
  inner_centroid_of_geometries()

Closes #111
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.

feat: nested geofences (grant area_manager access to all child areas of a region)

1 participant