Merge pull request #24731 from edx/mikix/small-pls-fixes
Small PLS courseware banner fixes
This commit is contained in:
@@ -13,3 +13,11 @@ def get_microfrontend_url(course_key, view_name=None):
|
||||
mfe_link += '/{}'.format(view_name)
|
||||
|
||||
return mfe_link
|
||||
|
||||
|
||||
def is_request_from_learning_mfe(request):
|
||||
"""
|
||||
Returns whether the given request was made by the frontend-app-learning MFE.
|
||||
"""
|
||||
return (settings.LEARNING_MICROFRONTEND_URL and
|
||||
request.META.get('HTTP_REFERER', '').startswith(settings.LEARNING_MICROFRONTEND_URL))
|
||||
|
||||
@@ -55,6 +55,7 @@ from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException
|
||||
from lms.djangoapps.certificates import api as certs_api
|
||||
from lms.djangoapps.certificates.models import CertificateStatuses
|
||||
from lms.djangoapps.commerce.utils import EcommerceService
|
||||
from lms.djangoapps.course_home_api.utils import is_request_from_learning_mfe
|
||||
from lms.djangoapps.courseware.access import has_access, has_ccx_coach_role
|
||||
from lms.djangoapps.courseware.access_utils import check_course_open_for_learner, check_public_access
|
||||
from lms.djangoapps.courseware.courses import (
|
||||
@@ -1682,7 +1683,7 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True):
|
||||
'web_app_course_url': reverse(COURSE_HOME_VIEW_NAME, args=[course.id]),
|
||||
'on_courseware_page': True,
|
||||
'verified_upgrade_link': verified_upgrade_deadline_link(request.user, course=course),
|
||||
'is_learning_mfe': request.META.get('HTTP_REFERER', '').startswith(settings.LEARNING_MICROFRONTEND_URL),
|
||||
'is_learning_mfe': is_request_from_learning_mfe(request),
|
||||
'is_mobile_app': is_request_from_mobile_app(request),
|
||||
'reset_deadlines_url': reverse(RESET_COURSE_DEADLINES_NAME),
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ from openedx.core.djangolib.js_utils import js_escaped_string
|
||||
<%def name="course_name()">
|
||||
<% return _("{course_number} Courseware").format(course_number=course.display_number_with_default) %>
|
||||
</%def>
|
||||
<%include file="/dates_banner.html" />
|
||||
% if is_mobile_app:
|
||||
<%include file="/dates_banner.html" />
|
||||
% endif
|
||||
<%block name="bodyclass">view-in-course view-courseware courseware ${course.css_class or ''}</%block>
|
||||
<%block name="title"><title>
|
||||
% if section_title:
|
||||
|
||||
@@ -30,8 +30,7 @@ from openedx.core.djangolib.markup import HTML
|
||||
<%include file='bookmark_button.html' args="bookmark_id=bookmark_id, is_bookmarked=bookmarked"/>
|
||||
% endif
|
||||
|
||||
% if vertical_banner_ctas and not is_mobile_app:
|
||||
## We don't show any CTA banners on the mobile app yet, they need to handle these especially.
|
||||
% if vertical_banner_ctas:
|
||||
% for vertical_banner_cta in vertical_banner_ctas:
|
||||
<div class="banner-cta has-button">
|
||||
<div class="banner-cta-text">${vertical_banner_cta['description']}</div>
|
||||
|
||||
@@ -306,10 +306,6 @@ class TestSafeSessionMiddleware(TestSafeSessionsLogMixin, TestCase):
|
||||
def test_error(self):
|
||||
self.verify_error(302)
|
||||
|
||||
def test_error_from_mobile_web_view(self):
|
||||
self.request.path = '/xblock/block-v1:org+course+run+type@html+block@block_id'
|
||||
self.verify_error(401)
|
||||
|
||||
@override_settings(MOBILE_APP_USER_AGENT_REGEXES=[r'open edX Mobile App'])
|
||||
def test_error_from_mobile_app(self):
|
||||
self.request.META = {'HTTP_USER_AGENT': 'open edX Mobile App Version 2.1'}
|
||||
|
||||
@@ -13,20 +13,9 @@ def is_request_from_mobile_app(request):
|
||||
Returns whether the given request was made by an open edX mobile app,
|
||||
either natively or through the mobile web view.
|
||||
|
||||
Note: The check for the user agent works only for mobile apps version 2.1
|
||||
and higher. Previous apps did not update their user agents to include the
|
||||
distinguishing string.
|
||||
|
||||
The check for the web view is a temporary check that works for mobile apps
|
||||
version 2.0 and higher. See is_request_from_mobile_web_view for more
|
||||
information.
|
||||
|
||||
Args:
|
||||
request (HttpRequest)
|
||||
"""
|
||||
if is_request_from_mobile_web_view(request):
|
||||
return True
|
||||
|
||||
if getattr(settings, 'MOBILE_APP_USER_AGENT_REGEXES', None):
|
||||
user_agent = request.META.get('HTTP_USER_AGENT')
|
||||
if user_agent:
|
||||
@@ -35,28 +24,3 @@ def is_request_from_mobile_app(request):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
PATHS_ACCESSED_BY_MOBILE_WITH_SESSION_COOKIES = [
|
||||
r'^/xblock/{usage_key_string}$'.format(usage_key_string=settings.USAGE_KEY_PATTERN),
|
||||
]
|
||||
|
||||
|
||||
def is_request_from_mobile_web_view(request):
|
||||
"""
|
||||
Returns whether the given request was made by an open edX mobile web
|
||||
view using a session cookie.
|
||||
|
||||
Args:
|
||||
request (HttpRequest)
|
||||
"""
|
||||
|
||||
# TODO (MA-1825): This is a TEMPORARY HACK until all of the version 2.0
|
||||
# iOS mobile apps have updated. The earlier versions didn't update their
|
||||
# user agents so we are checking for the specific URLs that are
|
||||
# accessed through the mobile web view.
|
||||
for mobile_path in PATHS_ACCESSED_BY_MOBILE_WITH_SESSION_COOKIES:
|
||||
if re.match(mobile_path, request.path):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import logging
|
||||
|
||||
from crum import get_current_request
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from lms.djangoapps.course_home_api.utils import is_request_from_learning_mfe
|
||||
from openedx.core.lib.mobile_utils import is_request_from_mobile_app
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -35,6 +39,13 @@ class PersonalizedLearnerScheduleCallToAction:
|
||||
"""
|
||||
ctas = []
|
||||
|
||||
# Some checks to disable PLS calls to action until these environments (mobile and MFE) support them natively
|
||||
request = get_current_request()
|
||||
is_mobile_app = request and is_request_from_mobile_app(request)
|
||||
is_learning_mfe = request and is_request_from_learning_mfe(request)
|
||||
if is_mobile_app or is_learning_mfe:
|
||||
return []
|
||||
|
||||
if category == self.CAPA_SUBMIT_DISABLED:
|
||||
# xblock is a capa problem, and the submit button is disabled. Check if it's because of a personalized
|
||||
# schedule due date being missed, and if so, we can offer to shift it.
|
||||
|
||||
Reference in New Issue
Block a user