Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
f1ebee43
Commit
f1ebee43
authored
Feb 22, 2016
by
Michael Frey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only allow ecommerce checkout if user is also activated
parent
44c27bb1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
12 deletions
+30
-12
common/djangoapps/course_modes/views.py
+1
-1
common/djangoapps/student/views.py
+1
-1
lms/djangoapps/commerce/tests/test_utils.py
+9
-3
lms/djangoapps/commerce/utils.py
+4
-3
lms/djangoapps/courseware/tests/test_views.py
+13
-2
lms/djangoapps/courseware/views.py
+2
-2
No files found.
common/djangoapps/course_modes/views.py
View file @
f1ebee43
...
@@ -151,7 +151,7 @@ class ChooseModeView(View):
...
@@ -151,7 +151,7 @@ class ChooseModeView(View):
if
verified_mode
.
sku
:
if
verified_mode
.
sku
:
ecommerce_service
=
EcommerceService
()
ecommerce_service
=
EcommerceService
()
context
[
"use_ecommerce_payment_flow"
]
=
ecommerce_service
.
is_enabled
()
context
[
"use_ecommerce_payment_flow"
]
=
ecommerce_service
.
is_enabled
(
request
)
context
[
"ecommerce_payment_page"
]
=
ecommerce_service
.
payment_page_url
()
context
[
"ecommerce_payment_page"
]
=
ecommerce_service
.
payment_page_url
()
context
[
"sku"
]
=
verified_mode
.
sku
context
[
"sku"
]
=
verified_mode
.
sku
...
...
common/djangoapps/student/views.py
View file @
f1ebee43
...
@@ -739,7 +739,7 @@ def dashboard(request):
...
@@ -739,7 +739,7 @@ def dashboard(request):
}
}
ecommerce_service
=
EcommerceService
()
ecommerce_service
=
EcommerceService
()
if
ecommerce_service
.
is_enabled
():
if
ecommerce_service
.
is_enabled
(
request
):
context
.
update
({
context
.
update
({
'use_ecommerce_payment_flow'
:
True
,
'use_ecommerce_payment_flow'
:
True
,
'ecommerce_payment_page'
:
ecommerce_service
.
payment_page_url
(),
'ecommerce_payment_page'
:
ecommerce_service
.
payment_page_url
(),
...
...
lms/djangoapps/commerce/tests/test_utils.py
View file @
f1ebee43
...
@@ -5,6 +5,8 @@ from mock import patch
...
@@ -5,6 +5,8 @@ from mock import patch
from
commerce.utils
import
audit_log
,
EcommerceService
from
commerce.utils
import
audit_log
,
EcommerceService
from
commerce.models
import
CommerceConfiguration
from
commerce.models
import
CommerceConfiguration
from
django.test.client
import
RequestFactory
from
student.tests.factories
import
UserFactory
class
AuditLogTests
(
TestCase
):
class
AuditLogTests
(
TestCase
):
...
@@ -25,6 +27,10 @@ class EcommerceServiceTests(TestCase):
...
@@ -25,6 +27,10 @@ class EcommerceServiceTests(TestCase):
SKU
=
'TESTSKU'
SKU
=
'TESTSKU'
def
setUp
(
self
):
def
setUp
(
self
):
self
.
request_factory
=
RequestFactory
()
self
.
user
=
UserFactory
.
create
()
self
.
request
=
self
.
request_factory
.
get
(
"foo"
)
self
.
request
.
user
=
self
.
user
CommerceConfiguration
.
objects
.
create
(
CommerceConfiguration
.
objects
.
create
(
checkout_on_ecommerce_service
=
True
,
checkout_on_ecommerce_service
=
True
,
single_course_checkout_page
=
'/test_basket/'
single_course_checkout_page
=
'/test_basket/'
...
@@ -33,20 +39,20 @@ class EcommerceServiceTests(TestCase):
...
@@ -33,20 +39,20 @@ class EcommerceServiceTests(TestCase):
def
test_is_enabled
(
self
):
def
test_is_enabled
(
self
):
"""Verify that is_enabled() returns True when ecomm checkout is enabled. """
"""Verify that is_enabled() returns True when ecomm checkout is enabled. """
is_enabled
=
EcommerceService
()
.
is_enabled
()
is_enabled
=
EcommerceService
()
.
is_enabled
(
self
.
request
)
self
.
assertTrue
(
is_enabled
)
self
.
assertTrue
(
is_enabled
)
config
=
CommerceConfiguration
.
current
()
config
=
CommerceConfiguration
.
current
()
config
.
checkout_on_ecommerce_service
=
False
config
.
checkout_on_ecommerce_service
=
False
config
.
save
()
config
.
save
()
is_not_enabled
=
EcommerceService
()
.
is_enabled
()
is_not_enabled
=
EcommerceService
()
.
is_enabled
(
self
.
request
)
self
.
assertFalse
(
is_not_enabled
)
self
.
assertFalse
(
is_not_enabled
)
@patch
(
'openedx.core.djangoapps.theming.helpers.is_request_in_themed_site'
)
@patch
(
'openedx.core.djangoapps.theming.helpers.is_request_in_themed_site'
)
def
test_is_enabled_for_microsites
(
self
,
is_microsite
):
def
test_is_enabled_for_microsites
(
self
,
is_microsite
):
"""Verify that is_enabled() returns False if used for a microsite."""
"""Verify that is_enabled() returns False if used for a microsite."""
is_microsite
.
return_value
=
True
is_microsite
.
return_value
=
True
is_not_enabled
=
EcommerceService
()
.
is_enabled
()
is_not_enabled
=
EcommerceService
()
.
is_enabled
(
self
.
request
)
self
.
assertFalse
(
is_not_enabled
)
self
.
assertFalse
(
is_not_enabled
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
...
...
lms/djangoapps/commerce/utils.py
View file @
f1ebee43
...
@@ -44,9 +44,10 @@ class EcommerceService(object):
...
@@ -44,9 +44,10 @@ class EcommerceService(object):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
config
=
CommerceConfiguration
.
current
()
self
.
config
=
CommerceConfiguration
.
current
()
def
is_enabled
(
self
):
def
is_enabled
(
self
,
request
):
""" Check if the service is enabled and that the site is not a microsite. """
""" Check if the user is activated, if the service is enabled and that the site is not a microsite. """
return
self
.
config
.
checkout_on_ecommerce_service
and
not
helpers
.
is_request_in_themed_site
()
return
(
request
.
user
.
is_active
and
self
.
config
.
checkout_on_ecommerce_service
and
not
helpers
.
is_request_in_themed_site
())
def
payment_page_url
(
self
):
def
payment_page_url
(
self
):
""" Return the URL for the checkout page.
""" Return the URL for the checkout page.
...
...
lms/djangoapps/courseware/tests/test_views.py
View file @
f1ebee43
...
@@ -39,6 +39,7 @@ from courseware.testutils import RenderXBlockTestMixin
...
@@ -39,6 +39,7 @@ from courseware.testutils import RenderXBlockTestMixin
from
courseware.tests.factories
import
StudentModuleFactory
from
courseware.tests.factories
import
StudentModuleFactory
from
courseware.user_state_client
import
DjangoXBlockUserStateClient
from
courseware.user_state_client
import
DjangoXBlockUserStateClient
from
edxmako.tests
import
mako_middleware_process_request
from
edxmako.tests
import
mako_middleware_process_request
from
lms.djangoapps.commerce.utils
import
EcommerceService
# pylint: disable=import-error
from
milestones.tests.utils
import
MilestonesTestCaseMixin
from
milestones.tests.utils
import
MilestonesTestCaseMixin
from
openedx.core.djangoapps.self_paced.models
import
SelfPacedConfiguration
from
openedx.core.djangoapps.self_paced.models
import
SelfPacedConfiguration
from
openedx.core.lib.gating
import
api
as
gating_api
from
openedx.core.lib.gating
import
api
as
gating_api
...
@@ -271,13 +272,23 @@ class ViewsTestCase(ModuleStoreTestCase):
...
@@ -271,13 +272,23 @@ class ViewsTestCase(ModuleStoreTestCase):
@ddt.data
(
True
,
False
)
@ddt.data
(
True
,
False
)
def
test_ecommerce_checkout
(
self
,
is_anonymous
):
def
test_ecommerce_checkout
(
self
,
is_anonymous
):
self
.
assert_enrollment_link_present
(
is_anonymous
=
is_anonymous
)
if
not
is_anonymous
:
self
.
assert_enrollment_link_present
(
is_anonymous
=
is_anonymous
)
else
:
request
=
self
.
request_factory
.
get
(
"foo"
)
request
.
user
=
AnonymousUser
()
self
.
assertEqual
(
EcommerceService
()
.
is_enabled
(
request
),
False
)
@ddt.data
(
True
,
False
)
@ddt.data
(
True
,
False
)
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SHOPPING_CART'
),
'Shopping Cart not enabled in settings'
)
@unittest.skipUnless
(
settings
.
FEATURES
.
get
(
'ENABLE_SHOPPING_CART'
),
'Shopping Cart not enabled in settings'
)
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
def
test_ecommerce_checkout_shopping_cart_enabled
(
self
,
is_anonymous
):
def
test_ecommerce_checkout_shopping_cart_enabled
(
self
,
is_anonymous
):
self
.
assert_enrollment_link_present
(
is_anonymous
=
is_anonymous
,
_id
=
True
)
if
not
is_anonymous
:
self
.
assert_enrollment_link_present
(
is_anonymous
=
is_anonymous
,
_id
=
True
)
else
:
request
=
self
.
request_factory
.
get
(
"foo"
)
request
.
user
=
AnonymousUser
()
self
.
assertEqual
(
EcommerceService
()
.
is_enabled
(
request
),
False
)
def
test_user_groups
(
self
):
def
test_user_groups
(
self
):
# depreciated function
# depreciated function
...
...
lms/djangoapps/courseware/views.py
View file @
f1ebee43
...
@@ -906,7 +906,7 @@ def course_about(request, course_id):
...
@@ -906,7 +906,7 @@ def course_about(request, course_id):
ecommerce_checkout_link
=
''
ecommerce_checkout_link
=
''
professional_mode
=
''
professional_mode
=
''
ecomm_service
=
EcommerceService
()
ecomm_service
=
EcommerceService
()
if
ecomm_service
.
is_enabled
()
and
(
if
ecomm_service
.
is_enabled
(
request
)
and
(
CourseMode
.
PROFESSIONAL
in
modes
or
CourseMode
.
NO_ID_PROFESSIONAL_MODE
in
modes
CourseMode
.
PROFESSIONAL
in
modes
or
CourseMode
.
NO_ID_PROFESSIONAL_MODE
in
modes
):
):
professional_mode
=
modes
.
get
(
CourseMode
.
PROFESSIONAL
,
''
)
or
\
professional_mode
=
modes
.
get
(
CourseMode
.
PROFESSIONAL
,
''
)
or
\
...
@@ -944,7 +944,7 @@ def course_about(request, course_id):
...
@@ -944,7 +944,7 @@ def course_about(request, course_id):
'is_cosmetic_price_enabled'
:
settings
.
FEATURES
.
get
(
'ENABLE_COSMETIC_DISPLAY_PRICE'
),
'is_cosmetic_price_enabled'
:
settings
.
FEATURES
.
get
(
'ENABLE_COSMETIC_DISPLAY_PRICE'
),
'course_price'
:
course_price
,
'course_price'
:
course_price
,
'in_cart'
:
in_cart
,
'in_cart'
:
in_cart
,
'ecommerce_checkout'
:
ecomm_service
.
is_enabled
(),
'ecommerce_checkout'
:
ecomm_service
.
is_enabled
(
request
),
'ecommerce_checkout_link'
:
ecommerce_checkout_link
,
'ecommerce_checkout_link'
:
ecommerce_checkout_link
,
'professional_mode'
:
professional_mode
,
'professional_mode'
:
professional_mode
,
'reg_then_add_to_cart_link'
:
reg_then_add_to_cart_link
,
'reg_then_add_to_cart_link'
:
reg_then_add_to_cart_link
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment