Browse Source

Update Telegram instructions. Fix redirect after login when adding Telegram integration.

pull/340/head
Pēteris Caune 5 years ago
parent
commit
29e016d0fc
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
8 changed files with 36 additions and 8 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +8
    -2
      hc/accounts/views.py
  3. +7
    -0
      hc/front/tests/test_add_telegram.py
  4. +1
    -0
      hc/front/urls.py
  5. +13
    -1
      hc/front/views.py
  6. BIN
      static/img/integrations/setup_telegram_3.png
  7. +1
    -1
      templates/integrations/add_slack_btn.html
  8. +5
    -4
      templates/integrations/add_telegram.html

+ 1
- 0
CHANGELOG.md View File

@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- API security: check channel ownership when setting check's channels - API security: check channel ownership when setting check's channels
- API: update check's "alert_after" field when changing schedule - API: update check's "alert_after" field when changing schedule
- API: validate channel identifiers before creating/updating a check (#335) - API: validate channel identifiers before creating/updating a check (#335)
- Fix redirect after login when adding Telegram integration
## v1.13.0 - 2020-02-13 ## v1.13.0 - 2020-02-13


+ 8
- 2
hc/accounts/views.py View File

@ -1,4 +1,5 @@
from datetime import timedelta as td from datetime import timedelta as td
from urllib.parse import urlparse
import uuid import uuid
from django.conf import settings from django.conf import settings
@ -42,12 +43,17 @@ NEXT_WHITELIST = (
"hc-p-channels", "hc-p-channels",
"hc-add-slack", "hc-add-slack",
"hc-add-pushover", "hc-add-pushover",
"hc-add-telegram",
) )
def _is_whitelisted(path):
def _is_whitelisted(redirect_url):
if not redirect_url:
return False
parsed = urlparse(redirect_url)
try: try:
match = resolve(path)
match = resolve(parsed.path)
except Resolver404: except Resolver404:
return False return False


+ 7
- 0
hc/front/tests/test_add_telegram.py View File

@ -34,6 +34,13 @@ class AddTelegramTestCase(BaseTestCase):
self.assertEqual(c.telegram_name, "My Group") self.assertEqual(c.telegram_name, "My Group")
self.assertEqual(c.project, self.project) self.assertEqual(c.project, self.project)
def test_it_handles_bad_signature(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url + "?bad-signature")
self.assertContains(r, "Incorrect Link")
self.assertFalse(Channel.objects.exists())
@patch("hc.api.transports.requests.request") @patch("hc.api.transports.requests.request")
def test_it_sends_invite(self, mock_get): def test_it_sends_invite(self, mock_get):
data = { data = {


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

@ -30,6 +30,7 @@ channel_urls = [
), ),
path("add_discord/", views.add_discord_complete, name="hc-add-discord-complete"), path("add_discord/", views.add_discord_complete, name="hc-add-discord-complete"),
path("add_pushover/", views.add_pushover_help), path("add_pushover/", views.add_pushover_help),
path("telegram/", views.add_telegram_help),
path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"), path("telegram/bot/", views.telegram_bot, name="hc-telegram-webhook"),
path("add_pdc/", views.add_pdc_help), path("add_pdc/", views.add_pdc_help),
path("add_slack/", views.add_slack_help), path("add_slack/", views.add_slack_help),


+ 13
- 1
hc/front/views.py View File

@ -1398,12 +1398,24 @@ def telegram_bot(request):
return HttpResponse() return HttpResponse()
def add_telegram_help(request):
ctx = {
"page": "channels",
"bot_name": settings.TELEGRAM_BOT_NAME,
}
return render(request, "integrations/add_telegram.html", ctx)
@login_required @login_required
def add_telegram(request): def add_telegram(request):
chat_id, chat_type, chat_name = None, None, None chat_id, chat_type, chat_name = None, None, None
qs = request.META["QUERY_STRING"] qs = request.META["QUERY_STRING"]
if qs: if qs:
chat_id, chat_type, chat_name = signing.loads(qs, max_age=600)
try:
chat_id, chat_type, chat_name = signing.loads(qs, max_age=600)
except signing.BadSignature:
return render(request, "bad_link.html")
if request.method == "POST": if request.method == "POST":
project = _get_project_for_user(request, request.POST.get("project")) project = _get_project_for_user(request, request.POST.get("project"))


BIN
static/img/integrations/setup_telegram_3.png View File

Before After
Width: 833  |  Height: 383  |  Size: 26 KiB Width: 787  |  Height: 555  |  Size: 35 KiB

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

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load humanize static hc_extras %} {% load humanize static hc_extras %}
{% block title %}Add Slack - {% site_name %}{% endblock %}
{% block title %}Slack Integration for {% site_name %}{% endblock %}
{% block content %} {% block content %}
<div class="row"> <div class="row">


+ 5
- 4
templates/integrations/add_telegram.html View File

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load compress humanize static hc_extras %} {% load compress humanize static hc_extras %}
{% block title %}Notification Channels - {% site_name %}{% endblock %}
{% block title %}Telegram Integration for {% site_name %}{% endblock %}
{% block content %} {% block content %}
@ -23,8 +23,7 @@
</p> </p>
</div> </div>
<h2>Integration Settings</h2>
<h2>Integration Settings</h2>
<form id="add-telegram" method="post" class="form-horizontal"> <form id="add-telegram" method="post" class="form-horizontal">
{% csrf_token %} {% csrf_token %}
<div class="form-group"> <div class="form-group">
@ -98,7 +97,9 @@
<p>Click or tap on the confirmation link, and <p>Click or tap on the confirmation link, and
{% site_name %} will open in a browser window asking you to {% site_name %} will open in a browser window asking you to
confirm the new integration.</p> confirm the new integration.</p>
<p>Confirm the integration, and it's done!</p>
<p>Select the project you want the Telegram integration added to,
click on "Connect Telegram", and it's done!</p>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<img <img


Loading…
Cancel
Save