Browse Source

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

pull/340/head
Pēteris Caune 5 years ago
parent
commit
056134f2de
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_whatsapp.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_whatsapp.html

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

@ -12,7 +12,9 @@ TEST_CREDENTIALS = {
@override_settings(**TEST_CREDENTIALS)
class AddWhatsAppTestCase(BaseTestCase):
url = "/integrations/add_whatsapp/"
def setUp(self):
super(AddWhatsAppTestCase, self).setUp()
self.url = "/projects/%s/add_whatsapp/" % self.project.code
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
@ -38,7 +40,7 @@ class AddWhatsAppTestCase(BaseTestCase):
self.client.login(username="[email protected]", 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, "whatsapp")
@ -53,7 +55,7 @@ class AddWhatsAppTestCase(BaseTestCase):
self.client.login(username="[email protected]", 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, "whatsapp")


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

@ -35,7 +35,6 @@ channel_urls = [
path("add_pushover/", views.add_pushover, name="hc-add-pushover"),
path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"),
path("add_telegram/", views.add_telegram, name="hc-add-telegram"),
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"),
path("add_apprise/", views.add_apprise, name="hc-add-apprise"),
@ -65,6 +64,7 @@ project_urls = [
path("add_sms/", views.add_sms, name="hc-add-sms"),
path("add_victorops/", views.add_victorops, name="hc-add-victorops"),
path("add_webhook/", views.add_webhook, name="hc-add-webhook"),
path("add_whatsapp/", views.add_whatsapp, name="hc-add-whatsapp"),
path("badges/", views.badges, name="hc-badges"),
path("checks/", views.my_checks, name="hc-checks"),
path("checks/add/", views.add_check, name="hc-add-check"),


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

@ -1401,14 +1401,15 @@ def add_sms(request, code):
@login_required
def add_whatsapp(request):
def add_whatsapp(request, code):
if not settings.TWILIO_USE_WHATSAPP:
raise Http404("whatsapp 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="whatsapp")
channel = Channel(project=project, kind="whatsapp")
channel.name = form.cleaned_data["label"]
channel.value = json.dumps(
{
@ -1420,15 +1421,15 @@ def add_whatsapp(request):
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_whatsapp.html", ctx)


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

@ -391,7 +391,7 @@
<h2>WhatsApp</h2>
<p>Get a WhatsApp message when a check goes up or down.</p>
<a href="{% url 'hc-add-whatsapp' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-whatsapp' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}


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

@ -24,7 +24,7 @@
<h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-whatsapp' %}">
<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…
Cancel
Save