forked from GithubBackups/healthchecks
Project code in URL for the "Add MS Teams" page. cc: #336
This commit is contained in:
parent
70ff6c53e4
commit
d0b77febbc
@ -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")
|
||||
|
@ -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("<uuid:code>/checks/", views.channel_checks, name="hc-channel-checks"),
|
||||
path("<uuid:code>/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"),
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -244,7 +244,7 @@
|
||||
<h2>Microsoft Teams</h2>
|
||||
<p>Chat and collaboration platform for Microsoft Office 365 customers.</p>
|
||||
|
||||
<a href="{% url 'hc-add-msteams' %}" class="btn btn-primary">Add Integration</a>
|
||||
<a href="{% url 'hc-add-msteams' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
@ -95,7 +95,7 @@
|
||||
|
||||
<h2>Integration Settings</h2>
|
||||
|
||||
<form method="post" class="form-horizontal" action="{% url 'hc-add-msteams' %}">
|
||||
<form method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
<div class="form-group {{ form.value.css_classes }}">
|
||||
<label for="post-url" class="col-sm-2 control-label">Webhook URL</label>
|
||||
|
Loading…
x
Reference in New Issue
Block a user