mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	users: Send "update" events when deactivating or reactivating users.
We now send "realm_user/update" (and "realm_bot/update" for bots) events with "is_active" field when deactivating and reactivating users, including bots. We would want to use "remove" event for a user losing access to another user for #10970, so it is better to use "update" event for deactivation as we only update "is_active" field in the user objects and the clients still have the data for deactivated users. Previously, we used to send "add" event for reactivation along with complete user objects, but clients should have the data for deactivated users as well, so an "update" event is enough like we do when deactivating users.
This commit is contained in:
		@@ -865,13 +865,6 @@ def apply_event(
 | 
			
		||||
            if not person["is_bot"]:
 | 
			
		||||
                person["profile_data"] = {}
 | 
			
		||||
            state["raw_users"][person_user_id] = person
 | 
			
		||||
        elif event["op"] == "remove":
 | 
			
		||||
            state["raw_users"][person_user_id]["is_active"] = False
 | 
			
		||||
            if include_subscribers:
 | 
			
		||||
                for sub in state["subscriptions"]:
 | 
			
		||||
                    sub["subscribers"] = [
 | 
			
		||||
                        user_id for user_id in sub["subscribers"] if user_id != person_user_id
 | 
			
		||||
                    ]
 | 
			
		||||
        elif event["op"] == "update":
 | 
			
		||||
            is_me = person_user_id == user_profile.id
 | 
			
		||||
 | 
			
		||||
@@ -980,16 +973,17 @@ def apply_event(
 | 
			
		||||
 | 
			
		||||
                if "new_email" in person:
 | 
			
		||||
                    p["email"] = person["new_email"]
 | 
			
		||||
 | 
			
		||||
                if "is_active" in person and not person["is_active"] and include_subscribers:
 | 
			
		||||
                    for sub in state["subscriptions"]:
 | 
			
		||||
                        sub["subscribers"] = [
 | 
			
		||||
                            user_id for user_id in sub["subscribers"] if user_id != person_user_id
 | 
			
		||||
                        ]
 | 
			
		||||
        else:
 | 
			
		||||
            raise AssertionError("Unexpected event type {type}/{op}".format(**event))
 | 
			
		||||
    elif event["type"] == "realm_bot":
 | 
			
		||||
        if event["op"] == "add":
 | 
			
		||||
            state["realm_bots"].append(event["bot"])
 | 
			
		||||
        elif event["op"] == "remove":
 | 
			
		||||
            user_id = event["bot"]["user_id"]
 | 
			
		||||
            for bot in state["realm_bots"]:
 | 
			
		||||
                if bot["user_id"] == user_id:
 | 
			
		||||
                    bot["is_active"] = False
 | 
			
		||||
        elif event["op"] == "delete":
 | 
			
		||||
            state["realm_bots"] = [
 | 
			
		||||
                item for item in state["realm_bots"] if item["user_id"] != event["bot"]["user_id"]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user