Skip to content

Commit 6263708

Browse files
chore: cleanup of mktg url link map
1 parent 9110ae0 commit 6263708

File tree

11 files changed

+23
-125
lines changed

11 files changed

+23
-125
lines changed

cms/envs/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@
12081208

12091209
################# EDX MARKETING SITE ##################################
12101210

1211-
MKTG_URL_LINK_MAP = {}
1211+
MKTG_URLS = {}
12121212

12131213
ID_VERIFICATION_SUPPORT_LINK = ''
12141214
PASSWORD_RESET_SUPPORT_LINK = ''

cms/envs/production.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def get_env_setting(setting):
8484
'EVENT_TRACKING_BACKENDS',
8585
'JWT_AUTH',
8686
'CELERY_QUEUES',
87-
'MKTG_URL_LINK_MAP',
8887
'REST_FRAMEWORK',
8988
'EVENT_BUS_PRODUCER_CONFIG',
9089
'DEFAULT_FILE_STORAGE',
@@ -151,8 +150,6 @@ def get_env_setting(setting):
151150
CACHES['staticfiles']['KEY_PREFIX'] = EDX_PLATFORM_REVISION
152151

153152

154-
MKTG_URL_LINK_MAP.update(_YAML_TOKENS.get('MKTG_URL_LINK_MAP', {}))
155-
156153
#Timezone overrides
157154
TIME_ZONE = CELERY_TIMEZONE
158155

common/djangoapps/edxmako/shortcuts.py

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,23 @@
1818
from django.conf import settings
1919
from django.http import HttpResponse # lint-amnesty, pylint: disable=unused-import
2020
from django.template import engines
21-
from django.urls import reverse, NoReverseMatch
2221
from six.moves.urllib.parse import urljoin
2322
from django.core.validators import URLValidator
2423
from django.core.exceptions import ValidationError
2524

26-
from edx_django_utils.monitoring import set_custom_attribute
2725
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
28-
from xmodule.util.xmodule_django import get_current_request_hostname # lint-amnesty, pylint: disable=wrong-import-order
2926

3027
from . import Engines
3128

3229
log = logging.getLogger(__name__)
3330

3431

3532
def marketing_link(name):
36-
"""Returns the correct URL for a link to the marketing site
37-
depending on if the marketing site is enabled
33+
"""Returns the correct URL for a link to the marketing site.
3834
39-
Since the marketing site is enabled by a setting, we have two
40-
possible URLs for certain links. This function is to decides
41-
which URL should be provided.
35+
This function returns marketing URLs based on the MKTG_URLS setting,
36+
which can be overridden via MKTG_URL_OVERRIDES for specific links.
4237
"""
43-
# link_map maps URLs from the marketing site to the old equivalent on
44-
# the Django site
45-
link_map = settings.MKTG_URL_LINK_MAP
46-
enable_mktg_site = configuration_helpers.get_value(
47-
'ENABLE_MKTG_SITE',
48-
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
49-
)
5038
marketing_urls = configuration_helpers.get_value(
5139
'MKTG_URLS',
5240
settings.MKTG_URLS
@@ -66,7 +54,7 @@ def marketing_link(name):
6654
log.debug("Invalid link set for link %s: %s", name, err)
6755
return '#'
6856

69-
if enable_mktg_site and name in marketing_urls:
57+
if name in marketing_urls:
7058
# special case for when we only want the root marketing URL
7159
if name == 'ROOT':
7260
return marketing_urls.get('ROOT')
@@ -81,20 +69,6 @@ def marketing_link(name):
8169
# URLs in the MKTG_URLS setting
8270
# e.g. urljoin('https://marketing.com', 'https://open-edx.org/about') >>> 'https://open-edx.org/about'
8371
return urljoin(marketing_urls.get('ROOT'), marketing_urls.get(name))
84-
# only link to the old pages when the marketing site isn't on
85-
elif not enable_mktg_site and name in link_map:
86-
# don't try to reverse disabled marketing links
87-
if link_map[name] is not None:
88-
host_name = get_current_request_hostname() # lint-amnesty, pylint: disable=unused-variable
89-
if link_map[name].startswith('http'):
90-
return link_map[name]
91-
else:
92-
try:
93-
return reverse(link_map[name])
94-
except NoReverseMatch:
95-
log.debug("Cannot find corresponding link for name: %s", name)
96-
set_custom_attribute('unresolved_marketing_link', name)
97-
return '#'
9872
else:
9973
log.debug("Cannot find corresponding link for name: %s", name)
10074
return '#'
@@ -113,19 +87,12 @@ def is_marketing_link_set(name):
11387
Returns a boolean if a given named marketing link is configured.
11488
"""
11589

