From 0ea2369dc0050fedb0fec067caaa51214c79344d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 21 Feb 2020 15:08:53 +0200 Subject: [PATCH] Project code in URL for the "Add Pagerteam" page. cc: #336 --- hc/front/tests/test_add_pagerteam.py | 6 ++++-- hc/front/urls.py | 2 +- hc/front/views.py | 10 ++++++---- templates/front/channels.html | 2 +- templates/integrations/add_pagerteam.html | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hc/front/tests/test_add_pagerteam.py b/hc/front/tests/test_add_pagerteam.py index 530562c2..80dad608 100644 --- a/hc/front/tests/test_add_pagerteam.py +++ b/hc/front/tests/test_add_pagerteam.py @@ -3,7 +3,9 @@ from hc.test import BaseTestCase class AddPagerTeamTestCase(BaseTestCase): - url = "/integrations/add_pagerteam/" + def setUp(self): + super(AddPagerTeamTestCase, self).setUp() + self.url = "/projects/%s/add_pagerteam/" % self.project.code def test_instructions_work(self): self.client.login(username="alice@example.org", password="password") @@ -15,7 +17,7 @@ class AddPagerTeamTestCase(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, "pagerteam") diff --git a/hc/front/urls.py b/hc/front/urls.py index 9085a3a5..14557c1f 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -29,7 +29,6 @@ channel_urls = [ path("add_pdc/", views.add_pdc, name="hc-add-pdc"), path("add_pdc//", views.add_pdc, name="hc-add-pdc-state"), path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"), - path("add_pagerteam/", views.add_pagerteam, name="hc-add-pagerteam"), path("add_slack/", views.add_slack, name="hc-add-slack"), path("add_slack_btn/", views.add_slack_btn, name="hc-add-slack-btn"), path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"), @@ -64,6 +63,7 @@ project_urls = [ 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_pagerteam/", views.add_pagerteam, name="hc-add-pagerteam"), 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"), diff --git a/hc/front/views.py b/hc/front/views.py index a79f8283..47c828d6 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -995,20 +995,22 @@ def add_pagertree(request): @login_required -def add_pagerteam(request): +def add_pagerteam(request, code): + project = _get_project_for_user(request, code) + if request.method == "POST": form = AddUrlForm(request.POST) if form.is_valid(): - channel = Channel(project=request.project, kind="pagerteam") + channel = Channel(project=project, kind="pagerteam") channel.value = form.cleaned_data["value"] channel.save() channel.assign_all_checks() - return redirect("hc-channels") + return redirect("hc-p-channels", project.code) else: form = AddUrlForm() - ctx = {"page": "channels", "project": request.project, "form": form} + ctx = {"page": "channels", "project": project, "form": form} return render(request, "integrations/add_pagerteam.html", ctx) diff --git a/templates/front/channels.html b/templates/front/channels.html index 4d64119f..7c639f9a 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -278,7 +278,7 @@

Pager Team

On-call rotations without limits.

- Add Integration + Add Integration
  • diff --git a/templates/integrations/add_pagerteam.html b/templates/integrations/add_pagerteam.html index 32b62780..304f58ea 100644 --- a/templates/integrations/add_pagerteam.html +++ b/templates/integrations/add_pagerteam.html @@ -40,7 +40,7 @@

    Integration Settings

    -
    + {% csrf_token %}