Browse Source

Show a warning in project's top navigation if the project has no configured integrations. Fixes #327

pull/340/head
Pēteris Caune 5 years ago
parent
commit
15b9611c5a
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 28 additions and 8 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +9
    -2
      hc/accounts/models.py
  3. +8
    -2
      hc/accounts/tests/test_project_model.py
  4. +1
    -1
      hc/front/tests/test_channels.py
  5. +1
    -1
      templates/base.html
  6. +8
    -2
      templates/front/channels.html

+ 1
- 0
CHANGELOG.md View File

@ -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)


+ 9
- 2
hc/accounts/models.py View File

@ -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):


+ 8
- 2
hc/accounts/tests/test_project_model.py View File

@ -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())

+ 1
- 1
hc/front/tests/test_channels.py View File

@ -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="[email protected]", password="password")


+ 1
- 1
templates/base.html View File

@ -97,7 +97,7 @@
<a href="{% url 'hc-checks' project.code %}">Checks</a>
</li>
{% with b=project.have_broken_channels %}
{% with b=project.have_channel_issues %}
<li {% if b %}id="broken-channels"{% endif %} {% if page == 'channels' %}class="active"{% endif %}>
<a href="{% url 'hc-channels' %}">
Integrations


+ 8
- 2
templates/front/channels.html View File

@ -150,8 +150,14 @@
{% endfor %}
</table>
{% else %}
<div class="alert alert-info">
The project <strong>{{ project }}</strong> has no integrations set up yet.
<div class="alert alert-danger">
<p> The project "{{ project }}" does not have any integrations
set up yet.
</p>
<p>With no configured integrations, {% site_name %}
<strong>will not send any notifications</strong>
when checks change state.
</p>
</div>
{% endif %}


Loading…
Cancel
Save