116-
enable_mktg_site = configuration_helpers.get_value(
117-
'ENABLE_MKTG_SITE',
118-
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
119-
)
12090
marketing_urls = configuration_helpers.get_value(
12191
'MKTG_URLS',
12292
settings.MKTG_URLS
12393
)
12494

125-
if enable_mktg_site:
126-
return name in marketing_urls
127-
else:
128-
return name in settings.MKTG_URL_LINK_MAP
95+
return name in marketing_urls
12996

13097

13198
def marketing_link_context_processor(request):
@@ -144,9 +111,7 @@ def marketing_link_context_processor(request):
144111

145112
return {
146113
"MKTG_URL_" + k: marketing_link(k)
147-
for k in (
148-
settings.MKTG_URL_LINK_MAP.keys() | marketing_urls.keys()
149-
)
114+
for k in marketing_urls.keys()
150115
}
151116

152117

common/djangoapps/edxmako/tests.py

Lines changed: 12 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.test import TestCase
99
from django.test.client import RequestFactory
1010
from django.test.utils import override_settings
11-
from django.urls import reverse
1211
from edx_django_utils.cache import RequestCache
1312

1413
from common.djangoapps.edxmako import LOOKUP, add_lookup
@@ -33,92 +32,34 @@ class ShortcutsTests(UrlResetMixin, TestCase):
3332

3433
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'ABOUT': '/about-us'})
3534
def test_marketing_link(self):
36-
with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}):
37-
# test marketing site on
38-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
39-
expected_link = 'https://dummy-root/about-us'
40-
link = marketing_link('ABOUT')
41-
assert link == expected_link
42-
# test marketing site off
43-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
44-
expected_link = reverse(self._get_test_url_name())
45-
link = marketing_link('ABOUT')
46-
assert link == expected_link
35+
expected_link = 'https://dummy-root/about-us'
36+
link = marketing_link('ABOUT')
37+
assert link == expected_link
4738

4839
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'ABOUT': '/about-us'})
4940
def test_is_marketing_link_set(self):
50-
with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}):
51-
# test marketing site on
52-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
53-
assert is_marketing_link_set('ABOUT')
54-
assert not is_marketing_link_set('NOT_CONFIGURED')
55-
# test marketing site off
56-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
57-
assert is_marketing_link_set('ABOUT')
58-
assert not is_marketing_link_set('NOT_CONFIGURED')
41+
assert is_marketing_link_set('ABOUT')
42+
assert not is_marketing_link_set('NOT_CONFIGURED')
5943

6044
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'ABOUT': '/about-us'})
6145
def test_is_any_marketing_link_set(self):
62-
with override_settings(MKTG_URL_LINK_MAP={'ABOUT': self._get_test_url_name()}):
63-
# test marketing site on
64-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
65-
assert is_any_marketing_link_set(['ABOUT'])
66-
assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED'])
67-
assert not is_any_marketing_link_set(['NOT_CONFIGURED'])
68-
# test marketing site off
69-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
70-
assert is_any_marketing_link_set(['ABOUT'])
71-
assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED'])
72-
assert not is_any_marketing_link_set(['NOT_CONFIGURED'])
73-
74-
def _get_test_url_name(self): # lint-amnesty, pylint: disable=missing-function-docstring
75-
if settings.ROOT_URLCONF == 'lms.urls':
76-
# return any lms url name
77-
return 'dashboard'
78-
else:
79-
# return any cms url name
80-
return 'organizations'
46+
assert is_any_marketing_link_set(['ABOUT'])
47+
assert is_any_marketing_link_set(['ABOUT', 'NOT_CONFIGURED'])
48+
assert not is_any_marketing_link_set(['NOT_CONFIGURED'])
8149

