Browse Source

Add "Ping Key Required" dialog

In the Details page, if the user click "Ping Now",
and the project is using {ping-key}/{slug} URLs,
but the ping key is not set, then show a
"Ping Key Required" message instead of trying to ping
and invalid URL.
pull/563/head
Pēteris Caune 3 years ago
parent
commit
b5f7ec1324
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 56 additions and 0 deletions
  1. +24
    -0
      hc/front/tests/test_details.py
  2. +32
    -0
      templates/front/details.html

+ 24
- 0
hc/front/tests/test_details.py View File

@ -24,6 +24,7 @@ class DetailsTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertContains(r, "How To Ping", status_code=200)
self.assertContains(r, "ping-now")
# The page should contain timezone strings
self.assertContains(r, "Europe/Riga")
@ -153,3 +154,26 @@ class DetailsTestCase(BaseTestCase):
# The summary for Dec. 2019 should be "–"
self.assertContains(r, "<td>–</td>", html=True)
def test_it_handles_no_ping_key(self):
self.project.show_slugs = True
self.project.ping_key = None
self.project.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertContains(r, "Ping Key Required", status_code=200)
self.assertNotContains(r, "ping-now")
def test_it_handles_no_ping_key_for_readonly_user(self):
self.project.show_slugs = True
self.project.ping_key = None
self.project.save()
self.bobs_membership.role = "r"
self.bobs_membership.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertNotContains(r, "Ping Key Required", status_code=200)
self.assertNotContains(r, "ping-now")

+ 32
- 0
templates/front/details.html View File

@ -142,10 +142,19 @@
</form>
{% endif %}
{% if project.show_slugs and not project.ping_key %}
{% if rw %}
<button
data-toggle="modal"
data-target="#no-ping-key-modal"
class="btn btn-sm btn-default">Ping Now!</button>
{% endif %}
{% else %}
<button
id="ping-now"
data-url="{{ check.url }}"
class="btn btn-sm btn-default">Ping Now!</button>
{% endif %}
</div>
</div>
@ -317,6 +326,29 @@
{% include "front/filtering_rules_modal.html" %}
{% include "front/copy_modal.html" %}
{% if rw and project.show_slugs and not project.ping_key %}
<div id="no-ping-key-modal" class="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4>Ping Key Required</h4>
</div>
<div class="modal-body">
<p>This project does not yet have a ping key.<br />
To ping this check, please generate the
ping key first.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a href="{% url 'hc-project-settings' project.code %}" class="btn btn-primary">Open Project Settings</a>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %}
{% block scripts %}


Loading…
Cancel
Save