diff --git a/hc/front/tests/test_add_telegram.py b/hc/front/tests/test_add_telegram.py index bd299668..a4d3354a 100644 --- a/hc/front/tests/test_add_telegram.py +++ b/hc/front/tests/test_add_telegram.py @@ -1,9 +1,11 @@ from django.core import signing +from django.test.utils import override_settings from hc.api.models import Channel from hc.test import BaseTestCase from mock import patch +@override_settings(TELEGRAM_TOKEN="fake-token") class AddTelegramTestCase(BaseTestCase): url = "/integrations/add_telegram/" @@ -12,6 +14,14 @@ class AddTelegramTestCase(BaseTestCase): r = self.client.get(self.url) self.assertContains(r, "start@ExampleBot") + @override_settings(TELEGRAM_TOKEN=None) + def test_it_requires_token(self): + payload = signing.dumps((123, "group", "My Group")) + + self.client.login(username="alice@example.org", password="password") + r = self.client.get(self.url + "?" + payload) + self.assertEqual(r.status_code, 404) + def test_it_shows_confirmation(self): payload = signing.dumps((123, "group", "My Group")) diff --git a/hc/front/urls.py b/hc/front/urls.py index 4ade6bf9..43d45056 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -29,11 +29,11 @@ channel_urls = [ name="hc-add-pushbullet-complete", ), path("add_discord/", views.add_discord_complete, name="hc-add-discord-complete"), - path("add_pushover/", views.add_pushover_help), - path("telegram/", views.add_telegram_help), + path("add_pushover/", views.pushover_help, name="hc-pushover-help"), + path("telegram/", views.telegram_help, name="hc-telegram-help"), path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"), - path("add_pdc/", views.add_pdc_help), - path("add_slack/", views.add_slack_help), + path("add_pdc/", views.pdc_help, name="hc-pdc-help"), + path("add_slack/", views.slack_help, name="hc-slack-help"), path("add_slack_btn/", views.add_slack_complete), path("add_telegram/", views.add_telegram, name="hc-add-telegram"), path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"), diff --git a/hc/front/views.py b/hc/front/views.py index e399326b..8ac918a0 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -271,16 +271,18 @@ def index(request): "page": "welcome", "check": check, "ping_url": check.url(), + "enable_apprise": settings.APPRISE_ENABLED is True, + "enable_discord": settings.DISCORD_CLIENT_ID is not None, + "enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None, + "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, - "enable_discord": settings.DISCORD_CLIENT_ID is not None, - "enable_telegram": settings.TELEGRAM_TOKEN is not None, + "enable_shell": settings.SHELL_ENABLED is True, + "enable_slack_btn": settings.SLACK_CLIENT_ID is not None, "enable_sms": settings.TWILIO_AUTH is not None, - "enable_whatsapp": settings.TWILIO_USE_WHATSAPP, + "enable_telegram": settings.TELEGRAM_TOKEN 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, - "enable_shell": settings.SHELL_ENABLED is True, + "enable_whatsapp": settings.TWILIO_USE_WHATSAPP, "registration_open": settings.REGISTRATION_OPEN, } @@ -683,18 +685,18 @@ def channels(request, code): "project": project, "profile": project.owner_profile, "channels": channels, - "enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None, - "enable_pushover": settings.PUSHOVER_API_TOKEN is not None, + "enable_apprise": settings.APPRISE_ENABLED is True, "enable_discord": settings.DISCORD_CLIENT_ID is not None, - "enable_telegram": settings.TELEGRAM_TOKEN is not None, - "enable_sms": settings.TWILIO_AUTH is not None, - "enable_whatsapp": settings.TWILIO_USE_WHATSAPP, - "enable_pdc": 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, + "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, "enable_shell": settings.SHELL_ENABLED is True, "enable_slack_btn": settings.SLACK_CLIENT_ID is not None, + "enable_sms": settings.TWILIO_AUTH is not None, + "enable_telegram": settings.TELEGRAM_TOKEN is not None, + "enable_trello": settings.TRELLO_APP_KEY is not None, + "enable_whatsapp": settings.TWILIO_USE_WHATSAPP, "use_payments": settings.USE_PAYMENTS, } @@ -925,7 +927,7 @@ def add_pd(request, code): @require_setting("PD_VENDOR_KEY") -def add_pdc_help(request): +def pdc_help(request): ctx = {"page": "channels"} return render(request, "integrations/add_pdc.html", ctx) @@ -1042,7 +1044,7 @@ def add_slack(request, code): @require_setting("SLACK_CLIENT_ID") -def add_slack_help(request): +def slack_help(request): ctx = {"page": "channels"} return render(request, "integrations/add_slack_btn.html", ctx) @@ -1258,7 +1260,7 @@ def add_discord_complete(request): @require_setting("PUSHOVER_API_TOKEN") -def add_pushover_help(request): +def pushover_help(request): ctx = {"page": "channels"} return render(request, "integrations/add_pushover_help.html", ctx) @@ -1398,7 +1400,8 @@ def telegram_bot(request): return HttpResponse() -def add_telegram_help(request): +@require_setting("TELEGRAM_TOKEN") +def telegram_help(request): ctx = { "page": "channels", "bot_name": settings.TELEGRAM_BOT_NAME, @@ -1407,6 +1410,7 @@ def add_telegram_help(request): return render(request, "integrations/add_telegram.html", ctx) +@require_setting("TELEGRAM_TOKEN") @login_required def add_telegram(request): chat_id, chat_type, chat_name = None, None, None diff --git a/static/css/welcome.css b/static/css/welcome.css index e4832a5f..c9f439a9 100644 --- a/static/css/welcome.css +++ b/static/css/welcome.css @@ -72,11 +72,19 @@ } #welcome-integrations .integration { + display: block; + color: #333; border: 1px solid #ddd; border-radius: 3px; padding: 20px 0; text-align: center; margin-bottom: 30px; + text-decoration: none; +} + +#welcome-integrations a.integration:hover { + border-color: #0091EA; + text-decoration: none; } #welcome-integrations img { diff --git a/templates/base.html b/templates/base.html index fee98e81..29d36080 100644 --- a/templates/base.html +++ b/templates/base.html @@ -67,7 +67,7 @@ - + {% if request.user.is_authenticated and project %} {{ project }} diff --git a/templates/front/welcome.html b/templates/front/welcome.html index 56771463..03ad90ad 100644 --- a/templates/front/welcome.html +++ b/templates/front/welcome.html @@ -329,10 +329,17 @@
+ {% if enable_slack_btn %} + + +

