forked from GithubBackups/healthchecks
Project code in URL for the "Add SMS" page. cc: #336
This commit is contained in:
parent
f6a7d46058
commit
250935006d
@ -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)
|
||||
|
@ -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"),
|
||||
|
@ -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)
|
||||
|
||||
|
@ -345,7 +345,7 @@
|
||||
<h2>SMS</h2>
|
||||
<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>
|
||||
{% endif %}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
<h2>Integration Settings</h2>
|
||||
|
||||
<form method="post" class="form-horizontal" action="{% url 'hc-add-sms' %}">
|
||||
<form method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
<div class="form-group {{ form.label.css_classes }}">
|
||||
<label for="id_label" class="col-sm-2 control-label">Label</label>
|
||||
|
Loading…
x
Reference in New Issue
Block a user