Browse Source

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

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

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

@ -3,7 +3,9 @@ from hc.test import BaseTestCase
class AddPdTestCase(BaseTestCase): class AddPdTestCase(BaseTestCase):
url = "/integrations/add_pd/"
def setUp(self):
super(AddPdTestCase, self).setUp()
self.url = "/projects/%s/add_pd/" % 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")
@ -16,7 +18,7 @@ class AddPdTestCase(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, "pd") self.assertEqual(c.kind, "pd")


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

@ -24,7 +24,6 @@ check_urls = [
channel_urls = [ channel_urls = [
path("", views.channels, name="hc-channels"), path("", views.channels, name="hc-channels"),
path("add_pd/", views.add_pd, name="hc-add-pd"),
path("add_pdc/", views.add_pdc, name="hc-add-pdc"), path("add_pdc/", views.add_pdc, name="hc-add-pdc"),
path("add_pdc/<str:state>/", views.add_pdc, name="hc-add-pdc-state"), path("add_pdc/<str:state>/", views.add_pdc, name="hc-add-pdc-state"),
path("add_slack/", views.add_slack, name="hc-add-slack"), path("add_slack/", views.add_slack, name="hc-add-slack"),
@ -59,6 +58,7 @@ project_urls = [
path("add_opsgenie/", views.add_opsgenie, name="hc-add-opsgenie"), path("add_opsgenie/", views.add_opsgenie, name="hc-add-opsgenie"),
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_pd/", views.add_pd, name="hc-add-pd"),
path("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"), path("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"),
path("add_shell/", views.add_shell, name="hc-add-shell"), path("add_shell/", views.add_shell, name="hc-add-shell"),
path("add_sms/", views.add_sms, name="hc-add-sms"), path("add_sms/", views.add_sms, name="hc-add-sms"),


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

@ -921,16 +921,18 @@ def _get_validated_code(request, session_key, key="code"):
@login_required @login_required
def add_pd(request):
def add_pd(request, code):
project = _get_project_for_user(request, code)
if request.method == "POST": if request.method == "POST":
form = AddPdForm(request.POST) form = AddPdForm(request.POST)
if form.is_valid(): if form.is_valid():
channel = Channel(project=request.project, kind="pd")
channel = Channel(project=project, kind="pd")
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 = AddPdForm() form = AddPdForm()


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

@ -259,7 +259,7 @@
{% if enable_pdc %} {% if enable_pdc %}
<a href="{% url 'hc-add-pdc' %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-pdc' %}" class="btn btn-primary">Add Integration</a>
{% else %} {% else %}
<a href="{% url 'hc-add-pd' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-pd' project.code %}" class="btn btn-primary">Add Integration</a>
{% endif %} {% endif %}
</li> </li>


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

@ -63,7 +63,7 @@
<h2>Integration Settings</h2> <h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-pd' %}">
<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="api-key" class="col-sm-2 control-label">Integration Key</label> <label for="api-key" class="col-sm-2 control-label">Integration Key</label>


Loading…
Cancel
Save