move the anonymous check earlier so that it cannot error out when it expects a non-anonymous user

This commit is contained in:
Emma Green
2019-10-17 12:54:36 -04:00
parent e258fab1ea
commit def6bced98

View File

@@ -89,6 +89,10 @@ def can_receive_discount(user, course, discount_expiration_date=None):
# TODO: Add additional conditions to return False here
# anonymous users should never get the discount
if user.is_anonymous:
return False
# Check if discount has expired
if not discount_expiration_date:
discount_expiration_date = get_discount_expiration_date(user, course)
@@ -113,9 +117,6 @@ def can_receive_discount(user, course, discount_expiration_date=None):
if DiscountRestrictionConfig.disabled_for_course_stacked_config(course):
return False
if user.is_anonymous:
return False
# Don't allow users who have enrolled in any courses in non-upsellable
# modes
if CourseEnrollment.objects.filter(user=user).exclude(mode__in=CourseMode.UPSELL_TO_VERIFIED_MODES).exists():