Browse Source

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

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

+ 4
- 2
hc/front/tests/test_add_victorops.py View File

@ -3,7 +3,9 @@ from hc.test import BaseTestCase
class AddVictorOpsTestCase(BaseTestCase): class AddVictorOpsTestCase(BaseTestCase):
url = "/integrations/add_victorops/"
def setUp(self):
super(AddVictorOpsTestCase, self).setUp()
self.url = "/projects/%s/add_victorops/" % 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")
@ -15,7 +17,7 @@ class AddVictorOpsTestCase(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, "victorops") self.assertEqual(c.kind, "victorops")


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

@ -33,7 +33,6 @@ channel_urls = [
path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"), path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"),
path("add_discord/", views.add_discord, name="hc-add-discord"), path("add_discord/", views.add_discord, name="hc-add-discord"),
path("add_pushover/", views.add_pushover, name="hc-add-pushover"), path("add_pushover/", views.add_pushover, name="hc-add-pushover"),
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_whatsapp/", views.add_whatsapp, name="hc-add-whatsapp"), path("add_whatsapp/", views.add_whatsapp, name="hc-add-whatsapp"),
@ -64,6 +63,7 @@ project_urls = [
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_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_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
- 4
hc/front/views.py View File

@ -1295,20 +1295,22 @@ def add_opsgenie(request, code):
@login_required @login_required
def add_victorops(request):
def add_victorops(request, code):
project = _get_project_for_user(request, code)
if request.method == "POST": if request.method == "POST":
form = AddUrlForm(request.POST) form = AddUrlForm(request.POST)
if form.is_valid(): if form.is_valid():
channel = Channel(project=request.project, kind="victorops")
channel = Channel(project=project, kind="victorops")
channel.value = form.cleaned_data["value"] channel.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 = AddUrlForm() form = AddUrlForm()
ctx = {"page": "channels", "project": request.project, "form": form}
ctx = {"page": "channels", "project": project, "form": form}
return render(request, "integrations/add_victorops.html", ctx) return render(request, "integrations/add_victorops.html", ctx)


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

@ -380,7 +380,7 @@
<h2>VictorOps</h2> <h2>VictorOps</h2>
<p>On-call scheduling, alerting, and incident tracking.</p> <p>On-call scheduling, alerting, and incident tracking.</p>
<a href="{% url 'hc-add-victorops' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-victorops' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% if enable_whatsapp %} {% if enable_whatsapp %}


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

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


Loading…
Cancel
Save