bugdown: Add @user|id syntax to support users with same name.

This commit is contained in:
Rohitt Vashishtha
2018-08-18 22:02:17 +00:00
committed by Tim Abbott
parent bc37800ad5
commit 2864ce552b
2 changed files with 38 additions and 1 deletions

View File

@@ -1376,7 +1376,13 @@ class UserMentionPattern(markdown.inlinepatterns.Pattern):
return None
wildcard = mention.user_mention_matches_wildcard(name)
user = arguments.db_data['mention_data'].get_user(name)
id_syntax_match = re.match(r'.+\|(?P<user_id>\d+)$', name)
if id_syntax_match:
id = id_syntax_match.group("user_id")
user = arguments.db_data['mention_data'].get_user_by_id(id)
else:
user = arguments.db_data['mention_data'].get_user(name)
if wildcard:
arguments.current_message.mentions_wildcard = True

View File

@@ -968,6 +968,37 @@ class BugdownTest(ZulipTestCase):
'check this out</p>' % (hamlet.id, cordelia.id))
self.assertEqual(msg.mentions_user_ids, set([hamlet.id, cordelia.id]))
def test_mention_duplicate_full_name(self) -> None:
realm = get_realm('zulip')
def make_user(email: str, full_name: str) -> UserProfile:
return create_user(
email=email,
password='whatever',
realm=realm,
full_name=full_name,
short_name='whatever',
)
sender_user_profile = self.example_user('othello')
twin1 = make_user('twin1@example.com', 'Mark Twin')
twin2 = make_user('twin2@example.com', 'Mark Twin')
cordelia = self.example_user('cordelia')
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = "@**Mark Twin|{}**, @**Mark Twin|{}** and @**Cordelia Lear**, hi.".format(twin1.id, twin2.id)
self.assertEqual(render_markdown(msg, content),
'<p>'
'<span class="user-mention" '
'data-user-id="%s">@Mark Twin</span>, '
'<span class="user-mention" '
'data-user-id="%s">@Mark Twin</span> and '
'<span class="user-mention" '
'data-user-id="%s">@Cordelia Lear</span>, '
'hi.</p>' % (twin1.id, twin2.id, cordelia.id))
self.assertEqual(msg.mentions_user_ids, set([twin1.id, twin2.id, cordelia.id]))
def test_mention_invalid(self) -> None:
sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))