Slack
Chat

+
+ {% else %}

Slack
Chat

+ {% endif %}
{% if enable_apprise %} @@ -384,10 +391,17 @@
+ {% if enable_pdc %} + + +

PagerDuty
Incident Management

+
+ {% else %}

PagerDuty
Incident Management

+ {% endif %}
@@ -422,10 +436,10 @@ {% if enable_pushover %}
- +
{% endif %} @@ -449,10 +463,10 @@ {% if enable_telegram %}
- +
{% endif %} diff --git a/templates/integrations/add_apprise.html b/templates/integrations/add_apprise.html index e079ccfa..75a91e7e 100644 --- a/templates/integrations/add_apprise.html +++ b/templates/integrations/add_apprise.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Apprise - {% site_name %}{% endblock %} +{% block title %}Apprise Integration for {% site_name %}{% endblock %} {% block content %}
diff --git a/templates/integrations/add_discord.html b/templates/integrations/add_discord.html index 67620e4b..9aa42de4 100644 --- a/templates/integrations/add_discord.html +++ b/templates/integrations/add_discord.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Discord - {% site_name %}{% endblock %} +{% block title %}Discord Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_matrix.html b/templates/integrations/add_matrix.html index 66f540c4..324aeb52 100644 --- a/templates/integrations/add_matrix.html +++ b/templates/integrations/add_matrix.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Matrix - {% site_name %}{% endblock %} +{% block title %}Matrix Integration for {% site_name %}{% endblock %} {% block content %}
diff --git a/templates/integrations/add_mattermost.html b/templates/integrations/add_mattermost.html index 133112bf..eff2a486 100644 --- a/templates/integrations/add_mattermost.html +++ b/templates/integrations/add_mattermost.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Mattermost - {% site_name %}{% endblock %} +{% block title %}Mattermost Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_msteams.html b/templates/integrations/add_msteams.html index fc78a5c9..3c814410 100644 --- a/templates/integrations/add_msteams.html +++ b/templates/integrations/add_msteams.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Microsoft Teams - {% site_name %}{% endblock %} +{% block title %}Microsoft Teams Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_opsgenie.html b/templates/integrations/add_opsgenie.html index 4a3b91a8..f0f83baa 100644 --- a/templates/integrations/add_opsgenie.html +++ b/templates/integrations/add_opsgenie.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add OpsGenie - {% site_name %}{% endblock %} +{% block title %}OpsGenie Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_pagerteam.html b/templates/integrations/add_pagerteam.html index d9b2e27b..ed313932 100644 --- a/templates/integrations/add_pagerteam.html +++ b/templates/integrations/add_pagerteam.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Pager Team - {% site_name %}{% endblock %} +{% block title %}Pager Team Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_pagertree.html b/templates/integrations/add_pagertree.html index 5732edbd..1a737a9b 100644 --- a/templates/integrations/add_pagertree.html +++ b/templates/integrations/add_pagertree.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add PagerTree - {% site_name %}{% endblock %} +{% block title %}PagerTree Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_pd.html b/templates/integrations/add_pd.html index 5daa8af7..ea4b8ba6 100644 --- a/templates/integrations/add_pd.html +++ b/templates/integrations/add_pd.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load compress humanize static hc_extras %} -{% block title %}Add PagerDuty - {% site_name %}{% endblock %} +{% block title %}PagerDuty Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_pdc.html b/templates/integrations/add_pdc.html index 24c4306e..25d3274a 100644 --- a/templates/integrations/add_pdc.html +++ b/templates/integrations/add_pdc.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add PagerDuty - {% site_name %}{% endblock %} +{% block title %}PagerDuty Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_prometheus.html b/templates/integrations/add_prometheus.html index c9f73d1e..502ba991 100644 --- a/templates/integrations/add_prometheus.html +++ b/templates/integrations/add_prometheus.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Prometheus - {% site_name %}{% endblock %} +{% block title %}Prometheus Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_pushbullet.html b/templates/integrations/add_pushbullet.html index 02069de4..98c96884 100644 --- a/templates/integrations/add_pushbullet.html +++ b/templates/integrations/add_pushbullet.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Pushbullet - {% site_name %}{% endblock %} +{% block title %}Pushbullet Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_slack.html b/templates/integrations/add_slack.html index 71a393ba..3fd6f2fb 100644 --- a/templates/integrations/add_slack.html +++ b/templates/integrations/add_slack.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add Slack - {% site_name %}{% endblock %} +{% block title %}Slack Integration for {% site_name %}{% endblock %} {% block content %}
diff --git a/templates/integrations/add_sms.html b/templates/integrations/add_sms.html index ebc18dcf..96067fd0 100644 --- a/templates/integrations/add_sms.html +++ b/templates/integrations/add_sms.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Notification Channels - {% site_name %}{% endblock %} +{% block title %}Add SMS Integration - {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_trello.html b/templates/integrations/add_trello.html index 521d8be1..96fdc96d 100644 --- a/templates/integrations/add_trello.html +++ b/templates/integrations/add_trello.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load compress humanize static hc_extras %} -{% block title %}Add Trello - {% site_name %}{% endblock %} +{% block title %}Trello Integration for {% site_name %}{% endblock %} {% block content %}
diff --git a/templates/integrations/add_victorops.html b/templates/integrations/add_victorops.html index 038081f5..aa4d34ed 100644 --- a/templates/integrations/add_victorops.html +++ b/templates/integrations/add_victorops.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Add VictorOps - {% site_name %}{% endblock %} +{% block title %}VictorOps Integration for {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_webhook.html b/templates/integrations/add_webhook.html index 5e9568c4..42f6050c 100644 --- a/templates/integrations/add_webhook.html +++ b/templates/integrations/add_webhook.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load compress humanize static hc_extras %} -{% block title %}Add Webhook - {% site_name %}{% endblock %} +{% block title %}Add Webhook Integration - {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/add_whatsapp.html b/templates/integrations/add_whatsapp.html index 58f8f11f..4a10a7a4 100644 --- a/templates/integrations/add_whatsapp.html +++ b/templates/integrations/add_whatsapp.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load humanize static hc_extras %} -{% block title %}Notification Channels - {% site_name %}{% endblock %} +{% block title %}Add WhatsApp Integration - {% site_name %}{% endblock %} {% block content %} diff --git a/templates/integrations/zendesk_description.html b/templates/integrations/zendesk_description.html deleted file mode 100644 index 7048304e..00000000 --- a/templates/integrations/zendesk_description.html +++ /dev/null @@ -1,8 +0,0 @@ -{% load humanize %} -{% if check.status == "down" %} - {{ check.name_then_code }} is down. - Last ping was {{ check.last_ping|naturaltime }}. - Details: {{ check.details_url }} -{% else %} - {{ check.name_then_code }} received a ping and is now UP -{% endif %} diff --git a/templates/integrations/zendesk_title.html b/templates/integrations/zendesk_title.html deleted file mode 100644 index 1bf6c0fb..00000000 --- a/templates/integrations/zendesk_title.html +++ /dev/null @@ -1,5 +0,0 @@ -{% if check.status == "down" %} - {{ check.name_then_code }} is down -{% else %} - {{ check.name_then_code }} is now UP -{% endif %}