mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	stream_data: Fix exception when notifications_stream is private.
If notifications_stream is private and the current user has never been subscribed, then we would throw an exception when trying to look up notifications_stream. In this situation, we should just treat it like the stream doesn't exist for the purposes of this user.
This commit is contained in:
		@@ -645,6 +645,13 @@ zrequire('marked', 'third/marked/lib/marked');
 | 
				
			|||||||
    assert(!page_params.never_subscribed);
 | 
					    assert(!page_params.never_subscribed);
 | 
				
			||||||
    assert.equal(page_params.notifications_stream, "");
 | 
					    assert.equal(page_params.notifications_stream, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Simulate a private stream the user isn't subscribed to
 | 
				
			||||||
 | 
					    initialize();
 | 
				
			||||||
 | 
					    page_params.realm_notifications_stream_id = 89;
 | 
				
			||||||
 | 
					    stream_data.initialize_from_page_params();
 | 
				
			||||||
 | 
					    assert.equal(page_params.notifications_stream, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Now actually subscribe the user to the stream
 | 
				
			||||||
    initialize();
 | 
					    initialize();
 | 
				
			||||||
    var foo = {
 | 
					    var foo = {
 | 
				
			||||||
        name: 'foo',
 | 
					        name: 'foo',
 | 
				
			||||||
@@ -652,7 +659,6 @@ zrequire('marked', 'third/marked/lib/marked');
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    stream_data.add_sub('foo', foo);
 | 
					    stream_data.add_sub('foo', foo);
 | 
				
			||||||
    page_params.realm_notifications_stream_id = 89;
 | 
					 | 
				
			||||||
    stream_data.initialize_from_page_params();
 | 
					    stream_data.initialize_from_page_params();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert.equal(page_params.notifications_stream, "foo");
 | 
					    assert.equal(page_params.notifications_stream, "foo");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -520,8 +520,15 @@ exports.initialize_from_page_params = function () {
 | 
				
			|||||||
    // Migrate the notifications stream from the new API structure to
 | 
					    // Migrate the notifications stream from the new API structure to
 | 
				
			||||||
    // what the frontend expects.
 | 
					    // what the frontend expects.
 | 
				
			||||||
    if (page_params.realm_notifications_stream_id !== -1) {
 | 
					    if (page_params.realm_notifications_stream_id !== -1) {
 | 
				
			||||||
        page_params.notifications_stream =
 | 
					        var notifications_stream_obj =
 | 
				
			||||||
            exports.get_sub_by_id(page_params.realm_notifications_stream_id).name;
 | 
					            exports.get_sub_by_id(page_params.realm_notifications_stream_id);
 | 
				
			||||||
 | 
					        if (notifications_stream_obj) {
 | 
				
			||||||
 | 
					            // This happens when the notifications stream is a private
 | 
				
			||||||
 | 
					            // stream the current user is not subscribed to.
 | 
				
			||||||
 | 
					            page_params.notifications_stream = notifications_stream_obj.name;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            page_params.notifications_stream = "";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        page_params.notifications_stream = "";
 | 
					        page_params.notifications_stream = "";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user