Browse Source

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

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

+ 5
- 3
hc/front/tests/test_add_trello.py View File

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


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

@ -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("<uuid:code>/checks/", views.channel_checks, name="hc-channel-checks"),
path("<uuid:code>/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"),


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

@ -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,
}


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

@ -352,7 +352,7 @@
<h2>Trello</h2>
<p>Create a Trello card when a check goes down.</p>
<a href="{% url 'hc-add-trello' %}" class="btn btn-primary">Add Integration</a>
<a href="{% url 'hc-add-trello' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}


Loading…
Cancel
Save