diff --git a/hc/front/tests/test_add_sms.py b/hc/front/tests/test_add_sms.py index 744b84fb..9ab1c3f6 100644 --- a/hc/front/tests/test_add_sms.py +++ b/hc/front/tests/test_add_sms.py @@ -5,7 +5,9 @@ from hc.test import BaseTestCase @override_settings(TWILIO_ACCOUNT="foo", TWILIO_AUTH="foo", TWILIO_FROM="123") class AddSmsTestCase(BaseTestCase): - url = "/integrations/add_sms/" + def setUp(self): + super(AddSmsTestCase, self).setUp() + self.url = "/projects/%s/add_sms/" % self.project.code def test_instructions_work(self): self.client.login(username="alice@example.org", password="password") @@ -26,7 +28,7 @@ class AddSmsTestCase(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, "sms") @@ -53,5 +55,5 @@ class AddSmsTestCase(BaseTestCase): @override_settings(TWILIO_AUTH=None) def test_it_requires_credentials(self): self.client.login(username="alice@example.org", password="password") - r = self.client.get("/integrations/add_sms/") + 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 4d5944ed..395c11e3 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -36,7 +36,6 @@ channel_urls = [ 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"), - path("add_sms/", views.add_sms, name="hc-add-sms"), path("add_whatsapp/", views.add_whatsapp, name="hc-add-whatsapp"), path("add_trello/", views.add_trello, name="hc-add-trello"), path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"), @@ -64,6 +63,7 @@ project_urls = [ path("add_pagerteam/", views.add_pagerteam, name="hc-add-pagerteam"), path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"), path("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"), + path("add_sms/", views.add_sms, name="hc-add-sms"), 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 0e74ea30..d53bd5fc 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1371,28 +1371,29 @@ def add_telegram(request): @login_required -def add_sms(request): +def add_sms(request, code): if settings.TWILIO_AUTH is None: raise Http404("sms integration is not available") + project = _get_project_for_user(request, code) if request.method == "POST": form = AddSmsForm(request.POST) if form.is_valid(): - channel = Channel(project=request.project, kind="sms") + channel = Channel(project=project, kind="sms") channel.name = form.cleaned_data["label"] channel.value = json.dumps({"value": form.cleaned_data["value"]}) channel.save() channel.assign_all_checks() - return redirect("hc-channels") + return redirect("hc-p-channels", project.code) else: form = AddSmsForm() ctx = { "page": "channels", - "project": request.project, + "project": project, "form": form, - "profile": request.project.owner_profile, + "profile": project.owner_profile, } return render(request, "integrations/add_sms.html", ctx) diff --git a/templates/front/channels.html b/templates/front/channels.html index c41cdcc9..b007c484 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -345,7 +345,7 @@

SMS

Get a text message to your phone when a check goes down.

- Add Integration + Add Integration {% endif %} diff --git a/templates/integrations/add_sms.html b/templates/integrations/add_sms.html index 76b6356c..ebc18dcf 100644 --- a/templates/integrations/add_sms.html +++ b/templates/integrations/add_sms.html @@ -25,7 +25,7 @@

Integration Settings

-
+ {% csrf_token %}