mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	subscription: Add real time sync for user-just-deactivated case.
Currently, stream subscriptions aren't getting updated without hard reload when user is deactivated in realm. Fix this issue by updating stream subscription widgets on user deactivation event. Fixes #5623
This commit is contained in:
		@@ -750,6 +750,7 @@ with_overrides(function (override) {
 | 
				
			|||||||
    event = event_fixtures.realm_user__remove;
 | 
					    event = event_fixtures.realm_user__remove;
 | 
				
			||||||
    global.with_stub(function (stub) {
 | 
					    global.with_stub(function (stub) {
 | 
				
			||||||
        override('people.deactivate', stub.f);
 | 
					        override('people.deactivate', stub.f);
 | 
				
			||||||
 | 
					        override('stream_data.remove_deactivated_user_from_all_streams', noop);
 | 
				
			||||||
        dispatch(event);
 | 
					        dispatch(event);
 | 
				
			||||||
        var args = stub.get_args('person');
 | 
					        var args = stub.get_args('person');
 | 
				
			||||||
        assert_same(args.person, event.person);
 | 
					        assert_same(args.person, event.person);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -209,6 +209,12 @@ zrequire('marked', 'third/marked/lib/marked');
 | 
				
			|||||||
    stream_data.update_subscribers_count(sub);
 | 
					    stream_data.update_subscribers_count(sub);
 | 
				
			||||||
    assert.equal(sub.subscriber_count, 0);
 | 
					    assert.equal(sub.subscriber_count, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // verify that deactivating user should unsubscribe user from all streams
 | 
				
			||||||
 | 
					    assert(stream_data.add_subscriber('Rome', george.user_id));
 | 
				
			||||||
 | 
					    set_global('subs', { rerender_subscriptions_settings: function () {} });
 | 
				
			||||||
 | 
					    stream_data.remove_deactivated_user_from_all_streams(george.user_id);
 | 
				
			||||||
 | 
					    assert(!stream_data.is_user_subscribed('Rome', george.user_id));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // verify that checking subscription with undefined user id
 | 
					    // verify that checking subscription with undefined user id
 | 
				
			||||||
    global.blueslip.warn = function (msg) {
 | 
					    global.blueslip.warn = function (msg) {
 | 
				
			||||||
        assert.equal(msg, "Undefined user_id passed to function is_user_subscribed");
 | 
					        assert.equal(msg, "Undefined user_id passed to function is_user_subscribed");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -197,6 +197,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
 | 
				
			|||||||
            people.add_in_realm(event.person);
 | 
					            people.add_in_realm(event.person);
 | 
				
			||||||
        } else if (event.op === 'remove') {
 | 
					        } else if (event.op === 'remove') {
 | 
				
			||||||
            people.deactivate(event.person);
 | 
					            people.deactivate(event.person);
 | 
				
			||||||
 | 
					            stream_data.remove_deactivated_user_from_all_streams(event.person.user_id);
 | 
				
			||||||
        } else if (event.op === 'update') {
 | 
					        } else if (event.op === 'update') {
 | 
				
			||||||
            user_events.update_person(event.person);
 | 
					            user_events.update_person(event.person);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -349,6 +349,16 @@ exports.add_subscriber = function (stream_name, user_id) {
 | 
				
			|||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.remove_deactivated_user_from_all_streams = function (user_id) {
 | 
				
			||||||
 | 
					    (stream_info.values()).forEach(function (stream) {
 | 
				
			||||||
 | 
					        if (exports.is_user_subscribed(stream.name, user_id)) {
 | 
				
			||||||
 | 
					            exports.remove_subscriber(stream.name, user_id);
 | 
				
			||||||
 | 
					            var sub = exports.get_sub(stream.name);
 | 
				
			||||||
 | 
					            subs.rerender_subscriptions_settings(sub);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.remove_subscriber = function (stream_name, user_id) {
 | 
					exports.remove_subscriber = function (stream_name, user_id) {
 | 
				
			||||||
    var sub = exports.get_sub(stream_name);
 | 
					    var sub = exports.get_sub(stream_name);
 | 
				
			||||||
    if (typeof sub === 'undefined') {
 | 
					    if (typeof sub === 'undefined') {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user