mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 14:38:46 +00:00
events: Add assertions that all ops are implemented.
We discovered recently that some ops for events were just not implemented in events.py (specifically, realm/deactivated). Since our goal is for events.py to be complete, we add this bit of hardening to ensure that it stays that way.
This commit is contained in:
@@ -625,23 +625,21 @@ def apply_event(
|
|||||||
p["profile_data"][str(custom_field_id)] = {
|
p["profile_data"][str(custom_field_id)] = {
|
||||||
"value": custom_field_new_value,
|
"value": custom_field_new_value,
|
||||||
}
|
}
|
||||||
|
else:
|
||||||
|
raise AssertionError("Unexpected event type {type}/{op}".format(**event))
|
||||||
elif event["type"] == "realm_bot":
|
elif event["type"] == "realm_bot":
|
||||||
if event["op"] == "add":
|
if event["op"] == "add":
|
||||||
state["realm_bots"].append(event["bot"])
|
state["realm_bots"].append(event["bot"])
|
||||||
|
elif event["op"] == "remove":
|
||||||
if event["op"] == "remove":
|
|
||||||
user_id = event["bot"]["user_id"]
|
user_id = event["bot"]["user_id"]
|
||||||
for bot in state["realm_bots"]:
|
for bot in state["realm_bots"]:
|
||||||
if bot["user_id"] == user_id:
|
if bot["user_id"] == user_id:
|
||||||
bot["is_active"] = False
|
bot["is_active"] = False
|
||||||
|
elif event["op"] == "delete":
|
||||||
if event["op"] == "delete":
|
|
||||||
state["realm_bots"] = [
|
state["realm_bots"] = [
|
||||||
item for item in state["realm_bots"] if item["user_id"] != event["bot"]["user_id"]
|
item for item in state["realm_bots"] if item["user_id"] != event["bot"]["user_id"]
|
||||||
]
|
]
|
||||||
|
elif event["op"] == "update":
|
||||||
if event["op"] == "update":
|
|
||||||
for bot in state["realm_bots"]:
|
for bot in state["realm_bots"]:
|
||||||
if bot["user_id"] == event["bot"]["user_id"]:
|
if bot["user_id"] == event["bot"]["user_id"]:
|
||||||
if "owner_id" in event["bot"]:
|
if "owner_id" in event["bot"]:
|
||||||
@@ -649,7 +647,8 @@ def apply_event(
|
|||||||
bot["owner_id"] = bot_owner_id
|
bot["owner_id"] = bot_owner_id
|
||||||
else:
|
else:
|
||||||
bot.update(event["bot"])
|
bot.update(event["bot"])
|
||||||
|
else:
|
||||||
|
raise AssertionError("Unexpected event type {type}/{op}".format(**event))
|
||||||
elif event["type"] == "stream":
|
elif event["type"] == "stream":
|
||||||
if event["op"] == "create":
|
if event["op"] == "create":
|
||||||
for stream in event["streams"]:
|
for stream in event["streams"]:
|
||||||
@@ -743,6 +742,8 @@ def apply_event(
|
|||||||
if key == "authentication_methods":
|
if key == "authentication_methods":
|
||||||
state["realm_password_auth_enabled"] = value["Email"] or value["LDAP"]
|
state["realm_password_auth_enabled"] = value["Email"] or value["LDAP"]
|
||||||
state["realm_email_auth_enabled"] = value["Email"]
|
state["realm_email_auth_enabled"] = value["Email"]
|
||||||
|
else:
|
||||||
|
raise AssertionError("Unexpected event type {type}/{op}".format(**event))
|
||||||
elif event["type"] == "subscription":
|
elif event["type"] == "subscription":
|
||||||
if event["op"] == "add":
|
if event["op"] == "add":
|
||||||
added_stream_ids = {sub["stream_id"] for sub in event["subscriptions"]}
|
added_stream_ids = {sub["stream_id"] for sub in event["subscriptions"]}
|
||||||
@@ -813,6 +814,8 @@ def apply_event(
|
|||||||
if sub["stream_id"] in stream_ids:
|
if sub["stream_id"] in stream_ids:
|
||||||
subscribers = set(sub["subscribers"]) - user_ids
|
subscribers = set(sub["subscribers"]) - user_ids
|
||||||
sub["subscribers"] = sorted(list(subscribers))
|
sub["subscribers"] = sorted(list(subscribers))
|
||||||
|
else:
|
||||||
|
raise AssertionError("Unexpected event type {type}/{op}".format(**event))
|
||||||
elif event["type"] == "presence":
|
elif event["type"] == "presence":
|
||||||
if slim_presence:
|
if slim_presence:
|
||||||
user_key = str(event["user_id"])
|
user_key = str(event["user_id"])
|
||||||
@@ -923,6 +926,8 @@ def apply_event(
|
|||||||
for realm_domain in state["realm_domains"]
|
for realm_domain in state["realm_domains"]
|
||||||
if realm_domain["domain"] != event["domain"]
|
if realm_domain["domain"] != event["domain"]
|
||||||
]
|
]
|
||||||
|
else:
|
||||||
|
raise AssertionError("Unexpected event type {type}/{op}".format(**event))
|
||||||
elif event["type"] == "realm_emoji":
|
elif event["type"] == "realm_emoji":
|
||||||
state["realm_emoji"] = event["realm_emoji"]
|
state["realm_emoji"] = event["realm_emoji"]
|
||||||
elif event["type"] == "realm_export":
|
elif event["type"] == "realm_export":
|
||||||
@@ -966,6 +971,8 @@ def apply_event(
|
|||||||
state["realm_user_groups"] = [
|
state["realm_user_groups"] = [
|
||||||
ug for ug in state["realm_user_groups"] if ug["id"] != event["group_id"]
|
ug for ug in state["realm_user_groups"] if ug["id"] != event["group_id"]
|
||||||
]
|
]
|
||||||
|
else:
|
||||||
|
raise AssertionError("Unexpected event type {type}/{op}".format(**event))
|
||||||
elif event["type"] == "user_status":
|
elif event["type"] == "user_status":
|
||||||
user_id_str = str(event["user_id"])
|
user_id_str = str(event["user_id"])
|
||||||
user_status = state["user_status"]
|
user_status = state["user_status"]
|
||||||
|
|||||||
Reference in New Issue
Block a user