From ad8e79a22e4497a4a31d5136486ea199fb419bce Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 3 Jul 2020 15:02:30 +0000 Subject: [PATCH] urls: Support simple user_id-based slugs. --- frontend_tests/node_tests/hash_util.js | 8 ++++---- frontend_tests/node_tests/people.js | 3 +++ static/js/people.js | 14 +++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js index cd35de6659..5456cd35af 100644 --- a/frontend_tests/node_tests/hash_util.js +++ b/frontend_tests/node_tests/hash_util.js @@ -12,7 +12,7 @@ set_global('location', { }); const hamlet = { - user_id: 1, + user_id: 15, email: 'hamlet@example.com', full_name: 'Hamlet', }; @@ -49,7 +49,7 @@ run_test('hash_util', () => { let operator = 'sender'; let operand = hamlet.email; - encode_decode_operand(operator, operand, '1-hamlet'); + encode_decode_operand(operator, operand, '15-hamlet'); operator = 'stream'; operand = 'frontend'; @@ -161,7 +161,7 @@ run_test('test_by_conversation_and_time_uri', () => { }; assert.equal(hash_util.by_conversation_and_time_uri(message), - 'https://example.com/#narrow/pm-with/1-pm/near/43'); + 'https://example.com/#narrow/pm-with/15-pm/near/43'); }); run_test('test_search_public_streams_notice_url', () => { @@ -181,5 +181,5 @@ run_test('test_search_public_streams_notice_url', () => { set_uri("#narrow/sender/15"); assert.equal(hash_util.search_public_streams_notice_url(), - "#narrow/streams/public/sender/15"); + "#narrow/streams/public/sender/15-hamlet"); }); diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index 69e630b8e1..e3e5a10c22 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -560,6 +560,9 @@ run_test('multi_user_methods', () => { let emails_string = people.user_ids_string_to_emails_string('402,401'); assert.equal(emails_string, 'emp401@example.com,emp402@example.com'); + emails_string = people.slug_to_emails('402,401'); + assert.equal(emails_string, 'emp401@example.com,emp402@example.com'); + emails_string = people.slug_to_emails('402,401-group'); assert.equal(emails_string, 'emp401@example.com,emp402@example.com'); diff --git a/static/js/people.js b/static/js/people.js index 8a8ab05997..93791f6848 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -547,7 +547,19 @@ exports.emails_to_slug = function (emails_string) { }; exports.slug_to_emails = function (slug) { - const m = /^([\d,]+)-/.exec(slug); + /* + It's not super important to be flexible about + PM-related slugs, since you would rarely post + them to the web, but we we do want to support + reasonable variations: + + 99-alice@example.com + 99 + + Our canonical version is 99-alice@example.com, + and we only care about the "99" prefix. + */ + const m = /^([\d,]+)(-.*)?/.exec(slug); if (m) { let user_ids_string = m[1]; user_ids_string = exports.exclude_me_from_string(user_ids_string);