From 59f5b7a5f52a92086a899f6169d54f825e5fb407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 21 Feb 2020 14:29:05 +0200 Subject: [PATCH] Project code in URL for the "Add Webhook" page. cc: #336 --- hc/front/tests/test_add_email.py | 6 +++--- hc/front/tests/test_add_webhook.py | 12 +++++++----- hc/front/urls.py | 2 +- hc/front/views.py | 10 ++++++---- hc/test.py | 2 ++ templates/front/channels.html | 2 +- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/hc/front/tests/test_add_email.py b/hc/front/tests/test_add_email.py index ee9b1ae4..87ec0aa4 100644 --- a/hc/front/tests/test_add_email.py +++ b/hc/front/tests/test_add_email.py @@ -23,7 +23,7 @@ class AddEmailTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) - self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code) + self.assertRedirects(r, self.channels_url) c = Channel.objects.get() doc = json.loads(c.value) @@ -79,7 +79,7 @@ class AddEmailTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) - self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code) + self.assertRedirects(r, self.channels_url) c = Channel.objects.get() doc = json.loads(c.value) @@ -95,7 +95,7 @@ class AddEmailTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) - self.assertRedirects(r, "/projects/%s/integrations/" % self.project.code) + self.assertRedirects(r, self.channels_url) c = Channel.objects.get() doc = json.loads(c.value) diff --git a/hc/front/tests/test_add_webhook.py b/hc/front/tests/test_add_webhook.py index 405f3b1a..d42d3946 100644 --- a/hc/front/tests/test_add_webhook.py +++ b/hc/front/tests/test_add_webhook.py @@ -3,7 +3,9 @@ from hc.test import BaseTestCase class AddWebhookTestCase(BaseTestCase): - url = "/integrations/add_webhook/" + def setUp(self): + super(AddWebhookTestCase, self).setUp() + self.url = "/projects/%s/add_webhook/" % self.project.code def test_instructions_work(self): self.client.login(username="alice@example.org", password="password") @@ -20,7 +22,7 @@ class AddWebhookTestCase(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.project, self.project) @@ -95,7 +97,7 @@ class AddWebhookTestCase(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.down_webhook_spec["body"], "hello") @@ -110,7 +112,7 @@ class AddWebhookTestCase(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( @@ -140,7 +142,7 @@ class AddWebhookTestCase(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.down_webhook_spec["headers"], {"test": "123"}) diff --git a/hc/front/urls.py b/hc/front/urls.py index a9379b82..6800bc18 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -24,7 +24,6 @@ check_urls = [ channel_urls = [ path("", views.channels, name="hc-channels"), - path("add_webhook/", views.add_webhook, name="hc-add-webhook"), path("add_shell/", views.add_shell, name="hc-add-shell"), path("add_pd/", views.add_pd, name="hc-add-pd"), path("add_pdc/", views.add_pdc, name="hc-add-pdc"), @@ -76,6 +75,7 @@ urlpatterns = [ path("integrations/", include(channel_urls)), path("projects//integrations/", views.channels, name="hc-p-channels"), path("projects//add_email/", views.add_email, name="hc-add-email"), + path("projects//add_webhook/", views.add_webhook, name="hc-add-webhook"), path("docs/", views.serve_doc, name="hc-docs"), path("docs/api/", views.docs_api, name="hc-docs-api"), path("docs/cron/", views.docs_cron, name="hc-docs-cron"), diff --git a/hc/front/views.py b/hc/front/views.py index 962632fa..d5bf270a 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -851,22 +851,24 @@ def add_email(request, code): @login_required -def add_webhook(request): +def add_webhook(request, code): + project = _get_project_for_user(request, code) + if request.method == "POST": form = AddWebhookForm(request.POST) if form.is_valid(): - channel = Channel(project=request.project, kind="webhook") + channel = Channel(project=project, kind="webhook") channel.value = form.get_value() channel.save() channel.assign_all_checks() - return redirect("hc-channels") + return redirect("hc-p-channels", project.code) else: form = AddWebhookForm() ctx = { "page": "channels", - "project": request.project, + "project": project, "form": form, "now": timezone.now().replace(microsecond=0).isoformat(), } diff --git a/hc/test.py b/hc/test.py index cc28a82a..ef828a5b 100644 --- a/hc/test.py +++ b/hc/test.py @@ -50,3 +50,5 @@ class BaseTestCase(TestCase): self.charlies_profile = Profile(user=self.charlie) self.charlies_profile.current_project = self.charlies_project self.charlies_profile.save() + + self.channels_url = "/projects/%s/integrations/" % self.project.code diff --git a/templates/front/channels.html b/templates/front/channels.html index 425f4eab..35df0379 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -189,7 +189,7 @@

Webhook

Receive a HTTP callback when a check goes down.

- Add Integration + Add Integration {% if enable_apprise %}