Browse Source

Apprise Notifications are now a controlled via settings

pull/272/head
Chris Caron 5 years ago
parent
commit
b5a03369b6
7 changed files with 33 additions and 4 deletions
  1. +11
    -1
      hc/api/transports.py
  2. +9
    -1
      hc/front/tests/test_add_apprise.py
  3. +5
    -0
      hc/front/views.py
  4. +3
    -0
      hc/settings.py
  5. +0
    -1
      requirements.txt
  6. +2
    -0
      templates/front/channels.html
  7. +3
    -1
      templates/front/welcome.html

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

@ -3,12 +3,17 @@ from django.template.loader import render_to_string
from django.utils import timezone
import json
import requests
import apprise
from urllib.parse import quote, urlencode
from hc.accounts.models import Profile
from hc.lib import emails
try:
import apprise
except ImportError:
# Enforce
settings.APPRISE_ENABLED = False
def tmpl(template_name, **ctx):
template_path = "integrations/%s" % template_name
@ -465,6 +470,11 @@ class Trello(HttpTransport):
class Apprise(HttpTransport):
def notify(self, check):
if not settings.APPRISE_ENABLED:
# Not supported and/or enabled
return "Apprise is disabled and/or not installed."
a = apprise.Apprise()
title = tmpl("apprise_title.html", check=check)
body = tmpl("apprise_description.html", check=check)


+ 9
- 1
hc/front/tests/test_add_apprise.py View File

@ -1,8 +1,10 @@
from hc.api.models import Channel
from hc.test import BaseTestCase
from django.test.utils import override_settings
class AddSlackTestCase(BaseTestCase):
@override_settings(APPRISE_ENABLED=True)
class AddAppriseTestCase(BaseTestCase):
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get("/integrations/add_apprise/")
@ -19,3 +21,9 @@ class AddSlackTestCase(BaseTestCase):
self.assertEqual(c.kind, "apprise")
self.assertEqual(c.value, "json://example.org")
self.assertEqual(c.project, self.project)
@override_settings(APPRISE_ENABLED=False)
def test_it_requires_client_id(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get("/integrations/add_apprise/")
self.assertEqual(r.status_code, 404)

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

@ -237,6 +237,7 @@ def index(request):
"enable_pd": settings.PD_VENDOR_KEY is not None,
"enable_trello": settings.TRELLO_APP_KEY is not None,
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
"enable_apprise": settings.APPRISE_ENABLED is True,
"registration_open": settings.REGISTRATION_OPEN,
}
@ -611,6 +612,7 @@ def channels(request):
"enable_pd": settings.PD_VENDOR_KEY is not None,
"enable_trello": settings.TRELLO_APP_KEY is not None,
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
"enable_apprise": settings.APPRISE_ENABLED is True,
"use_payments": settings.USE_PAYMENTS,
}
@ -1328,6 +1330,9 @@ def add_matrix(request):
@login_required
def add_apprise(request):
if not settings.APPRISE_ENABLED:
raise Http404("apprise integration is not available")
if request.method == "POST":
form = AddAppriseForm(request.POST)
if form.is_valid():


+ 3
- 0
hc/settings.py View File

@ -204,6 +204,9 @@ MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
# Apprise
APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
from .local_settings import *


+ 0
- 1
requirements.txt View File

@ -4,4 +4,3 @@ django_compressor==2.2
psycopg2==2.7.5
pytz==2019.1
requests==2.22.0
apprise==0.7.9

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

@ -213,6 +213,7 @@
<a href="{% url 'hc-add-webhook' %}" class="btn btn-primary">Add Integration</a>
</li>
{% if enable_apprise %}
<li>
<img src="{% static 'img/integrations/apprise.png' %}"
class="icon" alt="Pushover icon" />
@ -222,6 +223,7 @@
<a href="{% url 'hc-add-apprise' %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}
{% if enable_pushover %}
<li>
<img src="{% static 'img/integrations/po.png' %}"


+ 3
- 1
templates/front/welcome.html View File

@ -432,12 +432,14 @@
</div>
</div>
{% endif %}
{% if enable_apprise %}
<div class="col-md-2 col-sm-4 col-xs-6">
<div class="integration">
<img src="{% static 'img/integrations/apprise.png' %}" class="icon" alt="Apprise icon" />
<h3>WhatsApp<br><small>Chat</small></h3>
<h3>Apprise<br><small>>Push Notifications</small></h3>
</div>
</div>
{% endif %}
</div>
<div class="row tour-section">


Loading…
Cancel
Save