Browse Source

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

pull/340/head
Pēteris Caune 5 years ago
parent
commit
a6d497b21e
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 14 additions and 10 deletions
  1. +5
    -3
      hc/front/tests/test_add_opsgenie.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_opsgenie.html

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

@ -5,7 +5,9 @@ from hc.test import BaseTestCase
class AddOpsGenieTestCase(BaseTestCase):
url = "/integrations/add_opsgenie/"
def setUp(self):
super(AddOpsGenieTestCase, self).setUp()
self.url = "/projects/%s/add_opsgenie/" % self.project.code
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
@ -17,7 +19,7 @@ class AddOpsGenieTestCase(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, "opsgenie")
@ -41,7 +43,7 @@ class AddOpsGenieTestCase(BaseTestCase):
form = {"key": "123456", "region": "eu"}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.client.post(self.url, form)
c = Channel.objects.get()
payload = json.loads(c.value)


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

@ -35,7 +35,6 @@ channel_urls = [
path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"),
path("add_discord/", views.add_discord, name="hc-add-discord"),
path("add_pushover/", views.add_pushover, name="hc-add-pushover"),
path("add_opsgenie/", views.add_opsgenie, name="hc-add-opsgenie"),
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"),
@ -64,6 +63,7 @@ project_urls = [
path("add_matrix/", views.add_matrix, name="hc-add-matrix"),
path("add_mattermost/", views.add_mattermost, name="hc-add-mattermost"),
path("add_msteams/", views.add_msteams, name="hc-add-msteams"),
path("add_opsgenie/", views.add_opsgenie, name="hc-add-opsgenie"),
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"),


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

@ -1270,21 +1270,23 @@ def add_pushover(request):
@login_required
def add_opsgenie(request):
def add_opsgenie(request, code):
project = _get_project_for_user(request, code)
if request.method == "POST":
form = AddOpsGenieForm(request.POST)
if form.is_valid():
channel = Channel(project=request.project, kind="opsgenie")
channel = Channel(project=project, kind="opsgenie")
v = {"region": form.cleaned_data["region"], "key": form.cleaned_data["key"]}
channel.value = json.dumps(v)
channel.save()
channel.assign_all_checks()
return redirect("hc-channels")
return redirect("hc-p-channels", project.code)
else:
form = AddOpsGenieForm()
ctx = {"page": "channels", "project": request.project, "form": form}
ctx = {"page": "channels", "project": project, "form": form}
return render(request, "integrations/add_opsgenie.html", ctx)


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

@ -254,7 +254,7 @@
<h2>OpsGenie</h2>
<p> Alerting &amp; Incident Management Solution for Dev &amp; Ops.</p>
<a href="{% url 'hc-add-opsgenie' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-opsgenie' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
<li>


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

@ -64,7 +64,7 @@
<h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-opsgenie' %}">
<form method="post" class="form-horizontal">
{% csrf_token %}
<div class="form-group {{ form.value.css_classes }}">
<label for="api-key" class="col-sm-2 control-label">API Key</label>


Loading…
Cancel
Save