Browse Source

Project code in URL for the "Add SMS" page. cc: #336

pull/340/head
Pēteris Caune 5 years ago
parent
commit
250935006d
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 14 additions and 11 deletions
  1. +5
    -3
      hc/front/tests/test_add_sms.py
  2. +1
    -1
      hc/front/urls.py
  3. +6
    -5
      hc/front/views.py
  4. +1
    -1
      templates/front/channels.html
  5. +1
    -1
      templates/integrations/add_sms.html

+ 5
- 3
hc/front/tests/test_add_sms.py View File

@ -5,7 +5,9 @@ from hc.test import BaseTestCase
@override_settings(TWILIO_ACCOUNT="foo", TWILIO_AUTH="foo", TWILIO_FROM="123") @override_settings(TWILIO_ACCOUNT="foo", TWILIO_AUTH="foo", TWILIO_FROM="123")
class AddSmsTestCase(BaseTestCase): 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): def test_instructions_work(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
@ -26,7 +28,7 @@ class AddSmsTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form) r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get() c = Channel.objects.get()
self.assertEqual(c.kind, "sms") self.assertEqual(c.kind, "sms")
@ -53,5 +55,5 @@ class AddSmsTestCase(BaseTestCase):
@override_settings(TWILIO_AUTH=None) @override_settings(TWILIO_AUTH=None)
def test_it_requires_credentials(self): def test_it_requires_credentials(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get("/integrations/add_sms/")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 404) self.assertEqual(r.status_code, 404)

+ 1
- 1
hc/front/urls.py View File

@ -36,7 +36,6 @@ channel_urls = [
path("add_victorops/", views.add_victorops, name="hc-add-victorops"), path("add_victorops/", views.add_victorops, name="hc-add-victorops"),
path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"), path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"),
path("add_telegram/", views.add_telegram, name="hc-add-telegram"), 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_whatsapp/", views.add_whatsapp, name="hc-add-whatsapp"),
path("add_trello/", views.add_trello, name="hc-add-trello"), path("add_trello/", views.add_trello, name="hc-add-trello"),
path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"), 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_pagerteam/", views.add_pagerteam, name="hc-add-pagerteam"),
path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"), path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"),
path("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"), 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("add_webhook/", views.add_webhook, name="hc-add-webhook"),
path("badges/", views.badges, name="hc-badges"), path("badges/", views.badges, name="hc-badges"),
path("checks/", views.my_checks, name="hc-checks"), path("checks/", views.my_checks, name="hc-checks"),


+ 6
- 5
hc/front/views.py View File

@ -1371,28 +1371,29 @@ def add_telegram(request):
@login_required @login_required
def add_sms(request):
def add_sms(request, code):
if settings.TWILIO_AUTH is None: if settings.TWILIO_AUTH is None:
raise Http404("sms integration is not available") raise Http404("sms integration is not available")
project = _get_project_for_user(request, code)
if request.method == "POST": if request.method == "POST":
form = AddSmsForm(request.POST) form = AddSmsForm(request.POST)
if form.is_valid(): if form.is_valid():
channel = Channel(project=request.project, kind="sms")
channel = Channel(project=project, kind="sms")
channel.name = form.cleaned_data["label"] channel.name = form.cleaned_data["label"]
channel.value = json.dumps({"value": form.cleaned_data["value"]}) channel.value = json.dumps({"value": form.cleaned_data["value"]})
channel.save() channel.save()
channel.assign_all_checks() channel.assign_all_checks()
return redirect("hc-channels")
return redirect("hc-p-channels", project.code)
else: else:
form = AddSmsForm() form = AddSmsForm()
ctx = { ctx = {
"page": "channels", "page": "channels",
"project": request.project,
"project": project,
"form": form, "form": form,
"profile": request.project.owner_profile,
"profile": project.owner_profile,
} }
return render(request, "integrations/add_sms.html", ctx) return render(request, "integrations/add_sms.html", ctx)


+ 1
- 1
templates/front/channels.html View File

@ -345,7 +345,7 @@
<h2>SMS</h2> <h2>SMS</h2>
<p>Get a text message to your phone when a check goes down.</p> <p>Get a text message to your phone when a check goes down.</p>
<a href="{% url 'hc-add-sms' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-sms' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %} {% endif %}


+ 1
- 1
templates/integrations/add_sms.html View File

@ -25,7 +25,7 @@
<h2>Integration Settings</h2> <h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-sms' %}">
<form method="post" class="form-horizontal">
{% csrf_token %} {% csrf_token %}
<div class="form-group {{ form.label.css_classes }}"> <div class="form-group {{ form.label.css_classes }}">
<label for="id_label" class="col-sm-2 control-label">Label</label> <label for="id_label" class="col-sm-2 control-label">Label</label>


Loading…
Cancel
Save