diff --git a/hc/front/tests/test_add_mattermost.py b/hc/front/tests/test_add_mattermost.py index 1481462d..41e6a435 100644 --- a/hc/front/tests/test_add_mattermost.py +++ b/hc/front/tests/test_add_mattermost.py @@ -1,21 +1,23 @@ -from django.test.utils import override_settings - from hc.api.models import Channel from hc.test import BaseTestCase class AddMattermostTestCase(BaseTestCase): + def setUp(self): + super(AddMattermostTestCase, self).setUp() + self.url = "/projects/%s/add_mattermost/" % self.project.code + def test_instructions_work(self): self.client.login(username="alice@example.org", password="password") - r = self.client.get("/integrations/add_mattermost/") + r = self.client.get(self.url) self.assertContains(r, "Integration Settings", status_code=200) def test_it_works(self): form = {"value": "http://example.org"} self.client.login(username="alice@example.org", password="password") - r = self.client.post("/integrations/add_mattermost/", 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, "mattermost") diff --git a/hc/front/urls.py b/hc/front/urls.py index a8589c4d..6654eb87 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -31,7 +31,6 @@ channel_urls = [ 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_mattermost/", views.add_mattermost, name="hc-add-mattermost"), path("add_slack_btn/", views.add_slack_btn, name="hc-add-slack-btn"), path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"), path("add_discord/", views.add_discord, name="hc-add-discord"), @@ -61,21 +60,26 @@ channel_urls = [ ), ] +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_webhook/", views.add_webhook, name="hc-add-webhook"), + path("badges/", views.badges, name="hc-badges"), + path("checks/", views.my_checks, name="hc-checks"), + path("checks/add/", views.add_check, name="hc-add-check"), + path("checks/metrics/", views.metrics,), + path("metrics/", views.metrics, name="hc-metrics",), + path("checks/status/", views.status, name="hc-status"), + path("integrations/", views.channels, name="hc-p-channels"), +] + urlpatterns = [ path("", views.index, name="hc-index"), - path("projects//checks/", views.my_checks, name="hc-checks"), - path("projects//badges/", views.badges, name="hc-badges"), - path("projects//checks/add/", views.add_check, name="hc-add-check"), path("checks/cron_preview/", views.cron_preview), - path("projects//checks/status/", views.status, name="hc-status"), - path("projects//checks/metrics/", views.metrics,), - path("projects//metrics/", views.metrics, name="hc-metrics",), path("checks//", include(check_urls)), path("integrations/", include(channel_urls)), - path("projects//integrations/", views.channels, name="hc-p-channels"), - path("projects//add_email/", views.add_email, name="hc-add-email"), - path("projects//add_matrix/", views.add_matrix, name="hc-add-matrix"), - path("projects//add_webhook/", views.add_webhook, name="hc-add-webhook"), + path("projects//", include(project_urls)), path("docs/", views.serve_doc, name="hc-docs"), path("docs/api/", views.docs_api, name="hc-docs-api"), path("docs/cron/", views.docs_cron, name="hc-docs-cron"), diff --git a/hc/front/views.py b/hc/front/views.py index c8b861d6..939be3ec 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1044,21 +1044,22 @@ def add_slack(request): @login_required -def add_mattermost(request): +def add_mattermost(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="mattermost") + channel = Channel(project=project, kind="mattermost") 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", "form": form, "project": request.project} - + ctx = {"page": "channels", "form": form, "project": project} return render(request, "integrations/add_mattermost.html", ctx) diff --git a/templates/front/channels.html b/templates/front/channels.html index 55f60ae1..b9179082 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -234,7 +234,7 @@

Mattermost

High Trust Messaging for the Enterprise.

- Add Integration + Add Integration
  • diff --git a/templates/integrations/add_mattermost.html b/templates/integrations/add_mattermost.html index bebedb5d..fd3152bc 100644 --- a/templates/integrations/add_mattermost.html +++ b/templates/integrations/add_mattermost.html @@ -44,7 +44,7 @@ class="ai-guide-screenshot" alt="Screenshot" src="{% static 'img/integrations/setup_mattermost_2.png' %}"> - +
    @@ -63,7 +63,7 @@

    Integration Settings

    -
    + {% csrf_token %}