Browse Source

The "Add Telegram" page shows a project picker. cc: #336

pull/340/head
Pēteris Caune 5 years ago
parent
commit
7060d49306
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 42 additions and 15 deletions
  1. +3
    -2
      hc/front/tests/test_add_telegram.py
  2. +4
    -3
      hc/front/views.py
  3. +35
    -10
      templates/integrations/add_telegram.html

+ 3
- 2
hc/front/tests/test_add_telegram.py View File

@ -23,8 +23,9 @@ class AddTelegramTestCase(BaseTestCase):
payload = signing.dumps((123, "group", "My Group"))
self.client.login(username="[email protected]", 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")


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

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


+ 35
- 10
templates/integrations/add_telegram.html View File

@ -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 <strong>{{ chat_name }}</strong>. Sound good?
named <strong>{{ chat_name }}</strong>.
</p>
</div>
<form method="post" class="text-center">
{% csrf_token %}
<h2>Integration Settings</h2>
<form id="add-telegram" method="post" class="form-horizontal">
{% csrf_token %}
<div class="form-group">
<label class="col-sm-3 control-label">Project</label>
<div class="col-sm-8">
<select name="project" class="selectpicker">
{% for project in projects %}
<option value="{{ project.code }}">{{ project }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-8">
<button type="submit" class="btn btn-default">
<img class="ai-icon" src="{% static 'img/integrations/telegram.png' %}" alt="Telegram" />
Connect Telegram
</button>
</div>
</div>
</form>
<button type="submit" class="btn btn-lg btn-default">
<img class="ai-icon" src="{% static 'img/integrations/telegram.png' %}" alt="Telegram" />
Yes, connect Telegram
</button>
</form>
</div>
{% else %}
<p>If your team uses <a href="https://telegram.org/">Telegram</a>,
you can set up {% site_name %} to post status updates directly to an
@ -94,3 +111,11 @@
</div>
</div>
{% endblock %}
{% block scripts %}
{% compress js %}
<script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/bootstrap-select.min.js' %}"></script>
{% endcompress %}
{% endblock %}

Loading…
Cancel
Save