From bd98174d4cabc0d57bbc7990d1d48dc2bd5741be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 4 Sep 2020 13:17:54 +0300 Subject: [PATCH] Fix missing Resume button. Fixes #421 --- CHANGELOG.md | 1 + hc/front/tests/test_status_single.py | 31 ++++++++++++++++++++++------ hc/front/views.py | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4cafbe5..a007d7d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Handle excessively long email addresses in the team member invite form - Don't allow duplicate team memberships - When copying a check, copy all fields from the "Filtering Rules" dialog (#417) +- Fix missing Resume button (#421) ## v1.16.0 - 2020-08-04 diff --git a/hc/front/tests/test_status_single.py b/hc/front/tests/test_status_single.py index 18ca23ac..851d98e2 100644 --- a/hc/front/tests/test_status_single.py +++ b/hc/front/tests/test_status_single.py @@ -8,9 +8,11 @@ class StatusSingleTestCase(BaseTestCase): self.check = Check(project=self.project, name="Alice Was Here") self.check.save() + self.url = "/checks/%s/status/" % self.check.code + def test_it_works(self): self.client.login(username="alice@example.org", password="password") - r = self.client.get("/checks/%s/status/" % self.check.code) + r = self.client.get(self.url) doc = r.json() self.assertEqual(doc["status"], "new") @@ -24,7 +26,7 @@ class StatusSingleTestCase(BaseTestCase): self.check.save() self.client.login(username="alice@example.org", password="password") - r = self.client.get("/checks/%s/status/" % self.check.code) + r = self.client.get(self.url) doc = r.json() self.assertEqual(doc["status"], "up") @@ -38,7 +40,7 @@ class StatusSingleTestCase(BaseTestCase): self.check.save() timestamp = str(p.created.timestamp()) - url = "/checks/%s/status/?u=%s" % (self.check.code, timestamp) + url = self.url + "?u=%s" % timestamp self.client.login(username="alice@example.org", password="password") r = self.client.get(url) @@ -48,7 +50,7 @@ class StatusSingleTestCase(BaseTestCase): def test_it_allows_cross_team_access(self): self.client.login(username="bob@example.org", password="password") - r = self.client.get("/checks/%s/status/" % self.check.code) + r = self.client.get(self.url) self.assertEqual(r.status_code, 200) def test_it_handles_manual_resume(self): @@ -57,8 +59,25 @@ class StatusSingleTestCase(BaseTestCase): self.check.save() self.client.login(username="alice@example.org", password="password") - r = self.client.get("/checks/%s/status/" % self.check.code) + r = self.client.get(self.url) + doc = r.json() + + self.assertEqual(doc["status"], "paused") + self.assertIn("will ignore pings until resumed", doc["status_text"]) + self.assertIn("resume-btn", doc["status_text"]) + + def test_resume_requires_rw_access(self): + self.bobs_membership.rw = False + self.bobs_membership.save() + + self.check.status = "paused" + self.check.manual_resume = True + self.check.save() + + self.client.login(username="bob@example.org", password="password") + r = self.client.get(self.url) doc = r.json() self.assertEqual(doc["status"], "paused") - self.assertTrue("will ignore pings until resumed" in doc["status_text"]) + self.assertIn("will ignore pings until resumed", doc["status_text"]) + self.assertNotIn("resume-btn", doc["status_text"]) diff --git a/hc/front/views.py b/hc/front/views.py index 1016f201..6d1350f3 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -653,7 +653,7 @@ def status_single(request, code): doc = { "status": status, - "status_text": STATUS_TEXT_TMPL.render({"check": check}), + "status_text": STATUS_TEXT_TMPL.render({"check": check, "rw": rw}), "title": down_title(check), "updated": updated, }