From 3f28c04241436e9c496549e0b73e6e819e2b9114 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Tue, 30 May 2023 16:17:12 -0400 Subject: [PATCH] Banner + no create buttons when in read only mode Fix #1095 --- umap/context_processors.py | 12 ++++----- umap/templates/umap/about_summary.html | 4 ++- umap/templates/umap/content.html | 16 ++++++++++++ umap/templates/umap/home.html | 7 ------ umap/templates/umap/navigation.html | 4 ++- umap/tests/test_views.py | 34 ++++++++++++++++++++++++++ umap/views.py | 1 - 7 files changed, 62 insertions(+), 16 deletions(-) diff --git a/umap/context_processors.py b/umap/context_processors.py index 499a82a8..cd377af4 100644 --- a/umap/context_processors.py +++ b/umap/context_processors.py @@ -5,13 +5,13 @@ from . import VERSION def settings(request): return { - 'UMAP_FEEDBACK_LINK': djsettings.UMAP_FEEDBACK_LINK, - 'SITE_NAME': djsettings.SITE_NAME, - 'ENABLE_ACCOUNT_LOGIN': djsettings.ENABLE_ACCOUNT_LOGIN, + "UMAP_FEEDBACK_LINK": djsettings.UMAP_FEEDBACK_LINK, + "SITE_NAME": djsettings.SITE_NAME, + "ENABLE_ACCOUNT_LOGIN": djsettings.ENABLE_ACCOUNT_LOGIN, + "UMAP_READONLY": djsettings.UMAP_READONLY, + "UMAP_DEMO_SITE": djsettings.UMAP_DEMO_SITE, } def version(request): - return { - 'UMAP_VERSION': VERSION - } + return {"UMAP_VERSION": VERSION} diff --git a/umap/templates/umap/about_summary.html b/umap/templates/umap/about_summary.html index c580cf83..7901cb32 100644 --- a/umap/templates/umap/about_summary.html +++ b/umap/templates/umap/about_summary.html @@ -30,7 +30,9 @@
{% spaceless %}
- {% trans "Create a map" %} + {% if not UMAP_READONLY %} + {% trans "Create a map" %} + {% endif %} {% if demo_map %} {% trans "Play with the demo" %} {% endif %} diff --git a/umap/templates/umap/content.html b/umap/templates/umap/content.html index ca7fb698..dbd38ce5 100644 --- a/umap/templates/umap/content.html +++ b/umap/templates/umap/content.html @@ -18,6 +18,22 @@ {% endblock %} {% block content %} + {% if UMAP_READONLY %} +
+
+

+ {% blocktrans %}This instance of uMap is currently in read only mode, no creation/edit is allowed.{% endblocktrans %} +

+
+
+ {% endif %} + {% if UMAP_DEMO_SITE %} +
+
+ {% blocktrans with repo_url="https://github.com/umap-project/umap" stable_url="http://umap.openstreetmap.fr" %}This is a demo instance, used for tests and pre-rolling releases. If you need a stable instance, please use {{ stable_url }}. You can also host your own instance, it's open source!{% endblocktrans %} +
+
+ {% endif %} {% block maincontent %} {% endblock maincontent %} {% endblock content %} diff --git a/umap/templates/umap/home.html b/umap/templates/umap/home.html index b405786e..45bef52d 100644 --- a/umap/templates/umap/home.html +++ b/umap/templates/umap/home.html @@ -3,13 +3,6 @@ {% load umap_tags i18n %} {% block maincontent %} -{% if DEMO_SITE %} -
-
- {% blocktrans with repo_url="https://github.com/umap-project/umap" stable_url="http://umap.openstreetmap.fr" %}This is a demo instance, used for tests and pre-rolling releases. If you need a stable instance, please use {{ stable_url }}. You can also host your own instance, it's open source!{% endblocktrans %} -
-
-{% endif %} {% include "umap/search_bar.html" %} {% include "umap/about_summary.html" %} {% if showcase_map %} diff --git a/umap/templates/umap/navigation.html b/umap/templates/umap/navigation.html index acde349a..58c4d8e6 100644 --- a/umap/templates/umap/navigation.html +++ b/umap/templates/umap/navigation.html @@ -24,6 +24,8 @@
- {% trans "Create a map" %} + {% if not UMAP_READONLY %} + {% trans "Create a map" %} + {% endif %}
diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py index d1f025a7..a4fa8d23 100644 --- a/umap/tests/test_views.py +++ b/umap/tests/test_views.py @@ -162,3 +162,37 @@ def test_stats_basic(client, map, datalayer, user2): "users_active_last_week_count": 1, "users_count": 2, } + + +@pytest.mark.django_db +def test_read_only_displays_message_if_enabled(client, settings): + settings.UMAP_READONLY = True + response = client.get(reverse("home")) + assert ( + "This instance of uMap is currently in read only mode" + in response.content.decode() + ) + + +@pytest.mark.django_db +def test_read_only_does_not_display_message_if_disabled(client, settings): + settings.UMAP_READONLY = False + response = client.get(reverse("home")) + assert ( + "This instance of uMap is currently in read only mode" + not in response.content.decode() + ) + + +@pytest.mark.django_db +def test_read_only_hides_create_buttons_if_enabled(client, settings): + settings.UMAP_READONLY = True + response = client.get(reverse("home")) + assert "Create a map" not in response.content.decode() + + +@pytest.mark.django_db +def test_read_only_shows_create_buttons_if_disabled(client, settings): + settings.UMAP_READONLY = False + response = client.get(reverse("home")) + assert "Create a map" in response.content.decode() diff --git a/umap/views.py b/umap/views.py index 16018c49..ed242369 100644 --- a/umap/views.py +++ b/umap/views.py @@ -125,7 +125,6 @@ class Home(TemplateView, PaginatorMixin): "maps": maps, "demo_map": demo_map, "showcase_map": showcase_map, - "DEMO_SITE": settings.UMAP_DEMO_SITE, } def get_template_names(self):