diff --git a/CHANGELOG.md b/CHANGELOG.md index d3b3eba4..913f48a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,8 @@ All notable changes to this project will be documented in this file. - Improve the handling of unknown email addresses in the Sign In form - Add support for "... is UP" SMS notifications - Add an option for weekly reports (in addition to monthly) -- Implement PagerDuty Simple Install Flow -- Implement dark mode (using prefers-color-scheme: dark) +- Implement PagerDuty Simple Install Flow, remove PD Connect +- Implement dark mode ## v1.20.0 - 2020-04-22 diff --git a/hc/front/tests/test_add_pdc.py b/hc/front/tests/test_add_pdc.py deleted file mode 100644 index 73de6cd7..00000000 --- a/hc/front/tests/test_add_pdc.py +++ /dev/null @@ -1,47 +0,0 @@ -from django.test.utils import override_settings -from hc.api.models import Channel -from hc.test import BaseTestCase - - -@override_settings(PD_VENDOR_KEY="foo") -class AddPdConnectTestCase(BaseTestCase): - def setUp(self): - super().setUp() - self.url = "/projects/%s/add_pdc/" % self.project.code - - def test_it_works(self): - session = self.client.session - session["pd"] = "1234567890AB" # 12 characters - session.save() - - self.client.login(username="alice@example.org", password="password") - url = self.url + "1234567890AB/?service_key=123" - r = self.client.get(url, follow=True) - self.assertRedirects(r, self.channels_url) - - c = Channel.objects.get() - self.assertEqual(c.kind, "pd") - self.assertEqual(c.pd_service_key, "123") - self.assertEqual(c.project, self.project) - - @override_settings(PD_VENDOR_KEY=None) - def test_it_requires_vendor_key(self): - self.client.login(username="alice@example.org", password="password") - - r = self.client.get(self.url) - self.assertEqual(r.status_code, 404) - - @override_settings(PD_ENABLED=False) - def test_it_requires_pd_enabled(self): - self.client.login(username="alice@example.org", password="password") - - r = self.client.get(self.url) - self.assertEqual(r.status_code, 404) - - def test_it_requires_rw_access(self): - self.bobs_membership.rw = False - self.bobs_membership.save() - - self.client.login(username="bob@example.org", password="password") - r = self.client.get(self.url) - self.assertEqual(r.status_code, 403) diff --git a/hc/front/tests/test_add_pdc_complete.py b/hc/front/tests/test_add_pdc_complete.py deleted file mode 100644 index 4926470b..00000000 --- a/hc/front/tests/test_add_pdc_complete.py +++ /dev/null @@ -1,45 +0,0 @@ -from django.test.utils import override_settings -from hc.test import BaseTestCase - - -@override_settings(PD_VENDOR_KEY="foo") -class AddPdcCompleteTestCase(BaseTestCase): - def setUp(self): - super().setUp() - self.url = "/projects/%s/add_pdc/" % self.project.code - self.url += "XXXXXXXXXXXX/?service_key=123" - - def test_it_validates_code(self): - session = self.client.session - session["pd"] = "1234567890AB" - session.save() - - self.client.login(username="alice@example.org", password="password") - r = self.client.get(self.url) - self.assertEqual(r.status_code, 400) - - @override_settings(PD_VENDOR_KEY=None) - def test_it_requires_vendor_key(self): - self.client.login(username="alice@example.org", password="password") - - r = self.client.get(self.url) - self.assertEqual(r.status_code, 404) - - @override_settings(PD_ENABLED=False) - def test_it_requires_pd_enabled(self): - self.client.login(username="alice@example.org", password="password") - - r = self.client.get(self.url) - self.assertEqual(r.status_code, 404) - - def test_it_requires_rw_access(self): - self.bobs_membership.rw = False - self.bobs_membership.save() - - session = self.client.session - session["pd"] = "1234567890AB" - session.save() - - self.client.login(username="bob@example.org", password="password") - r = self.client.get(self.url) - self.assertEqual(r.status_code, 403) diff --git a/hc/front/tests/test_add_pdc_help.py b/hc/front/tests/test_pd_help.py similarity index 84% rename from hc/front/tests/test_add_pdc_help.py rename to hc/front/tests/test_pd_help.py index 9ac98975..876c3290 100644 --- a/hc/front/tests/test_add_pdc_help.py +++ b/hc/front/tests/test_pd_help.py @@ -2,9 +2,9 @@ from django.test.utils import override_settings from hc.test import BaseTestCase -@override_settings(PD_VENDOR_KEY="foo") +@override_settings(PD_APP_ID="abc") class AddPdcHelpTestCase(BaseTestCase): - url = "/integrations/add_pdc/" + url = "/integrations/pagerduty/" def test_instructions_work_when_not_logged_in(self): r = self.client.get(self.url) @@ -15,7 +15,7 @@ class AddPdcHelpTestCase(BaseTestCase): r = self.client.get(self.url) self.assertContains(r, "If your team uses") - @override_settings(PD_VENDOR_KEY=None) + @override_settings(PD_APP_ID=None) def test_it_requires_vendor_key(self): r = self.client.get(self.url) self.assertEqual(r.status_code, 404) diff --git a/hc/front/urls.py b/hc/front/urls.py index be827b9e..6216b312 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -31,7 +31,7 @@ channel_urls = [ 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.pdc_help, name="hc-pdc-help"), + path("pagerduty/", views.pd_help, name="hc-pagerduty-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"), @@ -63,8 +63,6 @@ project_urls = [ path("add_opsgenie/", views.add_opsgenie, name="hc-add-opsgenie"), path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"), path("add_pd/", views.add_pd, name="hc-add-pd"), - path("add_pdc/", views.add_pdc, name="hc-add-pdc"), - path("add_pdc//", views.add_pdc_complete, name="hc-add-pdc-complete"), path("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"), path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"), path("add_pushover/", views.add_pushover, name="hc-add-pushover"), diff --git a/hc/front/views.py b/hc/front/views.py index 76b0da23..bfc8cde8 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -311,7 +311,7 @@ def index(request): "enable_opsgenie": settings.OPSGENIE_ENABLED is True, "enable_pagertree": settings.PAGERTREE_ENABLED is True, "enable_pd": settings.PD_ENABLED is True, - "enable_pdc": settings.PD_VENDOR_KEY is not None, + "enable_pd_simple": settings.PD_APP_ID is not None, "enable_prometheus": settings.PROMETHEUS_ENABLED is True, "enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None, "enable_pushover": settings.PUSHOVER_API_TOKEN is not None, @@ -822,7 +822,6 @@ def channels(request, code): "enable_opsgenie": settings.OPSGENIE_ENABLED is True, "enable_pagertree": settings.PAGERTREE_ENABLED is True, "enable_pd": settings.PD_ENABLED is True, - "enable_pdc": settings.PD_VENDOR_KEY is not None, "enable_prometheus": settings.PROMETHEUS_ENABLED is True, "enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None, "enable_pushover": settings.PUSHOVER_API_TOKEN is not None, @@ -1148,59 +1147,10 @@ def add_pd_complete(request): @require_setting("PD_ENABLED") -@require_setting("PD_VENDOR_KEY") -def pdc_help(request): +@require_setting("PD_APP_ID") +def pd_help(request): ctx = {"page": "channels"} - return render(request, "integrations/add_pdc.html", ctx) - - -@require_setting("PD_ENABLED") -@require_setting("PD_VENDOR_KEY") -@login_required -def add_pdc(request, code): - project = _get_rw_project_for_user(request, code) - - state = token_urlsafe() - callback = settings.SITE_ROOT + reverse( - "hc-add-pdc-complete", args=[project.code, state] - ) - connect_url = "https://connect.pagerduty.com/connect?" + urlencode( - {"vendor": settings.PD_VENDOR_KEY, "callback": callback} - ) - - ctx = {"page": "channels", "project": project, "connect_url": connect_url} - request.session["pd"] = state - return render(request, "integrations/add_pdc.html", ctx) - - -@require_setting("PD_ENABLED") -@require_setting("PD_VENDOR_KEY") -@login_required -def add_pdc_complete(request, code, state): - if "pd" not in request.session: - return HttpResponseBadRequest() - - project = _get_rw_project_for_user(request, code) - - session_state = request.session.pop("pd") - if session_state != state: - return HttpResponseBadRequest() - - if request.GET.get("error") == "cancelled": - messages.warning(request, "PagerDuty setup was cancelled.") - return redirect("hc-channels", project.code) - - channel = Channel(kind="pd", project=project) - channel.value = json.dumps( - { - "service_key": request.GET.get("service_key"), - "account": request.GET.get("account"), - } - ) - channel.save() - channel.assign_all_checks() - messages.success(request, "The PagerDuty integration has been added!") - return redirect("hc-channels", project.code) + return render(request, "integrations/add_pd_simple.html", ctx) @require_setting("PAGERTREE_ENABLED") diff --git a/hc/settings.py b/hc/settings.py index a6258dc2..2867d9c6 100644 --- a/hc/settings.py +++ b/hc/settings.py @@ -214,7 +214,6 @@ PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True") # PagerDuty PD_ENABLED = envbool("PD_ENABLED", "True") -PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY") PD_APP_ID = os.getenv("PD_APP_ID") # Prometheus diff --git a/static/img/integrations/setup_pdc_0.png b/static/img/integrations/setup_pdc_0.png deleted file mode 100644 index fbde09e7..00000000 Binary files a/static/img/integrations/setup_pdc_0.png and /dev/null differ diff --git a/static/img/integrations/setup_pdc_1.png b/static/img/integrations/setup_pdc_1.png deleted file mode 100644 index cd9c1321..00000000 Binary files a/static/img/integrations/setup_pdc_1.png and /dev/null differ diff --git a/static/img/integrations/setup_pdc_2.png b/static/img/integrations/setup_pdc_2.png deleted file mode 100644 index c7f3f6c5..00000000 Binary files a/static/img/integrations/setup_pdc_2.png and /dev/null differ diff --git a/static/img/integrations/setup_pdc_3.png b/static/img/integrations/setup_pdc_3.png deleted file mode 100644 index bce423d3..00000000 Binary files a/static/img/integrations/setup_pdc_3.png and /dev/null differ diff --git a/templates/front/channels.html b/templates/front/channels.html index fb6d9327..f4fa3ae9 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -311,12 +311,7 @@

