This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 254
fix: Embargo API fixed with new product type. #4034
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
from django.utils.translation import ugettext_lazy as _ | ||
from oscar.core.loading import get_model | ||
|
||
from ecommerce.core.constants import SEAT_PRODUCT_CLASS_NAME | ||
from ecommerce.core.constants import SEAT_PRODUCT_CLASS_NAME, COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME | ||
from ecommerce.extensions.analytics.utils import parse_tracking_context | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -100,7 +100,6 @@ def clean_field_value(value): | |
""" | ||
return re.sub(r'[\^:"\']', '', value) | ||
|
||
|
||
def embargo_check(user, site, products, ip=None): | ||
""" Checks if the user has access to purchase products by calling the LMS embargo API. | ||
|
||
|
@@ -118,14 +117,18 @@ def embargo_check(user, site, products, ip=None): | |
_, _, ip = parse_tracking_context(user, usage='embargo') | ||
|
||
for product in products: | ||
# We only are checking Seats | ||
if product.get_product_class().name == SEAT_PRODUCT_CLASS_NAME: | ||
product_class_name = product.get_product_class().name | ||
|
||
# We are checking Seats & Course Entitlement | ||
if product_class_name == SEAT_PRODUCT_CLASS_NAME or product_class_name == COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME: | ||
courses.append(product.course.id) | ||
|
||
if courses: | ||
params = { | ||
'user': user, | ||
'ip_address': ip, | ||
'user': user.username, | ||
# ip variable is None when testing it locally, giving it dummy string "test_local_ip" | ||
# just to bypass the API, otherwise API returns "Missing Parameters" response. | ||
'ip_address': ip or "test_local_ip", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not have a test string hard coded here, especially if it's only for local testing. if we need behavior that varies whether you are in a local dev environment vs stage/prod, i recommend we instead use a config variable that, if true, will override what the |
||
'course_ids': courses | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last time when I reported this issue I tried using the same fix but it didn't work since for course entitlement products we didn't have course attribute set on them and hence the code would raise attribute errors as far as I remember. I would recommend double checking the code by debugging it locally and testing all the scenarios.