Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch content metadata for serialized assignments in credits_available response payload #316

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

iloveagent57
Copy link
Contributor

@iloveagent57 iloveagent57 commented Nov 2, 2023

This change allows us to pull-through content metadata from the enteprise-catalog get_content_metadata endpoint into serialized assignments contained within responses of the credits_available view.
For example, in response to

curl --location 'http://localhost:18270/api/v1/policy-redemption/credits_available/?enterprise_customer_uuid=70699d54-7504-4429-8295-e1c0ec68dbc7&lms_user_id=8' \

you'd get

[
    {
        "uuid": "3cc0ad2c-ede1-476c-8271-97683855e41d",
        "policy_redemption_url": "http://localhost:18270/api/v1/policy-redemption/3cc0ad2c-ede1-476c-8271-97683855e41d/redeem/",
        "remaining_balance_per_user": null,
        "remaining_balance": 482847,
        "subsidy_expiration_date": "2024-03-15T18:48:26Z",
        "learner_content_assignments": [
            {
                "uuid": "a7e12cd7-4c9a-41ef-82a6-bea4c9be0521",
                "assignment_configuration": "a9f97992-4894-4b80-9dde-b08ce3d7bff3",
                "learner_email": "verified@example.com",
                "lms_user_id": 8,
                "content_key": "course-v1:edX+DemoX+Demo_Course2",
                "content_title": null,
                "content_quantity": -200,
                "state": "allocated",
                "transaction_uuid": null,
                "last_notification_at": null,
                "actions": [],
                "content_metadata": null
            },
            {
                "uuid": "84cf3f51-2cd9-4632-9c93-809744e75fed",
                "assignment_configuration": "a9f97992-4894-4b80-9dde-b08ce3d7bff3",
                "learner_email": "verified@example.com",
                "lms_user_id": 8,
                "content_key": "edX+DemoX",
                "content_title": null,
                "content_quantity": -100,
                "state": "allocated",
                "transaction_uuid": null,
                "last_notification_at": null,
                "actions": [
                    {
                        "uuid": "d0f29825-c4d6-48f6-8f1b-4d456939e61c",
                        "action_type": "notified",
                        "completed_at": "2023-11-01T14:12:41Z",
                        "error_reason": null
                    }
                ],
                "content_metadata": {
                    "start_date": "2013-02-05T05:00:00Z",
                    "end_date": null,
                    "enroll_by_date": "2020-01-30T19:14:45.240399Z",
                    "content_price": 149,
                    "partners": [
                        {
                            "name": "edX",
                            "logo_image_url": "https://www.edx.org/images/logos/edx-logo-elm.svg"
                        }
                    ]
                }
            }
        ],
        "policy_type": "AssignedLearnerCreditAccessPolicy",
        "enterprise_customer_uuid": "70699d54-7504-4429-8295-e1c0ec68dbc7",
        "display_name": "test assignment policy",
        "description": "Assignment-based policy against Alex's third test subsidy.\r\nhttp://localhost:18280/admin/subsidy/subsidy/4c53f616-5ea0-42a0-9430-ba165cb2c916/change/\r\n\r\nCatalog record points at Test Enterprise's catalog:\r\nhttp://localhost:18000/admin/enterprise/enterprisecustomercatalog/482a8a38-f60d-4250-8f93-402cd5f69d3b/change/",
        "active": true,
        "catalog_uuid": "7467c9d2-433c-4f7e-ba2e-c5c7798527b2",
        "subsidy_uuid": "4c53f616-5ea0-42a0-9430-ba165cb2c916",
        "access_method": "assigned",
        "spend_limit": 1000000,
        "per_learner_enrollment_limit": null,
        "per_learner_spend_limit": null,
        "assignment_configuration": "a9f97992-4894-4b80-9dde-b08ce3d7bff3"
    }
]

Has good drf-spec docs at http://localhost:18270/api/schema/redoc/#tag/Subsidy-Access-Policy-Redemption/operation/api_v1_policy_redemption_credits_available_list

This PR built on top of some serialization changes in #307

Comment on lines 55 to 59
"""
Serializer to help return additional content metadata for assignments. These fields should
map more or less 1-1 to the fields in content metadata dicts returned from the
enterprise-catalog `get_content_metadata` response payload.
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives us a common place to hook into any additional data we want from the enterprise-catalog get_content_metadata endpoint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this pattern of having an isolated place to extract specific fields from get_content_metadata endpoint as needed.

record['key']: record for record in content_metadata_list
}
return {
assignment.content_key: metadata_by_key.get(assignment.content_key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious, non-blocking] Could there ever be a chance where the assignment's content key is no longer part of the catalog when this gets evaluated? How does the get_content_metadata API handle content keys that are not part of the catalog?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'd end up with the assignment's content_key mapping to null here. The situation you're describing is technically possible (content falls out of catalog after allocation), but I'm not sure exactly what should happen in that case. Ideally we'd have a hook in place to error out any unaccepted assignments.
The get_content_metadata endpoint won't include a record for requested keys that are not in the catalog, but the response is still a 200 as long as the catalog actually exists (even when no requested keys are found within it).

Comment on lines 55 to 59
"""
Serializer to help return additional content metadata for assignments. These fields should
map more or less 1-1 to the fields in content metadata dicts returned from the
enterprise-catalog `get_content_metadata` response payload.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this pattern of having an isolated place to extract specific fields from get_content_metadata endpoint as needed.

@iloveagent57 iloveagent57 force-pushed the aed/fetch-catalog-metadata branch 7 times, most recently from e770df8 to efd6f4e Compare November 6, 2023 15:08
@iloveagent57 iloveagent57 marked this pull request as ready for review November 6, 2023 15:09
@iloveagent57 iloveagent57 force-pushed the aed/fetch-catalog-metadata branch from efd6f4e to 0743d0d Compare November 6, 2023 15:22
@iloveagent57 iloveagent57 changed the title Aed/fetch catalog metadata Fetch content metadata for serialized assignments in credits_available response payload Nov 6, 2023
Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a handful of non-blocking nits.

@@ -0,0 +1,110 @@
"""
Python API for interacting with content metadata.
TODO: refactor subsidy_access_policy/content_metadata_api.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit/sanity check] Is this TODO part of this PR, or is it slated for future work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slated for future work

@iloveagent57 iloveagent57 force-pushed the aed/fetch-catalog-metadata branch from 0743d0d to 3c0d1a9 Compare November 6, 2023 16:35
@iloveagent57 iloveagent57 merged commit b2882ba into main Nov 6, 2023
3 checks passed
@iloveagent57 iloveagent57 deleted the aed/fetch-catalog-metadata branch November 6, 2023 20:43
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.

2 participants