Skip to content

Commit

Permalink
feat: change which reasons are selected for a non-redeemable policy
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Jul 26, 2023
1 parent 41ebf59 commit 6f2bd8d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions enterprise_access/apps/subsidy_access_policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ def will_exceed_spend_limit(self, content_key, content_metadata=None):
def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
"""
Check that a given learner can redeem the given content.
The ordering of each conditional is intentional based on an expected
error message to be shown based on the learners state at the time of
accessing the CourseAbout page in FE-app-learner-portal focusing on the
user state, catalog state based on content key, then subsidy/policy state
based on whether they are active and have spend available for the requested
content.
Returns:
3-tuple of (bool, str, list of dict):
Expand All @@ -335,14 +342,6 @@ def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
active_subsidy = subsidy_can_redeem_payload.get('active', False)
existing_transactions = subsidy_can_redeem_payload.get('all_transactions', [])

# inactive subsidy
if not active_subsidy:
return (False, REASON_SUBSIDY_EXPIRED, [])

# inactive policy
if not self.active:
return (False, REASON_POLICY_EXPIRED, [])

# learner not associated to enterprise
if not skip_customer_user_check:
if not self.lms_api_client.enterprise_contains_learner(self.enterprise_customer_uuid, lms_user_id):
Expand All @@ -356,6 +355,16 @@ def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
if not content_metadata:
return (False, REASON_CONTENT_NOT_IN_CATALOG, existing_transactions)

# TODO: Add Course Upgrade/Registration Deadline Passed Error here

# inactive subsidy
if not active_subsidy:
return (False, REASON_SUBSIDY_EXPIRED, [])

# inactive policy
if not self.active:
return (False, REASON_POLICY_EXPIRED, [])

# can_redeem false from subsidy
if not subsidy_can_redeem_payload.get('can_redeem', False):
return (False, REASON_NOT_ENOUGH_VALUE_IN_SUBSIDY, existing_transactions)
Expand Down

0 comments on commit 6f2bd8d

Please sign in to comment.