From b8771b9eb80e9add105c4cbeb6a2cf6a6397eb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 6 Oct 2021 16:12:28 +0300 Subject: [PATCH] Add uuid/slug switcher in the Details page --- hc/front/tests/test_details.py | 17 +++++++++++++++++ hc/front/views.py | 4 ++++ templates/front/details.html | 22 ++++++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/hc/front/tests/test_details.py b/hc/front/tests/test_details.py index 4e34b698..70630a69 100644 --- a/hc/front/tests/test_details.py +++ b/hc/front/tests/test_details.py @@ -177,3 +177,20 @@ class DetailsTestCase(BaseTestCase): r = self.client.get(self.url) self.assertNotContains(r, "Ping Key Required", status_code=200) self.assertNotContains(r, "ping-now") + + def test_it_handles_empty_slug(self): + self.project.show_slugs = True + self.project.save() + + self.client.login(username="alice@example.org", password="password") + r = self.client.get(self.url) + self.assertContains(r, "(unavailable, set name first)", status_code=200) + self.assertNotContains(r, "Copy URL") + self.assertNotContains(r, "ping-now") + + def test_it_saves_url_format_preference(self): + self.client.login(username="alice@example.org", password="password") + self.client.get(self.url + "?urls=slug") + + self.project.refresh_from_db() + self.assertTrue(self.project.show_slugs) diff --git a/hc/front/views.py b/hc/front/views.py index ef017e3a..b9957f25 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -641,6 +641,10 @@ def details(request, code): _refresh_last_active_date(request.profile) check, rw = _get_check_for_user(request, code) + if request.GET.get("urls") in ("uuid", "slug") and rw: + check.project.show_slugs = request.GET["urls"] == "slug" + check.project.save() + channels = Channel.objects.filter(project=check.project) channels = list(channels.order_by("created")) diff --git a/templates/front/details.html b/templates/front/details.html index acb9465b..6a10d18d 100644 --- a/templates/front/details.html +++ b/templates/front/details.html @@ -73,17 +73,27 @@ {% endif %}
-

How To Ping

+

+ How To Ping + {% if rw %} +
+ uuid + slug +
+ {% endif %} +

Keep this check up by making HTTP {% if check.methods == "POST" %}POST{% endif %} requests to this URL:

+ {% if check.url %} {{ check.url }} -

- Or by sending emails to this address: -

+ {% else %} + (unavailable, set name first) + {% endif %} +

Ping by sending email:

{{ check.email }}

You can also explicitly @@ -101,6 +111,7 @@ data-target="#filtering-rules-modal" class="btn btn-sm btn-default">Filtering Rules… {% endif %} + {% if check.url %} + {% endif %}

@@ -142,6 +154,7 @@ {% endif %} + {% if check.url %} {% if project.show_slugs and not project.ping_key %} {% if rw %} {% endif %} + {% endif %}