Add summary statistics to contract retrieve endpoint and remove unassigned codes from /codes output. Add filtering on assigned + redeemed statuses#3705
Merged
dsubak merged 5 commits intoJun 26, 2026
Conversation
…ed count of total_codes + annotation). Remove unassigned codes from the output since we no longer show that to anyone.
dsubak
commented
Jun 25, 2026
| organization__organization_users__is_manager=True, | ||
| ) | ||
| ) | ||
| if self.action == "retrieve": |
Contributor
Author
There was a problem hiding this comment.
Currently only used for the contract retrieve endpoints where we calculate summary stats.
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
… in cases where max_learners > 0 anymore
jkachel
reviewed
Jun 25, 2026
Contributor
Author
|
@jkachel and @daniellefrappier18 - pulling this out of draft and into ready for review! Ya'll obviously both already looked at it a little - the only material change since then is to add the ability to filter on status. Let me know if there are any questions! |
daniellefrappier18
approved these changes
Jun 26, 2026
daniellefrappier18
left a comment
Contributor
There was a problem hiding this comment.
Tested this out in mitodl/mit-learn#3530 and everything is working as expected on my end. :)
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.
Description (What does it do?)
Now that we've paginated the API, the frontend doesn't have a particularly good way to grab the breakdown of codes to show to the contract manager:

Previously, these were just calculated by looking at the total rowset returned from /codes.
This PR attempts to put that info into the contract retrieve endpoint instead - that endpoint already looked like it was outputting some values like that (most notably a miscalculated
total_codesvalue), so it seemed reasonable to add here.Additionally, this PR removes unassigned codes from the response entirely.
We no longer actually intend to show unassigned codes in the UI - contract admins shouldn't need to see them as the assign endpoints already handle distributing them automagically. The only codepath which returned them is for contracts which don't have automatic membership types AND a max_learners set (the former case never returns any codes, the latter returns the first one if it exists). We considered adding a query param to filter those out, but as this endpoint already has a bit too many edge cases, we thought this might make it easier to reason about - this makes /codes more like "used/assigned codes"
If we decide later that we do need them in this payload, we can either add a kwarg or create a new endpoint for "available codes".
Lastly, this PR adds filtering on the "status" of a code for the /codes endpoint. Since we've removed unassigned codes from the payload, we only have to worry about support for "assigned" and "redeemed" codes
Screenshots (if appropriate):
How can this be tested?
In addition to all tests passing, manual testing can be performed in the following manner.
Common setup
To test the filtering behavior, you'll want to redeem a few codes using the attach API.
At the end of setup, you should have at least a few values in redeemed, assigned and unassigned to make subsequent steps easier.
Removal of Unassigned codes from /codes
http://mitxonline.odl.local:9080/api/v0/b2b/manager/organizations/<org_id>/contracts/<contract_id>/codes/and observe that it is not returned in the resultset.Summary Statistics
Status filtering
http://mitxonline.odl.local:9080/api/v0/b2b/manager/organizations/<org_id>/contracts/<contract_id>/codes/and specify a status parameter of either "assigned" or "redeemed"Additional Information
Take note - this PR is a branch off of #3685; in order to simplify the release, this branch will be merged into that PR and the whole thing will be released in one shot.