feat: Creation APIs for Programs, Opportunities, and related resources#1070
Draft
jjackson wants to merge 12 commits intodimagi:mainfrom
Draft
feat: Creation APIs for Programs, Opportunities, and related resources#1070jjackson wants to merge 12 commits intodimagi:mainfrom
jjackson wants to merge 12 commits intodimagi:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Drop TokenHasScope from read (GET/list) actions — only require 'create' OAuth scope for write operations (POST/PATCH/DELETE), matching how existing endpoints use IsAuthenticated for reads - Add DeliverUnitReadSerializer with proper read fields (id, slug, name, payment_unit, app, optional) so GET responses use a read serializer like every other viewset - Scope ProgramViewSet queryset to user's org memberships, matching how OpportunityViewSet filters by user access - Update tests: list endpoints use force_authenticate (no scope), add explicit test for no-scope-required reads Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
Code reviewFound 1 issue:
commcare-connect/commcare_connect/opportunity/api/views.py Lines 221 to 223 in e4cbc4b commcare-connect/commcare_connect/program/api/views.py Lines 77 to 80 in e4cbc4b Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
- Scope read querysets to user's org membership: PaymentUnit, DeliverUnit filter by user membership in either the NM org or PM org (via program). ManagedOpportunity and ProgramApplication filter by PM org membership. Prevents authenticated users from enumerating resources across orgs. - Validate DeliverUnit's payment_unit belongs to the URL opportunity, preventing cross-opportunity FK injection - Add has_ended check to InviteUsersView — return 400 instead of silently queueing a no-op Celery task (matches web UI behavior) - Replace silent `except Program.DoesNotExist: pass` with get_object_or_404 in initial() — returns proper 404 instead of confusing 403 - Extract ProgramNestedViewMixin to DRY up shared initial/context logic - Remove unused IsOrgAdmin permission class Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
DRF's default CreateModelMixin returns the write serializer in create responses, which omits read-only fields like id, program_id, slug, date_created etc. Add ReadSerializerResponseMixin that overrides create() to serialize the response with the read serializer, so POST responses include full object details. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Product Description
Adds REST API endpoints to enable full end-to-end creation of Programs, ManagedOpportunities, PaymentUnits, DeliverUnits, and user invitations — filling the gap where these operations were previously only available through the web UI.
A new
createOAuth scope gates all write endpoints. Read endpoints require only authentication (no scope), matching the existingOpportunityViewSetpattern.Technical Summary
Jira: CCC-XXX (feature request for Connect team)
Draft PR: #1070
New Endpoints
/api/lookups/delivery_types//api/lookups/currencies//api/lookups/countries//api/program//api/program/<id>/opportunity//api/program/<id>/applications//api/opportunity/<id>/payment_units//api/opportunity/<id>/deliver_units//api/opportunity/<id>/invite/Key Design Decisions
createscope for writes only (mirrorsexportscope pattern). Reads require onlyIsAuthenticated, matching existing API convention.IsOrgProgramManagerAdminDRF permission class mirrors the existingorg_program_manager_requireddecorator. For nested routes (under Program),initial()injects the PM org slug from the program for permission checking.ReadSerializerResponseMixinensures POST responses return the full read serializer (withid, UUID,slug, timestamps) instead of just echoing input fields.payment_unitbelongs to the URL opportunity. InviteUsers checkshas_endedbefore queueing.New Files
Safety Story
createscope AND org program manager admin roleQA Plan
createscope can access write endpointscreatescope gets 403 on writes but 200 on reads🤖 Generated with Claude Code