bugdown: Remove email from rendered content of messages with mentions.

This field has been unused by clients for some time, and isn't great
for our public archive feature plans (where we'll not want to be
including email addresses in messages).
This commit is contained in:
Aditya Bansal 2018-01-21 11:03:42 +05:30 committed by Tim Abbott
parent d36ec962bb
commit 9eeb1c59f6
4 changed files with 9 additions and 17 deletions

View File

@ -1384,11 +1384,9 @@ class UserMentionPattern(markdown.inlinepatterns.Pattern):
if wildcard:
current_message.mentions_wildcard = True
email = '*'
user_id = "*"
elif user:
current_message.mentions_user_ids.add(user['id'])
email = user['email']
name = user['full_name']
user_id = str(user['id'])
else:
@ -1397,7 +1395,6 @@ class UserMentionPattern(markdown.inlinepatterns.Pattern):
el = markdown.util.etree.Element("span")
el.set('class', 'user-mention')
el.set('data-user-email', email)
el.set('data-user-id', user_id)
el.text = "@%s" % (name,)
return el

View File

@ -786,7 +786,7 @@ class BugdownTest(ZulipTestCase):
content = "@**all** test"
self.assertEqual(render_markdown(msg, content),
'<p><span class="user-mention" data-user-email="*" data-user-id="*">'
'<p><span class="user-mention" data-user-id="*">'
'@all'
'</span> test</p>')
self.assertTrue(msg.mentions_wildcard)
@ -797,7 +797,7 @@ class BugdownTest(ZulipTestCase):
content = "@**everyone** test"
self.assertEqual(render_markdown(msg, content),
'<p><span class="user-mention" data-user-email="*" data-user-id="*">'
'<p><span class="user-mention" data-user-id="*">'
'@everyone'
'</span> test</p>')
self.assertTrue(msg.mentions_wildcard)
@ -851,9 +851,8 @@ class BugdownTest(ZulipTestCase):
content = "@**King Hamlet**"
self.assertEqual(render_markdown(msg, content),
'<p><span class="user-mention" '
'data-user-email="%s" '
'data-user-id="%s">'
'@King Hamlet</span></p>' % (self.example_email("hamlet"), user_id))
'@King Hamlet</span></p>' % (user_id))
self.assertEqual(msg.mentions_user_ids, set([user_profile.id]))
def test_possible_mentions(self) -> None:
@ -881,12 +880,10 @@ class BugdownTest(ZulipTestCase):
self.assertEqual(render_markdown(msg, content),
'<p>'
'<span class="user-mention" '
'data-user-email="%s" '
'data-user-id="%s">@King Hamlet</span> and '
'<span class="user-mention" '
'data-user-email="%s" '
'data-user-id="%s">@Cordelia Lear</span>, '
'check this out</p>' % (hamlet.email, hamlet.id, cordelia.email, cordelia.id))
'check this out</p>' % (hamlet.id, cordelia.id))
self.assertEqual(msg.mentions_user_ids, set([hamlet.id, cordelia.id]))
def test_mention_invalid(self) -> None:
@ -912,13 +909,11 @@ class BugdownTest(ZulipTestCase):
content = "@**King Hamlet** @*support*"
self.assertEqual(render_markdown(msg, content),
'<p><span class="user-mention" '
'data-user-email="%s" '
'data-user-id="%s">'
'@King Hamlet</span> '
'<span class="user-group-mention" '
'data-user-group-id="%s">'
'@support</span></p>' % (self.example_email("hamlet"),
user_id,
'@support</span></p>' % (user_id,
user_group.id))
self.assertEqual(msg.mentions_user_ids, set([user_profile.id]))
self.assertEqual(msg.mentions_user_group_ids, set([user_group.id]))
@ -1246,7 +1241,7 @@ class BugdownApiTests(ZulipTestCase):
user_id = self.example_user('hamlet').id
stream_id = get_stream('Denmark', get_realm('zulip')).id
self.assertEqual(result.json()['rendered'],
u'<p>This mentions <a class="stream" data-stream-id="%s" href="/#narrow/stream/%s-Denmark">#Denmark</a> and <span class="user-mention" data-user-email="%s" data-user-id="%s">@King Hamlet</span>.</p>' % (stream_id, stream_id, self.example_email("hamlet"), user_id))
u'<p>This mentions <a class="stream" data-stream-id="%s" href="/#narrow/stream/%s-Denmark">#Denmark</a> and <span class="user-mention" data-user-id="%s">@King Hamlet</span>.</p>' % (stream_id, stream_id, user_id))
class BugdownErrorTests(ZulipTestCase):
def test_bugdown_error_handling(self) -> None:

View File

@ -1872,6 +1872,6 @@ class GetOldMessagesTest(ZulipTestCase):
othello = self.example_user('othello')
self.assertEqual(
meeting_message['match_content'],
('<p>How are you doing, <span class="user-mention" data-user-email="%s" data-user-id="%s">' +
('<p>How are you doing, <span class="user-mention" data-user-id="%s">' +
'@<span class="highlight">Othello</span>, the Moor of Venice</span>?</p>') % (
othello.email, othello.id))
othello.id))

View File

@ -1262,7 +1262,7 @@ class TestPushNotificationsContent(ZulipTestCase):
},
{
'name': 'mentions',
'rendered_content': '<p>Mentioning <span class="user-mention" data-user-email="cordelia@zulip.com" data-user-id="3">@Cordelia Lear</span>.</p>',
'rendered_content': '<p>Mentioning <span class="user-mention" data-user-id="3">@Cordelia Lear</span>.</p>',
'expected_output': 'Mentioning @Cordelia Lear.',
},
{