From d0b77febbc2ec85638034de905e2eac673297747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 21 Feb 2020 14:58:22 +0200 Subject: [PATCH] Project code in URL for the "Add MS Teams" page. cc: #336 --- hc/front/tests/test_add_msteams.py | 10 +++++++--- hc/front/urls.py | 2 +- hc/front/views.py | 10 ++++++---- templates/front/channels.html | 2 +- templates/integrations/add_msteams.html | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/hc/front/tests/test_add_msteams.py b/hc/front/tests/test_add_msteams.py index 441d43bf..3aeb61ca 100644 --- a/hc/front/tests/test_add_msteams.py +++ b/hc/front/tests/test_add_msteams.py @@ -3,17 +3,21 @@ from hc.test import BaseTestCase class AddMsTeamsTestCase(BaseTestCase): + def setUp(self): + super(AddMsTeamsTestCase, self).setUp() + self.url = "/projects/%s/add_msteams/" % self.project.code + def test_instructions_work(self): self.client.login(username="alice@example.org", password="password") - r = self.client.get("/integrations/add_msteams/") + r = self.client.get(self.url) self.assertContains(r, "Integration Settings", status_code=200) def test_it_works(self): form = {"value": "https://example.com/foo"} self.client.login(username="alice@example.org", password="password") - r = self.client.post("/integrations/add_msteams/", form) - self.assertRedirects(r, "/integrations/") + r = self.client.post(self.url, form) + self.assertRedirects(r, self.channels_url) c = Channel.objects.get() self.assertEqual(c.kind, "msteams") diff --git a/hc/front/urls.py b/hc/front/urls.py index 6654eb87..95cc076d 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -44,7 +44,6 @@ channel_urls = [ 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"), - path("add_msteams/", views.add_msteams, name="hc-add-msteams"), path("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"), path("/checks/", views.channel_checks, name="hc-channel-checks"), path("/name/", views.update_channel_name, name="hc-channel-name"), @@ -64,6 +63,7 @@ project_urls = [ path("add_email/", views.add_email, name="hc-add-email"), 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_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 939be3ec..83d26b5a 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1534,20 +1534,22 @@ def trello_settings(request): @login_required -def add_msteams(request): +def add_msteams(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="msteams") + channel = Channel(project=project, kind="msteams") 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_msteams.html", ctx) diff --git a/templates/front/channels.html b/templates/front/channels.html index b9179082..82da286c 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -244,7 +244,7 @@

Microsoft Teams

Chat and collaboration platform for Microsoft Office 365 customers.

- Add Integration + Add Integration
  • diff --git a/templates/integrations/add_msteams.html b/templates/integrations/add_msteams.html index 7437349f..cb959ff9 100644 --- a/templates/integrations/add_msteams.html +++ b/templates/integrations/add_msteams.html @@ -95,7 +95,7 @@

    Integration Settings

    -
    + {% csrf_token %}