Skip to content

Commit

Permalink
Merge pull request #11648 from edx/patch/2016-02-24
Browse files Browse the repository at this point in the history
Only allow ecommerce checkout if user is also activated
  • Loading branch information
mjfrey committed Feb 24, 2016
2 parents 44c27bb + c63dcf0 commit 70ad954
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cms/static/cms/js/require-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
// end of Annotation tool files

// externally hosted files
"mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured", // jshint ignore:line
"mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured", // jshint ignore:line
"youtube": [
// youtube URL does not end in ".js". We add "?noext" to the path so
// that require.js adds the ".js" to the query component of the URL,
Expand Down
2 changes: 1 addition & 1 deletion cms/static/coffee/spec/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ requirejs.config({
"URI": "xmodule_js/common_static/js/vendor/URI.min",
"mock-ajax": "xmodule_js/common_static/js/vendor/mock-ajax",

"mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured",
"mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured",
"youtube": "//www.youtube.com/player_api?noext",

"coffee/src/ajax_prefix": "xmodule_js/common_static/coffee/src/ajax_prefix",
Expand Down
2 changes: 1 addition & 1 deletion cms/static/coffee/spec/main_squire.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ requirejs.config({
"domReady": "xmodule_js/common_static/js/vendor/domReady",
"URI": "xmodule_js/common_static/js/vendor/URI.min",

"mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured",
"mathjax": "//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured",
"youtube": "//www.youtube.com/player_api?noext",

"coffee/src/ajax_prefix": "xmodule_js/common_static/coffee/src/ajax_prefix"
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/course_modes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get(self, request, course_id, error=None):

if verified_mode.sku:
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["sku"] = verified_mode.sku

Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def dashboard(request):
}

ecommerce_service = EcommerceService()
if ecommerce_service.is_enabled():
if ecommerce_service.is_enabled(request):
context.update({
'use_ecommerce_payment_flow': True,
'ecommerce_payment_page': ecommerce_service.payment_page_url(),
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/terrain/ui_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def css_contains_text(css_selector, partial_text, index=0):
# If we're expecting a non-empty string, give the page
# a chance to fill in text fields.
if partial_text:
wait_for(lambda _: css_html(css_selector, index=index))
wait_for(lambda _: css_html(css_selector, index=index), timeout=8)

actual_text = css_html(css_selector, index=index)

Expand Down
2 changes: 1 addition & 1 deletion common/lib/capa/capa/templates/formulaequationinput.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p id="answer_${id}" class="answer"></p>

<div id="input_${id}_preview" class="equation">
\[\]
\(\)
<img src="${STATIC_URL}images/spinner.gif" class="loading" alt="Loading"/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions common/static/js/capa/spec/formula_equation_preview_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe("Formula Equation Preview", function () {
// Either it makes a request or jumps straight into displaying ''.
waitsFor(function () {
// (Short circuit if `inputAjax` is indeed called)
return Problem.inputAjax.wasCalled ||
return Problem.inputAjax.wasCalled || // jshint ignore:line
MathJax.Hub.Queue.wasCalled;
}, "AJAX never called on user input", 1000);

Expand Down Expand Up @@ -266,7 +266,7 @@ describe("Formula Equation Preview", function () {

// We should look in the preview div for the MathJax.
var previewElement = $("#input_THE_ID_preview")[0];
expect(previewElement.firstChild.data).toEqual("\\[THE_FORMULA\\]");
expect(previewElement.firstChild.data).toEqual("\\(THE_FORMULA\\)");

// Refresh the MathJax.
expect(MathJax.Hub.Queue).toHaveBeenCalledWith(
Expand Down
2 changes: 1 addition & 1 deletion common/static/js/capa/src/formula_equation_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ formulaEquationPreview.enable = function () {
console.log("[FormulaEquationInput] Oops no mathjax for ", latex);
// Fall back to modifying the actual element.
var textNode = previewElement.childNodes[0];
textNode.data = "\\[" + latex + "\\]";
textNode.data = "\\(" + latex + "\\)";
MathJax.Hub.Queue(["Typeset", MathJax.Hub, previewElement]);
}
});
Expand Down
2 changes: 1 addition & 1 deletion common/templates/mathjax_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
<!-- This must appear after all mathjax-config blocks, so it is after the imports from the other templates.
It can't be run through static.url because MathJax uses crazy url introspection to do lazy loading of
MathJax extension libraries -->
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG"></script>
2 changes: 1 addition & 1 deletion common/test/acceptance/pages/lms/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def verify_mathjax_preview_available(self):
def verify_mathjax_rendered(self):
""" Checks that MathJax css class is present """
self.wait_for(
lambda: self._is_element_visible(".MathJax_CHTML"),
lambda: self._is_element_visible(".MathJax_SVG"),
description="MathJax Preview is rendered"
)

Expand Down
4 changes: 2 additions & 2 deletions common/test/acceptance/pages/lms/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def verify_mathjax_rendered_in_problem(self):
"""
def mathjax_present():
""" Returns True if MathJax css is present in the problem body """
mathjax_container = self.q(css="div.problem p .MathJax_CHTML")
mathjax_container = self.q(css="div.problem p .MathJax_SVG")
return mathjax_container.visible and mathjax_container.present

self.wait_for(
Expand All @@ -63,7 +63,7 @@ def verify_mathjax_rendered_in_hint(self):
"""
def mathjax_present():
""" Returns True if MathJax css is present in the problem body """
mathjax_container = self.q(css="div.problem div.problem-hint .MathJax_CHTML")
mathjax_container = self.q(css="div.problem div.problem-hint .MathJax_SVG")
return mathjax_container.visible and mathjax_container.present

self.wait_for(
Expand Down
2 changes: 1 addition & 1 deletion common/test/acceptance/pages/lms/tab_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def mathjax_has_rendered(self):
"""
Check that MathJax has rendered in tab content
"""
mathjax_container = self.q(css=".static_tab_wrapper .MathJax_CHTML")
mathjax_container = self.q(css=".static_tab_wrapper .MathJax_SVG")
EmptyPromise(
lambda: mathjax_container.present and mathjax_container.visible,
"MathJax is not visible"
Expand Down
2 changes: 2 additions & 0 deletions common/test/acceptance/tests/discussion/test_discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
from uuid import uuid4

from flaky import flaky
from nose.plugins.attrib import attr
from pytz import UTC

Expand Down Expand Up @@ -400,6 +401,7 @@ def setup_view(self):
)
view.push()

@flaky # TODO: TNL-4151
def test_comment_deletion_as_student(self):
self.setup_user()
self.setup_view()
Expand Down
12 changes: 9 additions & 3 deletions lms/djangoapps/commerce/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from commerce.utils import audit_log, EcommerceService
from commerce.models import CommerceConfiguration
from django.test.client import RequestFactory
from student.tests.factories import UserFactory


class AuditLogTests(TestCase):
Expand All @@ -25,6 +27,10 @@ class EcommerceServiceTests(TestCase):
SKU = 'TESTSKU'

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(
checkout_on_ecommerce_service=True,
single_course_checkout_page='/test_basket/'
Expand All @@ -33,20 +39,20 @@ def setUp(self):

def test_is_enabled(self):
"""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)

config = CommerceConfiguration.current()
config.checkout_on_ecommerce_service = False
config.save()
is_not_enabled = EcommerceService().is_enabled()
is_not_enabled = EcommerceService().is_enabled(self.request)
self.assertFalse(is_not_enabled)

@patch('openedx.core.djangoapps.theming.helpers.is_request_in_themed_site')
def test_is_enabled_for_microsites(self, is_microsite):
"""Verify that is_enabled() returns False if used for a microsite."""
is_microsite.return_value = True
is_not_enabled = EcommerceService().is_enabled()
is_not_enabled = EcommerceService().is_enabled(self.request)
self.assertFalse(is_not_enabled)

@override_settings(ECOMMERCE_PUBLIC_URL_ROOT='http://ecommerce_url')
Expand Down
7 changes: 4 additions & 3 deletions lms/djangoapps/commerce/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class EcommerceService(object):
def __init__(self):
self.config = CommerceConfiguration.current()

def is_enabled(self):
""" Check 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()
def is_enabled(self, request):
""" Check if the user is activated, if the service is enabled and that the site is not a microsite. """
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):
""" Return the URL for the checkout page.
Expand Down
15 changes: 13 additions & 2 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from courseware.tests.factories import StudentModuleFactory
from courseware.user_state_client import DjangoXBlockUserStateClient
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 openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from openedx.core.lib.gating import api as gating_api
Expand Down Expand Up @@ -271,13 +272,23 @@ def assert_enrollment_link_present(self, is_anonymous, _id=False):

@ddt.data(True, False)
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)
@unittest.skipUnless(settings.FEATURES.get('ENABLE_SHOPPING_CART'), 'Shopping Cart not enabled in settings')
@patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True})
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):
# depreciated function
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ def course_about(request, course_id):
ecommerce_checkout_link = ''
professional_mode = ''
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
):
professional_mode = modes.get(CourseMode.PROFESSIONAL, '') or \
Expand Down Expand Up @@ -944,7 +944,7 @@ def course_about(request, course_id):
'is_cosmetic_price_enabled': settings.FEATURES.get('ENABLE_COSMETIC_DISPLAY_PRICE'),
'course_price': course_price,
'in_cart': in_cart,
'ecommerce_checkout': ecomm_service.is_enabled(),
'ecommerce_checkout': ecomm_service.is_enabled(request),
'ecommerce_checkout_link': ecommerce_checkout_link,
'professional_mode': professional_mode,
'reg_then_add_to_cart_link': reg_then_add_to_cart_link,
Expand Down
2 changes: 1 addition & 1 deletion lms/static/js/spec/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'jasmine.async': 'xmodule_js/common_static/js/vendor/jasmine.async',
'draggabilly': 'xmodule_js/common_static/js/vendor/draggabilly.pkgd',
'domReady': 'xmodule_js/common_static/js/vendor/domReady',
'mathjax': '//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML&delayStartupUntil=configured', // jshint ignore:line
'mathjax': '//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // jshint ignore:line
'youtube': '//www.youtube.com/player_api?noext',
'coffee/src/ajax_prefix': 'xmodule_js/common_static/coffee/src/ajax_prefix',
'coffee/src/instructor_dashboard/student_admin': 'coffee/src/instructor_dashboard/student_admin',
Expand Down

0 comments on commit 70ad954

Please sign in to comment.