Browse Source

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

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

+ 7
- 3
hc/front/tests/test_add_msteams.py View File

@ -3,17 +3,21 @@ from hc.test import BaseTestCase
class AddMsTeamsTestCase(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): def test_instructions_work(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get("/integrations/add_msteams/")
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": "https://example.com/foo"} form = {"value": "https://example.com/foo"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", 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() c = Channel.objects.get()
self.assertEqual(c.kind, "msteams") self.assertEqual(c.kind, "msteams")


+ 1
- 1
hc/front/urls.py View File

@ -44,7 +44,6 @@ channel_urls = [
path("add_trello/", views.add_trello, name="hc-add-trello"), path("add_trello/", views.add_trello, name="hc-add-trello"),
path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"), path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"),
path("add_apprise/", views.add_apprise, name="hc-add-apprise"), 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("add_prometheus/", views.add_prometheus, name="hc-add-prometheus"),
path("<uuid:code>/checks/", views.channel_checks, name="hc-channel-checks"), path("<uuid:code>/checks/", views.channel_checks, name="hc-channel-checks"),
path("<uuid:code>/name/", views.update_channel_name, name="hc-channel-name"), 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_email/", views.add_email, name="hc-add-email"),
path("add_matrix/", views.add_matrix, name="hc-add-matrix"), path("add_matrix/", views.add_matrix, name="hc-add-matrix"),
path("add_mattermost/", views.add_mattermost, name="hc-add-mattermost"), 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("add_webhook/", views.add_webhook, name="hc-add-webhook"),
path("badges/", views.badges, name="hc-badges"), path("badges/", views.badges, name="hc-badges"),
path("checks/", views.my_checks, name="hc-checks"), path("checks/", views.my_checks, name="hc-checks"),


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

@ -1534,20 +1534,22 @@ def trello_settings(request):
@login_required @login_required
def add_msteams(request):
def add_msteams(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="msteams")
channel = Channel(project=project, kind="msteams")
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", "project": request.project, "form": form}
ctx = {"page": "channels", "project": project, "form": form}
return render(request, "integrations/add_msteams.html", ctx) return render(request, "integrations/add_msteams.html", ctx)


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

@ -244,7 +244,7 @@
<h2>Microsoft Teams</h2> <h2>Microsoft Teams</h2>
<p>Chat and collaboration platform for Microsoft Office 365 customers.</p> <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>
<li> <li>


+ 1
- 1
templates/integrations/add_msteams.html View File

@ -95,7 +95,7 @@
<h2>Integration Settings</h2> <h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-msteams' %}">
<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="post-url" class="col-sm-2 control-label">Webhook URL</label> <label for="post-url" class="col-sm-2 control-label">Webhook URL</label>


Loading…
Cancel
Save