From a6d497b21e2c60d402f251b0163079f97ab571e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 21 Feb 2020 15:03:26 +0200 Subject: [PATCH] Project code in URL for the "Add OpsGenie" page. cc: #336 --- hc/front/tests/test_add_opsgenie.py | 8 +++++--- hc/front/urls.py | 2 +- hc/front/views.py | 10 ++++++---- templates/front/channels.html | 2 +- templates/integrations/add_opsgenie.html | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hc/front/tests/test_add_opsgenie.py b/hc/front/tests/test_add_opsgenie.py index 706e329f..eaeba20a 100644 --- a/hc/front/tests/test_add_opsgenie.py +++ b/hc/front/tests/test_add_opsgenie.py @@ -5,7 +5,9 @@ from hc.test import BaseTestCase class AddOpsGenieTestCase(BaseTestCase): - url = "/integrations/add_opsgenie/" + def setUp(self): + super(AddOpsGenieTestCase, self).setUp() + self.url = "/projects/%s/add_opsgenie/" % self.project.code def test_instructions_work(self): self.client.login(username="alice@example.org", password="password") @@ -17,7 +19,7 @@ class AddOpsGenieTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) - self.assertRedirects(r, "/integrations/") + self.assertRedirects(r, self.channels_url) c = Channel.objects.get() self.assertEqual(c.kind, "opsgenie") @@ -41,7 +43,7 @@ class AddOpsGenieTestCase(BaseTestCase): form = {"key": "123456", "region": "eu"} self.client.login(username="alice@example.org", password="password") - r = self.client.post(self.url, form) + self.client.post(self.url, form) c = Channel.objects.get() payload = json.loads(c.value) diff --git a/hc/front/urls.py b/hc/front/urls.py index 95cc076d..9085a3a5 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -35,7 +35,6 @@ channel_urls = [ path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"), path("add_discord/", views.add_discord, name="hc-add-discord"), path("add_pushover/", views.add_pushover, name="hc-add-pushover"), - path("add_opsgenie/", views.add_opsgenie, name="hc-add-opsgenie"), path("add_victorops/", views.add_victorops, name="hc-add-victorops"), path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"), path("add_telegram/", views.add_telegram, name="hc-add-telegram"), @@ -64,6 +63,7 @@ project_urls = [ path("add_matrix/", views.add_matrix, name="hc-add-matrix"), path("add_mattermost/", views.add_mattermost, name="hc-add-mattermost"), path("add_msteams/", views.add_msteams, name="hc-add-msteams"), + path("add_opsgenie/", views.add_opsgenie, name="hc-add-opsgenie"), path("add_webhook/", views.add_webhook, name="hc-add-webhook"), path("badges/", views.badges, name="hc-badges"), path("checks/", views.my_checks, name="hc-checks"), diff --git a/hc/front/views.py b/hc/front/views.py index 83d26b5a..a79f8283 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1270,21 +1270,23 @@ def add_pushover(request): @login_required -def add_opsgenie(request): +def add_opsgenie(request, code): + project = _get_project_for_user(request, code) + if request.method == "POST": form = AddOpsGenieForm(request.POST) if form.is_valid(): - channel = Channel(project=request.project, kind="opsgenie") + channel = Channel(project=project, kind="opsgenie") v = {"region": form.cleaned_data["region"], "key": form.cleaned_data["key"]} channel.value = json.dumps(v) channel.save() channel.assign_all_checks() - return redirect("hc-channels") + return redirect("hc-p-channels", project.code) else: form = AddOpsGenieForm() - ctx = {"page": "channels", "project": request.project, "form": form} + ctx = {"page": "channels", "project": project, "form": form} return render(request, "integrations/add_opsgenie.html", ctx) diff --git a/templates/front/channels.html b/templates/front/channels.html index 82da286c..4d64119f 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -254,7 +254,7 @@

OpsGenie

Alerting & Incident Management Solution for Dev & Ops.

- Add Integration + Add Integration
  • diff --git a/templates/integrations/add_opsgenie.html b/templates/integrations/add_opsgenie.html index 89086aeb..012a1d6e 100644 --- a/templates/integrations/add_opsgenie.html +++ b/templates/integrations/add_opsgenie.html @@ -64,7 +64,7 @@

    Integration Settings

    -
    + {% csrf_token %}