forked from GithubBackups/healthchecks
Project code in URL for the "Add Mattermost" page. cc: #336
This commit is contained in:
parent
f8758e39ea
commit
70ff6c53e4
@ -1,21 +1,23 @@
|
|||||||
from django.test.utils import override_settings
|
|
||||||
|
|
||||||
from hc.api.models import Channel
|
from hc.api.models import Channel
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
class AddMattermostTestCase(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):
|
def test_instructions_work(self):
|
||||||
self.client.login(username="alice@example.org", password="password")
|
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)
|
self.assertContains(r, "Integration Settings", status_code=200)
|
||||||
|
|
||||||
def test_it_works(self):
|
def test_it_works(self):
|
||||||
form = {"value": "http://example.org"}
|
form = {"value": "http://example.org"}
|
||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
r = self.client.post("/integrations/add_mattermost/", form)
|
r = self.client.post(self.url, form)
|
||||||
self.assertRedirects(r, "/integrations/")
|
self.assertRedirects(r, self.channels_url)
|
||||||
|
|
||||||
c = Channel.objects.get()
|
c = Channel.objects.get()
|
||||||
self.assertEqual(c.kind, "mattermost")
|
self.assertEqual(c.kind, "mattermost")
|
||||||
|
@ -31,7 +31,6 @@ channel_urls = [
|
|||||||
path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"),
|
path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"),
|
||||||
path("add_pagerteam/", views.add_pagerteam, name="hc-add-pagerteam"),
|
path("add_pagerteam/", views.add_pagerteam, name="hc-add-pagerteam"),
|
||||||
path("add_slack/", views.add_slack, name="hc-add-slack"),
|
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_slack_btn/", views.add_slack_btn, name="hc-add-slack-btn"),
|
||||||
path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"),
|
path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"),
|
||||||
path("add_discord/", views.add_discord, name="hc-add-discord"),
|
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 = [
|
urlpatterns = [
|
||||||
path("", views.index, name="hc-index"),
|
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("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("checks/<uuid:code>/", include(check_urls)),
|
||||||
path("integrations/", include(channel_urls)),
|
path("integrations/", include(channel_urls)),
|
||||||
path("projects/<uuid:code>/integrations/", views.channels, name="hc-p-channels"),
|
path("projects/<uuid:code>/", include(project_urls)),
|
||||||
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("docs/", views.serve_doc, name="hc-docs"),
|
path("docs/", views.serve_doc, name="hc-docs"),
|
||||||
path("docs/api/", views.docs_api, name="hc-docs-api"),
|
path("docs/api/", views.docs_api, name="hc-docs-api"),
|
||||||
path("docs/cron/", views.docs_cron, name="hc-docs-cron"),
|
path("docs/cron/", views.docs_cron, name="hc-docs-cron"),
|
||||||
|
@ -1044,21 +1044,22 @@ def add_slack(request):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def add_mattermost(request):
|
def add_mattermost(request, code):
|
||||||
|
project = _get_project_for_user(request, code)
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = AddUrlForm(request.POST)
|
form = AddUrlForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
channel = Channel(project=request.project, kind="mattermost")
|
channel = Channel(project=project, kind="mattermost")
|
||||||
channel.value = form.cleaned_data["value"]
|
channel.value = form.cleaned_data["value"]
|
||||||
channel.save()
|
channel.save()
|
||||||
|
|
||||||
channel.assign_all_checks()
|
channel.assign_all_checks()
|
||||||
return redirect("hc-channels")
|
return redirect("hc-p-channels", project.code)
|
||||||
else:
|
else:
|
||||||
form = AddUrlForm()
|
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)
|
return render(request, "integrations/add_mattermost.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@
|
|||||||
<h2>Mattermost</h2>
|
<h2>Mattermost</h2>
|
||||||
<p>High Trust Messaging for the Enterprise.</p>
|
<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>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
class="ai-guide-screenshot"
|
class="ai-guide-screenshot"
|
||||||
alt="Screenshot"
|
alt="Screenshot"
|
||||||
src="{% static 'img/integrations/setup_mattermost_2.png' %}">
|
src="{% static 'img/integrations/setup_mattermost_2.png' %}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row ai-step">
|
<div class="row ai-step">
|
||||||
@ -63,7 +63,7 @@
|
|||||||
|
|
||||||
<h2>Integration Settings</h2>
|
<h2>Integration Settings</h2>
|
||||||
|
|
||||||
<form method="post" class="form-horizontal" action="{% url 'hc-add-mattermost' %}">
|
<form method="post" class="form-horizontal">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="form-group {{ form.value.css_classes }}">
|
<div class="form-group {{ form.value.css_classes }}">
|
||||||
<label for="callback-url" class="col-sm-2 control-label">
|
<label for="callback-url" class="col-sm-2 control-label">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user