Browse Source

Add the MATTERMOST_ENABLED setting

pull/474/head
Pēteris Caune 4 years ago
parent
commit
6c3debaf11
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
11 changed files with 64 additions and 2 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -0
      docker/.env
  3. +31
    -0
      hc/api/tests/test_notify_mattermost.py
  4. +4
    -1
      hc/api/transports.py
  5. +7
    -0
      hc/front/tests/test_add_mattermost.py
  6. +3
    -0
      hc/front/views.py
  7. +3
    -0
      hc/settings.py
  8. +4
    -1
      templates/docs/self_hosted_configuration.html
  9. +6
    -0
      templates/docs/self_hosted_configuration.md
  10. +2
    -0
      templates/front/channels.html
  11. +2
    -0
      templates/front/welcome.html

+ 1
- 0
CHANGELOG.md View File

@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- Add rate limiting for Pushover notifications (6 notifications / user / minute)
- Add the WEBHOOKS_ENABLED setting (#471)
- Add the SLACK_ENABLED setting (#471)
- Add the MATTERMOST_ENABLED setting (#471)
## Bug Fixes
- Fix unwanted HTML escaping in SMS and WhatsApp notifications


+ 1
- 0
docker/.env View File

@ -25,6 +25,7 @@ MASTER_BADGE_LABEL=Mychecks
MATRIX_ACCESS_TOKEN=
MATRIX_HOMESERVER=
MATRIX_USER_ID=
MATTERMOST_ENABLED=True
PD_VENDOR_KEY=
PING_BODY_LIMIT=10000
PING_EMAIL_DOMAIN=localhost


+ 31
- 0
hc/api/tests/test_notify_mattermost.py View File

@ -0,0 +1,31 @@
# coding: utf-8
from datetime import timedelta as td
from django.utils.timezone import now
from hc.api.models import Channel, Check, Notification
from hc.test import BaseTestCase
from django.test.utils import override_settings
class NotifyTestCase(BaseTestCase):
def _setup_data(self, value, status="down", email_verified=True):
self.check = Check(project=self.project)
self.check.status = status
self.check.last_ping = now() - td(minutes=61)
self.check.save()
self.channel = Channel(project=self.project)
self.channel.kind = "mattermost"
self.channel.value = value
self.channel.email_verified = email_verified
self.channel.save()
self.channel.checks.add(self.check)
@override_settings(MATTERMOST_ENABLED=False)
def test_it_requires_mattermost_enabled(self):
self._setup_data("123")
self.channel.notify(self.check)
n = Notification.objects.get()
self.assertEqual(n.error, "Mattermost notifications are not enabled.")

+ 4
- 1
hc/api/transports.py View File

@ -263,9 +263,12 @@ class Webhook(HttpTransport):
class Slack(HttpTransport):
def notify(self, check):
if not settings.SLACK_ENABLED:
if self.channel.kind == "slack" and not settings.SLACK_ENABLED:
return "Slack notifications are not enabled."
if self.channel.kind == "mattermost" and not settings.MATTERMOST_ENABLED:
return "Mattermost notifications are not enabled."
text = tmpl("slack_message.json", check=check)
payload = json.loads(text)
return self.post(self.channel.slack_webhook_url, json=payload)


+ 7
- 0
hc/front/tests/test_add_mattermost.py View File

@ -1,3 +1,4 @@
from django.test.utils import override_settings
from hc.api.models import Channel
from hc.test import BaseTestCase
@ -31,3 +32,9 @@ class AddMattermostTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 403)
@override_settings(MATTERMOST_ENABLED=False)
def test_it_handles_disabled_integration(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 404)

+ 3
- 0
hc/front/views.py View File

@ -295,6 +295,7 @@ def index(request):
"enable_discord": settings.DISCORD_CLIENT_ID is not None,
"enable_linenotify": settings.LINENOTIFY_CLIENT_ID is not None,
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
"enable_pdc": settings.PD_VENDOR_KEY is not None,
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
@ -763,6 +764,7 @@ def channels(request, code):
"enable_discord": settings.DISCORD_CLIENT_ID is not None,
"enable_linenotify": settings.LINENOTIFY_CLIENT_ID is not None,
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
"enable_pdc": settings.PD_VENDOR_KEY is not None,
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
@ -1210,6 +1212,7 @@ def add_slack_complete(request):
return redirect("hc-channels", project.code)
@require_setting("MATTERMOST_ENABLED")
@login_required
def add_mattermost(request, code):
project = _get_rw_project_for_user(request, code)


+ 3
- 0
hc/settings.py View File

@ -199,6 +199,9 @@ MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
# Mattermost
MATTERMOST_ENABLED = envbool("MATTERMOST_ENABLED", "True")
# PagerDuty
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")


+ 4
- 1
templates/docs/self_hosted_configuration.html View File

@ -140,6 +140,9 @@ integration.</p>
<h2 id="MATRIX_USER_ID"><code>MATRIX_USER_ID</code></h2>
<p>Default: <code>None</code></p>
<p>The Matrix bot's user identifier, required by the Matrix integration.</p>
<h2 id="MATTERMOST_ENABLED"><code>MATTERMOST_ENABLED</code></h2>
<p>Default: <code>True</code></p>
<p>A boolean that turns on/off the Mattermost integration. Enabled by default.</p>
<h2 id="PD_VENDOR_KEY"><code>PD_VENDOR_KEY</code></h2>
<p>Default: <code>None</code></p>
<p><a href="https://www.pagerduty.com/">PagerDuty</a> vendor key,
@ -284,7 +287,7 @@ and create a <em>Slack app</em>. When setting up the Slack app, make sure to:</p
</ul>
<h2 id="SLACK_CLIENT_SECRET"><code>SLACK_CLIENT_SECRET</code></h2>
<p>Default: <code>None</code></p>
<p>The Slack Client Secret, required if <code>SLACK_CLIENT_ID</code> is set.
<p>The Slack Client Secret. Required if <code>SLACK_CLIENT_ID</code> is set.
Look it up at <a href="https://api.slack.com/apps/">https://api.slack.com/apps/</a>.</p>
<h2 id="SLACK_ENABLED"><code>SLACK_ENABLED</code></h2>
<p>Default: <code>True</code></p>


+ 6
- 0
templates/docs/self_hosted_configuration.md View File

@ -230,6 +230,12 @@ Default: `None`
The Matrix bot's user identifier, required by the Matrix integration.
## `MATTERMOST_ENABLED` {: #MATTERMOST_ENABLED }
Default: `True`
A boolean that turns on/off the Mattermost integration. Enabled by default.
## `PD_VENDOR_KEY` {: #PD_VENDOR_KEY }
Default: `None`


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

@ -265,6 +265,7 @@
</li>
{% endif %}
{% if enable_mattermost %}
<li>
<img src="{% static 'img/integrations/mattermost.png' %}"
class="icon" alt="Mattermost icon" />
@ -273,6 +274,7 @@
<p>High Trust Messaging for the Enterprise.</p>
<a href="{% url 'hc-add-mattermost' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}
<li>
<img src="{% static 'img/integrations/msteams.png' %}"


+ 2
- 0
templates/front/welcome.html View File

@ -460,6 +460,7 @@
</div>
{% endif %}
{% if enable_mattermost %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<div class="integration">
<img src="{% static 'img/integrations/mattermost.png' %}" class="icon" alt="" />
@ -469,6 +470,7 @@
</h3>
</div>
</div>
{% endif %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<div class="integration">


Loading…
Cancel
Save