Skip to content

Commit

Permalink
feat: log can_redeem results in viewset's evaluate_policies
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Jul 26, 2023
1 parent a7f2af2 commit 615a609
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions enterprise_access/apps/api/v1/views/subsidy_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ def evaluate_policies(self, enterprise_customer_uuid, lms_user_id, content_key):
for policy in all_policies_for_enterprise:
try:
redeemable, reason, _ = policy.can_redeem(lms_user_id, content_key, skip_customer_user_check=True)
logger.info(
f'[can_redeem] {policy} inputs: (lms_user_id={lms_user_id}, content_key={content_key}) results: '
f'redeemable={redeemable}, reason={reason}.'
)
except ContentPriceNullException as exc:
logger.warning(f'{exc} when checking can_redeem() for {enterprise_customer_uuid}')
raise RedemptionRequestException(
Expand Down
10 changes: 8 additions & 2 deletions enterprise_access/apps/subsidy_access_policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ def delete(self, *args, **kwargs):
self.active = False
self.save()

def __str__(self):
return f'<{self.__class__} uuid={self.uuid}>'


class CreditPolicyMixin:
"""
Expand Down Expand Up @@ -641,8 +644,11 @@ def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
limits specified on the policy.
"""
# perform generic access checks
should_attempt_redemption, reason, existing_redemptions = \
super().can_redeem(lms_user_id, content_key, skip_customer_user_check)
should_attempt_redemption, reason, existing_redemptions = super().can_redeem(
lms_user_id,
content_key,
skip_customer_user_check,
)
if not should_attempt_redemption:
return (False, reason, existing_redemptions)

Expand Down

0 comments on commit 615a609

Please sign in to comment.