Browse Source

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

pull/340/head
Pēteris Caune 5 years ago
parent
commit
70ff6c53e4
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 31 additions and 24 deletions
  1. +7
    -5
      hc/front/tests/test_add_mattermost.py
  2. +15
    -11
      hc/front/urls.py
  3. +6
    -5
      hc/front/views.py
  4. +1
    -1
      templates/front/channels.html
  5. +2
    -2
      templates/integrations/add_mattermost.html

+ 7
- 5
hc/front/tests/test_add_mattermost.py View File

@ -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="[email protected]", 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="[email protected]", 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")


+ 15
- 11
hc/front/urls.py View File

@ -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/<slug:key>", views.metrics,),
path("metrics/<slug:key>", 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/<uuid:code>/checks/", views.my_checks, name="hc-checks"),
path("projects/<uuid:code>/badges/", views.badges, name="hc-badges"),
path("projects/<uuid:code>/checks/add/", views.add_check, name="hc-add-check"),
path("checks/cron_preview/", views.cron_preview),
path("projects/<uuid:code>/checks/status/", views.status, name="hc-status"),
path("projects/<uuid:code>/checks/metrics/<slug:key>", views.metrics,),
path("projects/<uuid:code>/metrics/<slug:key>", views.metrics, name="hc-metrics",),
path("checks/<uuid:code>/", include(check_urls)),
path("integrations/", include(channel_urls)),
path("projects/<uuid:code>/integrations/", views.channels, name="hc-p-channels"),
path("projects/<uuid:code>/add_email/", views.add_email, name="hc-add-email"),
path("projects/<uuid:code>/add_matrix/", views.add_matrix, name="hc-add-matrix"),
path("projects/<uuid:code>/add_webhook/", views.add_webhook, name="hc-add-webhook"),
path("projects/<uuid:code>/", 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"),


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

@ -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)


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

@ -234,7 +234,7 @@
<h2>Mattermost</h2>
<p>High Trust Messaging for the Enterprise.</p>
<a href="{% url 'hc-add-mattermost' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-mattermost' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
<li>


+ 2
- 2
templates/integrations/add_mattermost.html View File

@ -44,7 +44,7 @@
class="ai-guide-screenshot"
alt="Screenshot"
src="{% static 'img/integrations/setup_mattermost_2.png' %}">
</div>
</div>
</div>
<div class="row ai-step">
@ -63,7 +63,7 @@
<h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-mattermost' %}">
<form method="post" class="form-horizontal">
{% csrf_token %}
<div class="form-group {{ form.value.css_classes }}">
<label for="callback-url" class="col-sm-2 control-label">


Loading…
Cancel
Save