Skip to content

Commit

Permalink
fix: ensure assigned policies have highest priority
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Sep 13, 2024
1 parent 16e2f11 commit 512dd79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 1 addition & 2 deletions enterprise_access/apps/content_assignments/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions enterprise_access/apps/subsidy_access_policy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion enterprise_access/apps/subsidy_access_policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 512dd79

Please sign in to comment.