Skip to content

feat: organization-scoped species activation API (#1222) - #675

Open
FangHsin0122 wants to merge 1 commit into
Greenstand:masterfrom
FangHsin0122:feat/1222-organization-species-backend
Open

feat: organization-scoped species activation API (#1222)#675
FangHsin0122 wants to merge 1 commit into
Greenstand:masterfrom
FangHsin0122:feat/1222-organization-species-backend

Conversation

@FangHsin0122

@FangHsin0122 FangHsin0122 commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Backend work for Greenstand/treetracker-admin-client#1222, which adds organization-scoped species activation. This PR only covers the backend. The frontend part of #1222 (species dropdown in admin-client) is being handled separately.

  • Added a new OrganizationSpecies junction table, along with the model, repository, and controller
  • GET /organization/{organizationId}/species — returns the species available to the organization, filtered to active mappings and active species
  • POST .../activate — returns 422 if the target species is globally inactive
  • POST .../deactivate — idempotent
  • Added list_species / manage_org_species auth policies, matched by org ID
  • Added a one-time backfill script (backfill:organization-species) that rebuilds the initial mappings from historical trees.species_id usage, so existing organizations don't end up with an empty species list after rollout

Dependency

The companion treetracker-database migration (AddOrganizationSpeciesTable) needs to be merged and deployed first.
Link: Greenstand/treetracker-database#124

Testing

  • npm run build / npm run lint: clean
  • npx jest --ci: 42 passed, 0 failed, including the new auth policy coverage
  • Manual endpoint matrix against a local Postgres database restored from the real schema: 18/18 passed, covering org-scoped lists, hierarchy inheritance, cross-org 401s, read/write policy separation, the retired-species 422 guard, idempotent deactivate, and legacy route regression
  • Verified the backfill script with dry run → real run → idempotent rerun against fixture data

Add OrganizationSpecies junction table, org-scoped GET/activate/deactivate endpoints,

and the list_species/manage_org_species auth policies.
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