diff --git a/CHANGELOG.md b/CHANGELOG.md index 112caea3..9c6a0cfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Added an example of capturing and submitting log output (#315) - The sendalerts commands measures dwell time and reports it over statsd protocol - Django 3.0.3 +- Show a warning in top navigation if the project has no integrations (#327) ### Bug Fixes - Increase the allowable length of Matrix room alias to 100 (#320) diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 1eb5f8a5..ab0793e3 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -282,8 +282,15 @@ class Project(models.Model): break return status - def have_broken_channels(self): - return self.channel_set.exclude(last_error="").exists() + def have_channel_issues(self): + errors = list(self.channel_set.values_list("last_error", flat=True)) + + # It's a problem if a project has no integrations at all + if len(errors) == 0: + return True + + # It's a problem if any integration has a logged error + return True if max(errors) else False class Member(models.Model): diff --git a/hc/accounts/tests/test_project_model.py b/hc/accounts/tests/test_project_model.py index 46862c58..c7623aa9 100644 --- a/hc/accounts/tests/test_project_model.py +++ b/hc/accounts/tests/test_project_model.py @@ -15,9 +15,15 @@ class ProjectModelTestCase(BaseTestCase): self.assertEqual(self.project.num_checks_available(), 18) def test_it_handles_zero_broken_channels(self): - self.assertFalse(self.project.have_broken_channels()) + Channel.objects.create(kind="webhook", last_error="", project=self.project) + + self.assertFalse(self.project.have_channel_issues()) def test_it_handles_one_broken_channel(self): Channel.objects.create(kind="webhook", last_error="x", project=self.project) - self.assertTrue(self.project.have_broken_channels()) + self.assertTrue(self.project.have_channel_issues()) + + def test_it_handles_no_channels(self): + # It's an issue if the project has no channels at all: + self.assertTrue(self.project.have_channel_issues()) diff --git a/hc/front/tests/test_channels.py b/hc/front/tests/test_channels.py index 50bead97..08ddf903 100644 --- a/hc/front/tests/test_channels.py +++ b/hc/front/tests/test_channels.py @@ -126,7 +126,7 @@ class ChannelsTestCase(BaseTestCase): r = self.client.get("/integrations/") self.assertRedirects(r, "/") - def test_it_shows_broken_channel_indicator(self): + def test_it_shows_channel_issues_indicator(self): Channel.objects.create(kind="sms", project=self.project, last_error="x") self.client.login(username="alice@example.org", password="password") diff --git a/templates/base.html b/templates/base.html index 4d372f3d..1b2df4c2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -97,7 +97,7 @@ Checks - {% with b=project.have_broken_channels %} + {% with b=project.have_channel_issues %}
  • Integrations diff --git a/templates/front/channels.html b/templates/front/channels.html index 0fd5bfb9..04164260 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -150,8 +150,14 @@ {% endfor %} {% else %} -
    - The project {{ project }} has no integrations set up yet. +
    +

    The project "{{ project }}" does not have any integrations + set up yet. +

    +

    With no configured integrations, {% site_name %} + will not send any notifications + when checks change state. +

    {% endif %}