Skip to content

Commit

Permalink
Merge pull request #1357 from glogiotatidis/issue-1355
Browse files Browse the repository at this point in the history
[Fix #1355] Add entrypoint_{name,value} to some special links.
  • Loading branch information
glogiotatidis committed Apr 28, 2020
2 parents c120bd4 + ac7b37a commit a2409bb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
6 changes: 5 additions & 1 deletion snippets/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,12 +704,16 @@ def _convert_special_buttons(self, data):
to_append = {}
for key, value in local_data.items():
if key == 'button_url':
action, args = util.convert_special_link(value)
action, args, entrypoint_name, entrypoint_value = util.convert_special_link(value)
if action:
to_append['button_action'] = action
to_delete.append(key)
if args:
to_append['button_action_args'] = args
if entrypoint_name:
to_append['entrypoint_name'] = entrypoint_name
if entrypoint_value:
to_append['entrypoint_value'] = entrypoint_value

for key in to_delete:
local_data.pop(key)
Expand Down
37 changes: 27 additions & 10 deletions snippets/base/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def test_multiple_links_with_metrics(self):
'title': ('And this another variable with <a href="https://snippets.mozilla.org">more '
'links</a>'),
'special_account': 'With <a href="special:accounts">special accounts link</a>.',
'special_appMenu': 'and another <a href="special:menu:appMenu">special menu link</a>.',
'special_appMenu': 'and another <a href="special:menu:appMenu">special menu link</a>',
'special_about': 'and an <a href="special:about:about">about:about</a> link',
'special_preferences': 'and finally <a href="special:preferences">preferences</a>.',
'nolinks': 'And finally one with no links.',
}
final_data = {
Expand All @@ -62,6 +64,8 @@ def test_multiple_links_with_metrics(self):
'title': 'And this another variable with <link4>more links</link4>',
'special_account': 'With <link5>special accounts link</link5>.',
'special_appMenu': 'and another <link6>special menu link</link6>.',
'special_about': 'and an <link7>about:about</link7> link',
'special_preferences': 'and finally <link8>preferences</link8>.',
'nolinks': 'And finally one with no links.',
'links': {
'link0': {
Expand Down Expand Up @@ -89,10 +93,23 @@ def test_multiple_links_with_metrics(self):
'action': 'OPEN_APPLICATIONS_MENU',
'args': 'appMenu',
},
'link7': {
'action': 'OPEN_ABOUT_PAGE',
'args': 'about',
'entrypoint_name': 'entryPoint',
'entrypoint_value': 'snippets',
},
'link8': {
'action': 'OPEN_PREFERENCES_PAGE',
'entrypoint_value': 'snippets',
},
}
}
generated_data = fluent_link_extractor(
data, ['text', 'title', 'special_account', 'special_appMenu', 'nolinks'])
data,
['text', 'title', 'special_account', 'special_appMenu',
'special_about', 'special_preferences', 'nolinks']
)

self.assertEqual(final_data['text'], generated_data['text'])
self.assertEqual(final_data['title'], generated_data['title'])
Expand All @@ -114,15 +131,15 @@ def test_base(self):
}
}
inputs = [
('https://example.com', (None, None)),
('special:menu:foo', ('OPEN_APPLICATIONS_MENU', 'foo')),
('special:about:login', ('OPEN_ABOUT_PAGE', 'login')),
('special:highlight:foo', ('HIGHLIGHT_FEATURE', 'foo')),
('special:preferences', ('OPEN_PREFERENCES_PAGE', None)),
('special:accounts', ('SHOW_FIREFOX_ACCOUNTS', None)),
('special:monitor', ('ENABLE_FIREFOX_MONITOR', monitor_data)),
('https://example.com', (None, None, None, None)),
('special:menu:foo', ('OPEN_APPLICATIONS_MENU', 'foo', None, None)),
('special:about:login', ('OPEN_ABOUT_PAGE', 'login', 'entryPoint', 'snippets')),
('special:highlight:foo', ('HIGHLIGHT_FEATURE', 'foo', None, None)),
('special:preferences', ('OPEN_PREFERENCES_PAGE', None, None, 'snippets')),
('special:accounts', ('SHOW_FIREFOX_ACCOUNTS', None, None, None)),
('special:monitor', ('ENABLE_FIREFOX_MONITOR', monitor_data, None, None)),
# This is invalid link but test that the app doesn't choke.
('special:highlight:', ('HIGHLIGHT_FEATURE', '')),
('special:highlight:', ('HIGHLIGHT_FEATURE', '', None, None)),
]
for url, expected_tuple in inputs:
self.assertEqual(convert_special_link(url), expected_tuple)
Expand Down
13 changes: 10 additions & 3 deletions snippets/base/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,21 @@ def urlparams(url_, fragment=None, query_dict=None, replace=True, **query):


def convert_special_link(url):
action = args = None
action = args = entrypoint_name = entrypoint_value = None
if url.startswith('special:menu:'):
action = 'OPEN_APPLICATIONS_MENU'
args = url.rsplit(':', 1)[1]
elif url.startswith('special:about:'):
action = 'OPEN_ABOUT_PAGE'
args = url.rsplit(':', 1)[1]
entrypoint_name = 'entryPoint'
entrypoint_value = 'snippets'
elif url.startswith('special:highlight:'):
action = 'HIGHLIGHT_FEATURE'
args = url.rsplit(':', 1)[1]
elif url == 'special:preferences':
action = 'OPEN_PREFERENCES_PAGE'
entrypoint_value = 'snippets'
elif url == 'special:accounts':
action = 'SHOW_FIREFOX_ACCOUNTS'
elif url == 'special:monitor':
Expand All @@ -127,7 +130,7 @@ def convert_special_link(url):
'form_type': 'button'
}
}
return action, args
return action, args, entrypoint_name, entrypoint_value


def fluent_link_extractor(data, variables):
Expand All @@ -154,14 +157,18 @@ def __call__(self, matchobj):
if url_match:
url = url_match.group('url')

action, args = convert_special_link(url)
action, args, entrypoint_name, entrypoint_value = convert_special_link(url)

if action:
self.links[keyname] = {
'action': action,
}
if args:
self.links[keyname]['args'] = args
if entrypoint_name:
self.links[keyname]['entrypoint_name'] = entrypoint_name
if entrypoint_value:
self.links[keyname]['entrypoint_value'] = entrypoint_value
else:
self.links[keyname] = {
'url': url,
Expand Down

0 comments on commit a2409bb

Please sign in to comment.