8250
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'TOS': '/tos'})
8351
@override_settings(MKTG_URL_OVERRIDES={'TOS': 'https://edx.org'})
8452
def test_override_marketing_link_valid(self):
8553
expected_link = 'https://edx.org'
86-
# test marketing site on
87-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
88-
link = marketing_link('TOS')
89-
assert link == expected_link
90-
# test marketing site off
91-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
92-
link = marketing_link('TOS')
93-
assert link == expected_link
54+
link = marketing_link('TOS')
55+
assert link == expected_link
9456

9557
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root', 'TOS': '/tos'})
9658
@override_settings(MKTG_URL_OVERRIDES={'TOS': '123456'})
9759
def test_override_marketing_link_invalid(self):
9860
expected_link = '#'
99-
# test marketing site on
100-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
101-
link = marketing_link('TOS')
102-
assert link == expected_link
103-
# test marketing site off
104-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
105-
link = marketing_link('TOS')
106-
assert link == expected_link
107-
108-
@skip_unless_lms
109-
def test_link_map_url_reverse(self):
110-
url_link_map = {
111-
'ABOUT': 'dashboard',
112-
'BAD_URL': 'foobarbaz',
113-
}
114-
115-
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
116-
with override_settings(MKTG_URL_LINK_MAP=url_link_map):
117-
link = marketing_link('ABOUT')
118-
assert link == '/dashboard'
119-
120-
link = marketing_link('BAD_URL')
121-
assert link == '#'
61+
link = marketing_link('TOS')
62+
assert link == expected_link
12263

12364

12465
class AddLookupTests(TestCase):

lms/djangoapps/static_template_view/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
# Only enable URLs for those marketing links actually enabled in the
2828
# settings. Disable URLs by marking them as None.
29-
for key, value in settings.MKTG_URL_LINK_MAP.items():
29+
for key, value in settings.MKTG_URLS.items():
3030
# Skip disabled URLs
3131
if value is None:
3232
continue

lms/envs/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@
23972397

23982398
######################### MARKETING SITE ###############################
23992399

2400-
MKTG_URL_LINK_MAP = {
2400+
MKTG_URLS = {
24012401
'ABOUT': 'about',
24022402
'CONTACT': 'contact',
24032403
'FAQ': 'help',

lms/envs/minimal.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ TRACKING_BACKENDS: {}
1515
EVENT_TRACKING_BACKENDS: {}
1616
JWT_AUTH: {}
1717
CELERY_QUEUES: {}
18-
MKTG_URL_LINK_MAP: {}
1918
MKTG_URL_OVERRIDES: {}
2019
REST_FRAMEWORK: {}
2120

lms/envs/mock.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ MKTG_URLS:
831831
TOS_AND_HONOR: hello
832832
TRADEMARKS: hello
833833
WHAT_IS_VERIFIED_CERT: hello
834-
MKTG_URL_LINK_MAP: {}
835834
MKTG_URL_OVERRIDES:
836835
course-v1:Org+Course+Run: hello
837836
MOBILE_STORE_URLS:

lms/envs/production.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def get_env_setting(setting):
7979
'EVENT_TRACKING_BACKENDS',
8080
'JWT_AUTH',
8181
'CELERY_QUEUES',
82-
'MKTG_URL_LINK_MAP',
8382
'REST_FRAMEWORK',
8483
'EVENT_BUS_PRODUCER_CONFIG',
8584
'DEFAULT_FILE_STORAGE',
@@ -177,8 +176,6 @@ def get_env_setting(setting):
177176
}
178177
)
179178

180-
MKTG_URL_LINK_MAP.update(_YAML_TOKENS.get('MKTG_URL_LINK_MAP', {}))
181-
182179
# Timezone overrides
183180
TIME_ZONE = CELERY_TIMEZONE
184181

lms/envs/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272

273273
######################### MARKETING SITE ###############################
274274

275-
MKTG_URL_LINK_MAP = {
275+
MKTG_URLS = {
276276
'ABOUT': 'about',
277277
'CONTACT': 'contact',
278278
'HELP_CENTER': 'help-center',

0 commit comments

Comments
 (0)