mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	urls: Support simple user_id-based slugs.
This commit is contained in:
		@@ -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");
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -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');
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user