PagerDuty

On-call scheduling, alerting, and incident tracking.

- - {% if enable_pdc %} - Add Integration - {% else %} - Add Integration - {% endif %} + Add Integration {% endif %} diff --git a/templates/front/welcome.html b/templates/front/welcome.html index b56330ec..4da4fa27 100644 --- a/templates/front/welcome.html +++ b/templates/front/welcome.html @@ -498,8 +498,8 @@ {% if enable_pd %}
- {% if enable_pdc %} - + {% if enable_pd_simple %} +

PagerDuty
diff --git a/templates/integrations/add_pdc.html b/templates/integrations/add_pdc.html deleted file mode 100644 index 58d6728e..00000000 --- a/templates/integrations/add_pdc.html +++ /dev/null @@ -1,126 +0,0 @@ -{% extends "base.html" %} -{% load humanize static hc_extras %} - -{% block title %}PagerDuty Integration for {{ site_name }}{% endblock %} - -{% block description %} - -{% endblock %} - -{% block content %} -
-
-

PagerDuty

- -
- {% if request.user.is_authenticated %} -

If your team uses PagerDuty, - you can set up {{ site_name }} to create a PagerDuty incident when - a check goes down, and resolve it when a check goes back up.

- - {% if connect_url %} -
-
- - Alert with PagerDuty - -
-
- {% endif %} - - {% else %} -

- {{ site_name }} is a free and - open source - service for monitoring your cron jobs, background processes and - scheduled tasks. Before adding PagerDuty integration, please log into - {{ site_name }}:

- -
- Sign In -
- {% endif %} -
- -

Setup Guide

- - {% if not connect_url %} -
-
- -

- {% if request.user.is_authenticated %} - Go - {% else %} - After logging in, go - {% endif %} - - to the Integrations page, - and click on Add Integration next to the - PagerDuty integration. -

-
-
- Screenshot -
-
- {% endif %} - -
-
- -

- Click on "Alert with PagerDuty", and you will be - asked to log into your PagerDuty account. -

-
-
- Screenshot -
-
- -
-
- -

- Next, PagerDuty will let set the name and escalation policy - for this integration. -

-
-
- Screenshot -
-
- -
-
- -

- And that is all! You will then be redirected back to - "Integrations" page on {{ site_name }} and see - the new integration! -

-
-
- Screenshot -
-
-
-
-{% endblock %}