diff --git a/enterprise_access/apps/content_assignments/api.py b/enterprise_access/apps/content_assignments/api.py index bd707755..8f7eba4c 100644 --- a/enterprise_access/apps/content_assignments/api.py +++ b/enterprise_access/apps/content_assignments/api.py @@ -207,10 +207,9 @@ def get_assignment_for_learner( queryset = LearnerContentAssignment.objects.select_related('assignment_configuration') try: return queryset.get( + Q(content_key=content_key_to_match) | Q(parent_content_key=content_key_to_match), assignment_configuration=assignment_configuration, lms_user_id=lms_user_id, - # assignment content_key is assumed to always be a course with no namespace prefix. - content_key=content_key_to_match, ) except LearnerContentAssignment.DoesNotExist: return None diff --git a/enterprise_access/apps/subsidy_access_policy/constants.py b/enterprise_access/apps/subsidy_access_policy/constants.py index f92c6adb..a0e627f5 100644 --- a/enterprise_access/apps/subsidy_access_policy/constants.py +++ b/enterprise_access/apps/subsidy_access_policy/constants.py @@ -30,6 +30,7 @@ class SegmentEvents: # Configure the priority of each policy type here. When given multiple redeemable policies to select for redemption, # the policy resolution engine will select policies with the lowest priority number. +ASSIGNED_CREDIT_POLICY_TYPE_PRIORITY = 0 CREDIT_POLICY_TYPE_PRIORITY = 1 SUBSCRIPTION_POLICY_TYPE_PRIORITY = 2 diff --git a/enterprise_access/apps/subsidy_access_policy/models.py b/enterprise_access/apps/subsidy_access_policy/models.py index 46ff611b..fd237054 100644 --- a/enterprise_access/apps/subsidy_access_policy/models.py +++ b/enterprise_access/apps/subsidy_access_policy/models.py @@ -25,6 +25,7 @@ from ..content_assignments.models import AssignmentConfiguration from .constants import ( + ASSIGNED_CREDIT_POLICY_TYPE_PRIORITY, CREDIT_POLICY_TYPE_PRIORITY, FORCE_ENROLLMENT_KEYWORD, REASON_BEYOND_ENROLLMENT_DEADLINE, @@ -1107,6 +1108,16 @@ def priority(self): return CREDIT_POLICY_TYPE_PRIORITY +class AssignedCreditPolicyMixin: + """ + Mixin class for assigned credit type policies. + """ + + @property + def priority(self): + return ASSIGNED_CREDIT_POLICY_TYPE_PRIORITY + + class PerLearnerEnrollmentCreditAccessPolicy(CreditPolicyMixin, SubsidyAccessPolicy): """ Policy that limits the number of enrollments transactions for a learner in a subsidy. @@ -1273,7 +1284,7 @@ def remaining_balance_per_user(self, lms_user_id=None): return self.per_learner_spend_limit - positive_spent_amount -class AssignedLearnerCreditAccessPolicy(CreditPolicyMixin, SubsidyAccessPolicy): +class AssignedLearnerCreditAccessPolicy(AssignedCreditPolicyMixin, SubsidyAccessPolicy): """ Policy based on LearnerContentAssignments, backed by a learner credit type of subsidy.