From 7060d49306276fcd7b523334ef0f93a8d53481e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 25 Feb 2020 14:51:39 +0200 Subject: [PATCH] The "Add Telegram" page shows a project picker. cc: #336 --- hc/front/tests/test_add_telegram.py | 5 +-- hc/front/views.py | 7 ++-- templates/integrations/add_telegram.html | 45 ++++++++++++++++++------ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/hc/front/tests/test_add_telegram.py b/hc/front/tests/test_add_telegram.py index 5b106c94..35c1014b 100644 --- a/hc/front/tests/test_add_telegram.py +++ b/hc/front/tests/test_add_telegram.py @@ -23,8 +23,9 @@ class AddTelegramTestCase(BaseTestCase): payload = signing.dumps((123, "group", "My Group")) self.client.login(username="alice@example.org", password="password") - r = self.client.post(self.url + "?" + payload, {}) - self.assertRedirects(r, "/integrations/") + form = {"project": str(self.project.code)} + r = self.client.post(self.url + "?" + payload, form) + self.assertRedirects(r, self.channels_url) c = Channel.objects.get() self.assertEqual(c.kind, "telegram") diff --git a/hc/front/views.py b/hc/front/views.py index 438beb54..e161c71a 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1430,7 +1430,8 @@ def add_telegram(request): chat_id, chat_type, chat_name = signing.loads(qs, max_age=600) if request.method == "POST": - channel = Channel(project=request.project, kind="telegram") + project = _get_project_for_user(request, request.POST.get("project")) + channel = Channel(project=project, kind="telegram") channel.value = json.dumps( {"id": chat_id, "type": chat_type, "name": chat_name} ) @@ -1438,11 +1439,11 @@ def add_telegram(request): channel.assign_all_checks() messages.success(request, "The Telegram integration has been added!") - return redirect("hc-channels") + return redirect("hc-p-channels", project.code) ctx = { "page": "channels", - "project": request.project, + "projects": request.profile.projects(), "chat_id": chat_id, "chat_type": chat_type, "chat_name": chat_name, diff --git a/templates/integrations/add_telegram.html b/templates/integrations/add_telegram.html index 9eefee4c..9e44e6ea 100644 --- a/templates/integrations/add_telegram.html +++ b/templates/integrations/add_telegram.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load humanize static hc_extras %} +{% load compress humanize static hc_extras %} {% block title %}Notification Channels - {% site_name %}{% endblock %} @@ -19,18 +19,35 @@ {% else %} a Telegram chat {% endif %} - named {{ chat_name }}. Sound good? + named {{ chat_name }}.

+ -
- {% csrf_token %} +

Integration Settings

+ + + {% csrf_token %} +
+ +
+ +
+
+ +
+
+ +
+
+
- - - {% else %}

If your team uses Telegram, you can set up {% site_name %} to post status updates directly to an @@ -94,3 +111,11 @@ {% endblock %} + +{% block scripts %} +{% compress js %} + + + +{% endcompress %} +{% endblock %}