feat: scope GET /opportunity to an AGENT caller's own agents - #916
feat: scope GET /opportunity to an AGENT caller's own agents#916ivannissimrch wants to merge 17 commits into
Conversation
Code review findingsCorrectness
Test coverage
Simplification / reuse
Minor
🤖 Posted by Claude Code |
… into scope-opportunity-list-to-agent
…ot its volunteers
Description
fe 934 asks that NGO users only see opportunities belonging to their own organisation. Today
GET /opportunityapplies no caller-based scoping at all, so an NGO user sees every organisation's.The issue says both "their own operator (their email domain)" and "for their own shelter", which give different lists. Nadav settled it on fe 950: "anyone from the same NGO/agent can see the opportunities there of that NGO/agent". So this scopes by agent.
agent.organization_idis NULL for every agent on local and dev so that operator scoping would return an empty list for everyone today anyway.GET /opportunitynow resolves the caller's agent memberships server-side and restricts the result to those agents when the caller's role is AGENT. Coordinators and admins are unaffected.Only ACTIVE memberships count. A PENDING membership is one a coordinator has not approved yet, so it grants nothing.
fe 950 is the frontend half and needs this to be safe to ship.
Related Issues
fe 934
fe 950
Changes
getCallerAgentIdsinsrc/server/utils/data/: a person's ACTIVE agent memberships, dedupedGET /opportunity: when the caller is an AGENT, constrainwhere.agent.idto those IDs
through to an unfiltered query, so the failure mode is closed, not open
src/test/server/routes/opportunity-agent-scope.routes.test.tsChecklist