urls: Support simple user_id-based slugs.

This commit is contained in:
Steve Howell 2020-07-03 15:02:30 +00:00 committed by Tim Abbott
parent 2574efde3d
commit ad8e79a22e
3 changed files with 20 additions and 5 deletions

View File

@ -12,7 +12,7 @@ set_global('location', {
}); });
const hamlet = { const hamlet = {
user_id: 1, user_id: 15,
email: 'hamlet@example.com', email: 'hamlet@example.com',
full_name: 'Hamlet', full_name: 'Hamlet',
}; };
@ -49,7 +49,7 @@ run_test('hash_util', () => {
let operator = 'sender'; let operator = 'sender';
let operand = hamlet.email; let operand = hamlet.email;
encode_decode_operand(operator, operand, '1-hamlet'); encode_decode_operand(operator, operand, '15-hamlet');
operator = 'stream'; operator = 'stream';
operand = 'frontend'; operand = 'frontend';
@ -161,7 +161,7 @@ run_test('test_by_conversation_and_time_uri', () => {
}; };
assert.equal(hash_util.by_conversation_and_time_uri(message), 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', () => { 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"); set_uri("#narrow/sender/15");
assert.equal(hash_util.search_public_streams_notice_url(), assert.equal(hash_util.search_public_streams_notice_url(),
"#narrow/streams/public/sender/15"); "#narrow/streams/public/sender/15-hamlet");
}); });

View File

@ -560,6 +560,9 @@ run_test('multi_user_methods', () => {
let emails_string = people.user_ids_string_to_emails_string('402,401'); let emails_string = people.user_ids_string_to_emails_string('402,401');
assert.equal(emails_string, 'emp401@example.com,emp402@example.com'); 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'); emails_string = people.slug_to_emails('402,401-group');
assert.equal(emails_string, 'emp401@example.com,emp402@example.com'); assert.equal(emails_string, 'emp401@example.com,emp402@example.com');

View File

@ -547,7 +547,19 @@ exports.emails_to_slug = function (emails_string) {
}; };
exports.slug_to_emails = function (slug) { 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) { if (m) {
let user_ids_string = m[1]; let user_ids_string = m[1];
user_ids_string = exports.exclude_me_from_string(user_ids_string); user_ids_string = exports.exclude_me_from_string(user_ids_string);