diff --git a/enterprise_access/apps/api/serializers/subsidy_access_policy.py b/enterprise_access/apps/api/serializers/subsidy_access_policy.py index 0e1485832..ac2374302 100644 --- a/enterprise_access/apps/api/serializers/subsidy_access_policy.py +++ b/enterprise_access/apps/api/serializers/subsidy_access_policy.py @@ -13,6 +13,7 @@ from requests.exceptions import HTTPError from rest_framework import serializers +from enterprise_access.apps.subsidy_access_policy.constants import AccessMethods from enterprise_access.apps.subsidy_access_policy.constants import CENTS_PER_DOLLAR, PolicyTypes from enterprise_access.apps.subsidy_access_policy.models import SubsidyAccessPolicy @@ -522,6 +523,16 @@ class SubsidyAccessPolicyCreditsAvailableResponseSerializer(SubsidyAccessPolicyR help_text='', source='subsidy_expiration_datetime', ) + learner_content_assignments = serializers.SerializerMethodField('get_assignments_serializer') + + def get_assignments_serializer(self, obj): + if obj.access_method == AccessMethods.ASSIGNED: + assignments = obj.assignment_configuration.assignments.all().filter( + lms_user_id=self.context.get('lms_user_id') + ) + serializer = LearnerContentAssignmentResponseSerializer(assignments, many=True) + return serializer.data + return [] @extend_schema_field(serializers.IntegerField) def get_remaining_balance_per_user(self, obj):