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
2 changes: 1 addition & 1 deletion cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@

################# EDX MARKETING SITE ##################################

MKTG_URL_LINK_MAP = {}
MKTG_URLS = {}

ID_VERIFICATION_SUPPORT_LINK = ''
PASSWORD_RESET_SUPPORT_LINK = ''
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 @@ -151,8 +150,6 @@ def get_env_setting(setting):
CACHES['staticfiles']['KEY_PREFIX'] = EDX_PLATFORM_REVISION


MKTG_URL_LINK_MAP.update(_YAML_TOKENS.get('MKTG_URL_LINK_MAP', {}))

#Timezone overrides
TIME_ZONE = CELERY_TIMEZONE

Expand Down
47 changes: 6 additions & 41 deletions common/djangoapps/edxmako/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,23 @@
from django.conf import settings
from django.http import HttpResponse # lint-amnesty, pylint: disable=unused-import
from django.template import engines
from django.urls import reverse, NoReverseMatch
from six.moves.urllib.parse import urljoin
from django.core.validators import URLValidator
from django.core.exceptions import ValidationError

from edx_django_utils.monitoring import set_custom_attribute
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from xmodule.util.xmodule_django import get_current_request_hostname # lint-amnesty, 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 correct URL for a link to the marketing site.

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.
This function returns marketing URLs based on the MKTG_URLS setting,
which can be overridden via MKTG_URL_OVERRIDES for specific links.
"""
# 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,20 +69,6 @@ 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() # lint-amnesty, pylint: disable=unused-variable
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 '#'
Expand All @@ -113,19 +87,12 @@ 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 +111,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
84 changes: 12 additions & 72 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,34 @@ 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_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): # lint-amnesty, 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 == expected_link

@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 == expected_link


class AddLookupTests(TestCase):
Expand Down
1 change: 1 addition & 0 deletions common/djangoapps/student/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@override_settings(
BRAZE_COURSE_ENROLLMENT_CANVAS_ID=BRAZE_COURSE_ENROLLMENT_CANVAS_ID,
LEARNING_MICROFRONTEND_URL="https://learningmfe.openedx.org",
MKTG_URLS={'ROOT': None},
)
class TestCourseEnrollmentEmailTask(ModuleStoreTestCase):
"""
Expand Down
61 changes: 35 additions & 26 deletions lms/djangoapps/branding/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ class TestFooter(TestCase):
"""Test retrieving the footer. """
maxDiff = None

@mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True})
@mock.patch.dict('django.conf.settings.MKTG_URLS', {
"ROOT": "https://edx.org",
"ENTERPRISE": "/enterprise"
@override_settings(
MKTG_URLS={
"ROOT": "https://edx.org",
"ENTERPRISE": "/enterprise"
},
ENTERPRISE_MARKETING_FOOTER_QUERY_PARAMS={},
PLATFORM_NAME='\xe9dX'
)
@with_site_configuration(configuration={
'MKTG_URLS': {
"ROOT": "https://edx.org",
"ENTERPRISE": "/enterprise"
}
})
@override_settings(ENTERPRISE_MARKETING_FOOTER_QUERY_PARAMS={}, PLATFORM_NAME='\xe9dX')
def test_footer_business_links_no_marketing_query_params(self):
"""
Enterprise marketing page values returned should be a concatenation of ROOT and
Expand All @@ -62,27 +70,28 @@ def test_footer_business_links_no_marketing_query_params(self):
business_links = _footer_business_links()
assert business_links[0]['url'] == 'https://edx.org/enterprise'

@mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True})
@mock.patch.dict('django.conf.settings.MKTG_URLS', {
"ROOT": "https://edx.org",
"ABOUT": "/about-us",
"NEWS": "/news-announcements",
"CONTACT": "/contact",
"CAREERS": '/careers',
"FAQ": "/student-faq",
"BLOG": "/edx-blog",
"DONATE": "/donate",
"JOBS": "/jobs",
"SITE_MAP": "/sitemap",
"TRADEMARKS": "/trademarks",
"TOS_AND_HONOR": "/edx-terms-service",
"PRIVACY": "/edx-privacy-policy",
"ACCESSIBILITY": "/accessibility",
"AFFILIATES": '/affiliate-program',
"MEDIA_KIT": "/media-kit",
"ENTERPRISE": "https://business.edx.org"
})
@override_settings(PLATFORM_NAME='\xe9dX')
@override_settings(
MKTG_URLS={
"ROOT": "https://edx.org",
"ABOUT": "/about-us",
"NEWS": "/news-announcements",
"CONTACT": "/contact",
"CAREERS": '/careers',
"FAQ": "/student-faq",
"BLOG": "/edx-blog",
"DONATE": "/donate",
"JOBS": "/jobs",
"SITE_MAP": "/sitemap",
"TRADEMARKS": "/trademarks",
"TOS_AND_HONOR": "/edx-terms-service",
"PRIVACY": "/edx-privacy-policy",
"ACCESSIBILITY": "/accessibility",
"AFFILIATES": '/affiliate-program',
"MEDIA_KIT": "/media-kit",
"ENTERPRISE": "https://business.edx.org"
},
PLATFORM_NAME='\xe9dX'
)
def test_get_footer(self):
actual_footer = get_footer(is_secure=True)
business_url = 'https://business.edx.org/?utm_campaign=edX.org+Referral&utm_source=edX.org&utm_medium=Footer'
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/learner_home/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_happy_path(self, mock_marketing_link):

@ddt.data(
(True, f'{settings.CATALOG_MICROFRONTEND_URL}/courses'),
(False, '/courses'),
(False, 'courses'),
)
@ddt.unpack
def test_link_with_new_catalog_page(self, catalog_mfe_enabled, expected_catalog_link):
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/static_template_view/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# Only enable URLs for those marketing links actually enabled in the
# settings. Disable URLs by marking them as None.
for key, value in settings.MKTG_URL_LINK_MAP.items():
for key, value in settings.MKTG_URLS.items():
# Skip disabled URLs
if value is None:
continue
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@

######################### MARKETING SITE ###############################

MKTG_URL_LINK_MAP = {
MKTG_URLS = {
'ABOUT': 'about',
'CONTACT': 'contact',
'FAQ': 'help',
Expand Down
1 change: 0 additions & 1 deletion lms/envs/minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ TRACKING_BACKENDS: {}
EVENT_TRACKING_BACKENDS: {}
JWT_AUTH: {}
CELERY_QUEUES: {}
MKTG_URL_LINK_MAP: {}
MKTG_URL_OVERRIDES: {}
REST_FRAMEWORK: {}

Expand Down
1 change: 0 additions & 1 deletion lms/envs/mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ MKTG_URLS:
TOS_AND_HONOR: hello
TRADEMARKS: hello
WHAT_IS_VERIFIED_CERT: hello
MKTG_URL_LINK_MAP: {}
MKTG_URL_OVERRIDES:
course-v1:Org+Course+Run: hello
MOBILE_STORE_URLS:
Expand Down
3 changes: 0 additions & 3 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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 @@ -177,8 +176,6 @@ def get_env_setting(setting):
}
)

MKTG_URL_LINK_MAP.update(_YAML_TOKENS.get('MKTG_URL_LINK_MAP', {}))

# Timezone overrides
TIME_ZONE = CELERY_TIMEZONE

Expand Down
2 changes: 1 addition & 1 deletion lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@

######################### MARKETING SITE ###############################

MKTG_URL_LINK_MAP = {
MKTG_URLS = {
'ABOUT': 'about',
'CONTACT': 'contact',
'HELP_CENTER': 'help-center',
Expand Down
Loading
Loading