From 5bdb01baf91e2063a309a826506dfc5db5842bf4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C4=93teris=20Caune?= <cuu508@gmail.com>
Date: Fri, 12 Apr 2024 15:43:06 +0300
Subject: [PATCH] Fix the Zulip integration to use Flip.new_status

---
 hc/api/tests/test_notify_zulip.py         | 4 +++-
 hc/api/transports.py                      | 7 ++++---
 templates/integrations/zulip_content.html | 2 +-
 templates/integrations/zulip_topic.html   | 2 +-
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/hc/api/tests/test_notify_zulip.py b/hc/api/tests/test_notify_zulip.py
index 614bee24..8444caed 100644
--- a/hc/api/tests/test_notify_zulip.py
+++ b/hc/api/tests/test_notify_zulip.py
@@ -19,7 +19,9 @@ class NotifyZulipTestCase(BaseTestCase):
 
         self.check = Check(project=self.project)
         self.check.name = "Foobar"
-        self.check.status = "down"
+        # Transport classes should use flip.new_status,
+        # so the status "paused" should not appear anywhere
+        self.check.status = "paused"
         self.check.last_ping = now() - td(minutes=61)
         self.check.save()
 
diff --git a/hc/api/transports.py b/hc/api/transports.py
index f148a07b..5d6bfa7c 100644
--- a/hc/api/transports.py
+++ b/hc/api/transports.py
@@ -1197,21 +1197,22 @@ class Zulip(HttpTransport):
 
         raise TransportError(message)
 
-    def notify(self, check: Check, notification: Notification) -> None:
+    def notify_flip(self, flip: Flip, notification: Notification) -> None:
         if not settings.ZULIP_ENABLED:
             raise TransportError("Zulip notifications are not enabled.")
 
         topic = self.channel.zulip.topic
         if not topic:
-            topic = tmpl("zulip_topic.html", check=check)
+            topic = tmpl("zulip_topic.html", check=flip.owner, status=flip.new_status)
 
         url = self.channel.zulip.site + "/api/v1/messages"
         auth = (self.channel.zulip.bot_email, self.channel.zulip.api_key)
+        content = tmpl("zulip_content.html", check=flip.owner, status=flip.new_status)
         data = {
             "type": self.channel.zulip.mtype,
             "to": self.channel.zulip.to,
             "topic": topic,
-            "content": tmpl("zulip_content.html", check=check),
+            "content": content,
         }
 
         self.post(url, data=data, auth=auth)
diff --git a/templates/integrations/zulip_content.html b/templates/integrations/zulip_content.html
index 387561bc..1d53c076 100644
--- a/templates/integrations/zulip_content.html
+++ b/templates/integrations/zulip_content.html
@@ -1,6 +1,6 @@
 {% load hc_extras humanize %}
 
-[{{ check.name_then_code }}]({{ check.cloaked_url }}) is **{{ check.status|upper }}**. {% if check.status == "down" and check.last_ping %}Last ping was {{ check.last_ping|naturaltime }}.{% endif %}
+[{{ check.name_then_code }}]({{ check.cloaked_url }}) is **{{ status|upper }}**. {% if status == "down" and check.last_ping %}Last ping was {{ check.last_ping|naturaltime }}.{% endif %}
 
 {% if check.desc %}
 ---
diff --git a/templates/integrations/zulip_topic.html b/templates/integrations/zulip_topic.html
index eb298b98..002e0f4b 100644
--- a/templates/integrations/zulip_topic.html
+++ b/templates/integrations/zulip_topic.html
@@ -1 +1 @@
-{{ check.name_then_code|safe }} is {{ check.status|upper }}
+{{ check.name_then_code|safe }} is {{ status|upper }}