Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_course_settings_response(self):
"is_prerequisite_courses_enabled": False,
"language_options": settings.ALL_LANGUAGES,
"lms_link_for_about_page": get_link_for_about_page(self.course),
"marketing_enabled": False,
"marketing_enabled": True,
"mfe_proctored_exam_settings_url": get_proctored_exam_settings_url(
self.course.id
),
Expand Down
6 changes: 1 addition & 5 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,11 +1386,7 @@ def get_course_settings(request, course_key, course_block):
'ENABLE_PUBLISHER',
settings.FEATURES.get('ENABLE_PUBLISHER', False)
)
marketing_enabled = configuration_helpers.get_value_for_org(
course_block.location.org,
'ENABLE_MKTG_SITE',
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
)
marketing_enabled = True
enable_extended_course_details = configuration_helpers.get_value_for_org(
course_block.location.org,
'ENABLE_EXTENDED_COURSE_DETAILS',
Expand Down
1 change: 0 additions & 1 deletion cms/envs/mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ FEATURES:
ENABLE_LTI_PROVIDER: true
ENABLE_MAX_FAILED_LOGIN_ATTEMPTS: true
ENABLE_MKTG_EMAIL_OPT_IN: true
ENABLE_MKTG_SITE: true
ENABLE_MOBILE_REST_API: true
ENABLE_PASSWORD_RESET_FAILURE_EMAIL: true
ENABLE_PROCTORED_EXAMS: true
Expand Down
3 changes: 0 additions & 3 deletions cms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def get_env_setting(setting):
'EVENT_TRACKING_BACKENDS',
'JWT_AUTH',
'CELERY_QUEUES',
'MKTG_URL_LINK_MAP',
'REST_FRAMEWORK',
'EVENT_BUS_PRODUCER_CONFIG',
'DEFAULT_FILE_STORAGE',
Expand Down Expand Up @@ -149,8 +148,6 @@ def get_env_setting(setting):
CACHES['staticfiles']['KEY_PREFIX'] = EDX_PLATFORM_REVISION # noqa: F405


MKTG_URL_LINK_MAP.update(_YAML_TOKENS.get('MKTG_URL_LINK_MAP', {})) # noqa: F405

#Timezone overrides
TIME_ZONE = CELERY_TIMEZONE # noqa: F405

Expand Down
60 changes: 14 additions & 46 deletions common/djangoapps/edxmako/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,21 @@
from django.core.validators import URLValidator
from django.http import HttpResponse # pylint: disable=unused-import
from django.template import engines
from django.urls import NoReverseMatch, reverse
from edx_django_utils.monitoring import set_custom_attribute
from six.moves.urllib.parse import urljoin

from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from xmodule.util.xmodule_django import get_current_request_hostname # pylint: disable=wrong-import-order

from . import Engines

log = logging.getLogger(__name__)


def marketing_link(name):
"""Returns the correct URL for a link to the marketing site
depending on if the marketing site is enabled
"""Returns the URL for a marketing site link from MKTG_URLS.

Since the marketing site is enabled by a setting, we have two
possible URLs for certain links. This function is to decides
which URL should be provided.
MKTG_URL_OVERRIDES take priority. 'ROOT' falls back to the local landing page
('/'); any other unconfigured link falls back to '#'.
"""
# link_map maps URLs from the marketing site to the old equivalent on
# the Django site
link_map = settings.MKTG_URL_LINK_MAP
enable_mktg_site = configuration_helpers.get_value(
'ENABLE_MKTG_SITE',
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
)
marketing_urls = configuration_helpers.get_value(
'MKTG_URLS',
settings.MKTG_URLS
Expand All @@ -66,7 +54,7 @@ def marketing_link(name):
log.debug("Invalid link set for link %s: %s", name, err)
return '#'

if enable_mktg_site and name in marketing_urls:
if name in marketing_urls:
# special case for when we only want the root marketing URL
if name == 'ROOT':
return marketing_urls.get('ROOT')
Expand All @@ -81,23 +69,14 @@ def marketing_link(name):
# URLs in the MKTG_URLS setting
# e.g. urljoin('https://marketing.com', 'https://open-edx.org/about') >>> 'https://open-edx.org/about'
return urljoin(marketing_urls.get('ROOT'), marketing_urls.get(name))
# only link to the old pages when the marketing site isn't on
elif not enable_mktg_site and name in link_map:
# don't try to reverse disabled marketing links
if link_map[name] is not None:
host_name = get_current_request_hostname() # pylint: disable=unused-variable # noqa: F841
if link_map[name].startswith('http'):
return link_map[name]
else:
try:
return reverse(link_map[name])
except NoReverseMatch:
log.debug("Cannot find corresponding link for name: %s", name)
set_custom_attribute('unresolved_marketing_link', name)
return '#'
else:
log.debug("Cannot find corresponding link for name: %s", name)
return '#'

# ROOT is the live site root (not a legacy marketing page), so default it to
# the local landing page when no marketing site ROOT is configured.
if name == 'ROOT':
return '/'

log.debug("Cannot find corresponding link for name: %s", name)
return '#'


def is_any_marketing_link_set(names):
Expand All @@ -112,20 +91,11 @@ def is_marketing_link_set(name):
"""
Returns a boolean if a given named marketing link is configured.
"""

enable_mktg_site = configuration_helpers.get_value(
'ENABLE_MKTG_SITE',
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
)
marketing_urls = configuration_helpers.get_value(
'MKTG_URLS',
settings.MKTG_URLS
)

if enable_mktg_site:
return name in marketing_urls
else:
return name in settings.MKTG_URL_LINK_MAP
return name in marketing_urls


def marketing_link_context_processor(request):
Expand All @@ -144,9 +114,7 @@ def marketing_link_context_processor(request):

return {
"MKTG_URL_" + k: marketing_link(k)
for k in (
settings.MKTG_URL_LINK_MAP.keys() | marketing_urls.keys()
)
for k in marketing_urls.keys()
}


Expand Down
90 changes: 16 additions & 74 deletions common/djangoapps/edxmako/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from unittest.mock import Mock, patch

import ddt
from django.conf import settings
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from django.urls import reverse
from edx_django_utils.cache import RequestCache

from common.djangoapps.edxmako import LOOKUP, add_lookup
Expand All @@ -33,92 +31,36 @@ class ShortcutsTests(UrlResetMixin, TestCase):

@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'ABOUT': '/about-us'})
def test_marketing_link(self):
with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}):
# test marketing site on
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
expected_link = 'https://dummy-root/about-us'
link = marketing_link('ABOUT')
assert link == expected_link
# test marketing site off
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
expected_link = reverse(self._get_test_url_name())
link = marketing_link('ABOUT')
assert link == expected_link
expected_link = 'https://dummy-root/about-us'
link = marketing_link('ABOUT')
assert link == expected_link

@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'ABOUT': '/about-us'})
def test_marketing_link_unconfigured(self):
assert marketing_link('NOT_CONFIGURED') == '#'

@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'ABOUT': '/about-us'})
def test_is_marketing_link_set(self):
with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}):
# test marketing site on
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
assert is_marketing_link_set('ABOUT')
assert not is_marketing_link_set('NOT_CONFIGURED')
# test marketing site off
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
assert is_marketing_link_set('ABOUT')
assert not is_marketing_link_set('NOT_CONFIGURED')
assert is_marketing_link_set('ABOUT')
assert not is_marketing_link_set('NOT_CONFIGURED')

@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'ABOUT': '/about-us'})
def test_is_any_marketing_link_set(self):
with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}):
# test marketing site on
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
assert is_any_marketing_link_set(['ABOUT'])
assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED'])
assert not is_any_marketing_link_set(['NOT_CONFIGURED'])
# test marketing site off
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
assert is_any_marketing_link_set(['ABOUT'])
assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED'])
assert not is_any_marketing_link_set(['NOT_CONFIGURED'])

def _get_test_url_name(self): # pylint: disable=missing-function-docstring
if settings.ROOT_URLCONF == 'lms.urls':
# return any lms url name
return 'dashboard'
else:
# return any cms url name
return 'organizations'
assert is_any_marketing_link_set(['ABOUT'])
assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED'])
assert not is_any_marketing_link_set(['NOT_CONFIGURED'])

@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'TOS': '/tos'})
@override_settings(MKTG_URL_OVERRIDES={'TOS': 'https://edx.org'})
def test_override_marketing_link_valid(self):
expected_link = 'https://edx.org'
# test marketing site on
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
link = marketing_link('TOS')
assert link == expected_link
# test marketing site off
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
link = marketing_link('TOS')
assert link == expected_link
link = marketing_link('TOS')
assert link == 'https://edx.org'

@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'TOS': '/tos'})
@override_settings(MKTG_URL_OVERRIDES={'TOS': '123456'})
def test_override_marketing_link_invalid(self):
expected_link = '#'
# test marketing site on
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
link = marketing_link('TOS')
assert link == expected_link
# test marketing site off
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
link = marketing_link('TOS')
assert link == expected_link

@skip_unless_lms
def test_link_map_url_reverse(self):
url_link_map = {
'ABOUT': 'dashboard',
'BAD_URL': 'foobarbaz',
}

with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
with override_settings(MKTG_URL_LINK_MAP=url_link_map):
link = marketing_link('ABOUT')
assert link == '/dashboard'

link = marketing_link('BAD_URL')
assert link == '#'
link = marketing_link('TOS')
assert link == '#'


class AddLookupTests(TestCase):
Expand Down
25 changes: 5 additions & 20 deletions common/djangoapps/student/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,7 @@ def assertChangeEmailSent(self, test_body_type):
# Must have two items in outbox: one for old email, another for new email
assert len(mail.outbox) == 2

use_https = self.request.is_secure()
if settings.FEATURES['ENABLE_MKTG_SITE']:
contact_link = marketing_link('CONTACT')
else:
contact_link = '{protocol}://{site}{link}'.format(
protocol='https' if use_https else 'http',
site=settings.SITE_NAME,
link=reverse('contact'),
)
contact_link = marketing_link('CONTACT')

# Verifying contents
for msg in mail.outbox:
Expand Down Expand Up @@ -590,17 +582,10 @@ def test_new_email_fails(self, ace_mail):
@skip_unless_lms
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'CONTACT': '/help/contact-us'})
@patch('common.djangoapps.student.signals.signals.USER_EMAIL_CHANGED.send')
@ddt.data(
('plain_text', False),
('plain_text', True),
('html', False),
('html', True)
)
@ddt.unpack
def test_successful_email_change(self, test_body_type, test_marketing_enabled, mock_email_change_signal):
with patch.dict(settings.FEATURES, {'ENABLE_MKTG_SITE': test_marketing_enabled}):
self.assertChangeEmailSent(test_body_type)
assert mock_email_change_signal.called
@ddt.data('plain_text', 'html')
def test_successful_email_change(self, test_body_type, mock_email_change_signal):
self.assertChangeEmailSent(test_body_type)
assert mock_email_change_signal.called

meta = json.loads(UserProfile.objects.get(user=self.user).meta)
assert 'old_emails' in meta
Expand Down
5 changes: 2 additions & 3 deletions common/djangoapps/student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin,
MOCK_SETTINGS = {
'FEATURES': {
'DISABLE_START_DATES': False,
'ENABLE_MKTG_SITE': True,
'DISABLE_SET_JWT_COOKIES_FOR_TESTS': True,
},
'SOCIAL_SHARING_SETTINGS': {
Expand Down Expand Up @@ -1087,13 +1086,13 @@ def test_user_with_unacknowledged_notice(self, mock_notices):
Verifies that we will redirect the learner to the URL returned from the `check_for_unacknowledged_notices`
function.
"""
mock_notices.return_value = reverse("about")
mock_notices.return_value = reverse("root")

with override_settings(FEATURES={**settings.FEATURES, 'ENABLE_NOTICES': True}):
response = self.client.get(self.path)

assert response.status_code == 302
assert response.url == "/about"
assert response.url == "/"
mock_notices.assert_called_once()

@patch('common.djangoapps.student.views.dashboard.check_for_unacknowledged_notices')
Expand Down
10 changes: 1 addition & 9 deletions common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,15 +924,7 @@ def confirm_email_change(request, key):
transaction.set_rollback(True)
return response

use_https = request.is_secure()
if settings.FEATURES['ENABLE_MKTG_SITE']:
contact_link = marketing_link('CONTACT')
else:
contact_link = '{protocol}://{site}{link}'.format(
protocol='https' if use_https else 'http',
site=configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME),
link=reverse('contact'),
)
contact_link = marketing_link('CONTACT')

site = Site.objects.get_current()
message_context = get_base_template_context(site)
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/util/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_link_for_about_page(course):

if is_social_sharing_enabled and course.social_sharing_url:
course_about_url = course.social_sharing_url
elif settings.FEATURES.get('ENABLE_MKTG_SITE') and getattr(course, 'marketing_url', None):
elif getattr(course, 'marketing_url', None):
course_about_url = course.marketing_url
else:
course_about_url = f'{about_base_url}/courses/{course.id}/about'
Expand Down
Loading
Loading