From dee189be33ad0c9f7989ab6d8536114c2bf1f613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 25 Feb 2020 11:24:32 +0200 Subject: [PATCH] Project code in URL for the "Add Trello" page. cc: #336 --- hc/front/tests/test_add_trello.py | 8 +++++--- hc/front/urls.py | 2 +- hc/front/views.py | 12 +++++++----- templates/front/channels.html | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hc/front/tests/test_add_trello.py b/hc/front/tests/test_add_trello.py index 55a9406e..0a4ec436 100644 --- a/hc/front/tests/test_add_trello.py +++ b/hc/front/tests/test_add_trello.py @@ -5,8 +5,10 @@ from hc.api.models import Channel from hc.test import BaseTestCase -class AddPagerTreeTestCase(BaseTestCase): - url = "/integrations/add_trello/" +class AddTrelloTestCase(BaseTestCase): + def setUp(self): + super(AddTrelloTestCase, self).setUp() + self.url = "/projects/%s/add_trello/" % self.project.code @override_settings(TRELLO_APP_KEY="foo") def test_instructions_work(self): @@ -29,7 +31,7 @@ class AddPagerTreeTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.post(self.url, form) - self.assertRedirects(r, "/integrations/") + self.assertRedirects(r, self.channels_url) c = Channel.objects.get() self.assertEqual(c.kind, "trello") diff --git a/hc/front/urls.py b/hc/front/urls.py index aa12f1cc..e011d56c 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -35,7 +35,6 @@ channel_urls = [ path("add_pushover/", views.add_pushover_help), path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"), path("add_telegram/", views.add_telegram, name="hc-add-telegram"), - path("add_trello/", views.add_trello, name="hc-add-trello"), path("add_trello/settings/", views.trello_settings, name="hc-trello-settings"), path("/checks/", views.channel_checks, name="hc-channel-checks"), path("/name/", views.update_channel_name, name="hc-channel-name"), @@ -69,6 +68,7 @@ project_urls = [ path("add_pushover/", views.add_pushover, name="hc-add-pushover"), path("add_shell/", views.add_shell, name="hc-add-shell"), path("add_sms/", views.add_sms, name="hc-add-sms"), + path("add_trello/", views.add_trello, name="hc-add-trello"), path("add_victorops/", views.add_victorops, name="hc-add-victorops"), path("add_webhook/", views.add_webhook, name="hc-add-webhook"), path("add_whatsapp/", views.add_whatsapp, name="hc-add-whatsapp"), diff --git a/hc/front/views.py b/hc/front/views.py index 9602212a..30a58c74 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1477,18 +1477,20 @@ def add_whatsapp(request, code): @login_required -def add_trello(request): +def add_trello(request, code): if settings.TRELLO_APP_KEY is None: raise Http404("trello integration is not available") + project = _get_project_for_user(request, code) if request.method == "POST": - channel = Channel(project=request.project, kind="trello") + channel = Channel(project=project, kind="trello") channel.value = request.POST["settings"] channel.save() channel.assign_all_checks() - return redirect("hc-channels") + return redirect("hc-p-channels", project.code) + return_url = settings.SITE_ROOT + reverse("hc-add-trello", args=[project.code]) authorize_url = "https://trello.com/1/authorize?" + urlencode( { "expiration": "never", @@ -1496,13 +1498,13 @@ def add_trello(request): "scope": "read,write", "response_type": "token", "key": settings.TRELLO_APP_KEY, - "return_url": settings.SITE_ROOT + reverse("hc-add-trello"), + "return_url": return_url, } ) ctx = { "page": "channels", - "project": request.project, + "project": project, "authorize_url": authorize_url, } diff --git a/templates/front/channels.html b/templates/front/channels.html index a3943e64..7e3fd5e6 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -352,7 +352,7 @@

Trello

Create a Trello card when a check goes down.

- Add Integration + Add Integration {% endif %}