From 615a609a744d3c7c1ff08fedeccdceb086dd72ca Mon Sep 17 00:00:00 2001 From: Alex Dusenbery Date: Wed, 26 Jul 2023 12:57:03 -0400 Subject: [PATCH] feat: log can_redeem results in viewset's evaluate_policies --- .../apps/api/v1/views/subsidy_access_policy.py | 4 ++++ enterprise_access/apps/subsidy_access_policy/models.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/enterprise_access/apps/api/v1/views/subsidy_access_policy.py b/enterprise_access/apps/api/v1/views/subsidy_access_policy.py index 87ccf919..8c8a35dc 100644 --- a/enterprise_access/apps/api/v1/views/subsidy_access_policy.py +++ b/enterprise_access/apps/api/v1/views/subsidy_access_policy.py @@ -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( diff --git a/enterprise_access/apps/subsidy_access_policy/models.py b/enterprise_access/apps/subsidy_access_policy/models.py index b65da292..edd5c2cb 100644 --- a/enterprise_access/apps/subsidy_access_policy/models.py +++ b/enterprise_access/apps/subsidy_access_policy/models.py @@ -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: """ @@ -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)