diff --git a/swh/web/assets/src/bundles/webapp/webapp.css b/swh/web/assets/src/bundles/webapp/webapp.css --- a/swh/web/assets/src/bundles/webapp/webapp.css +++ b/swh/web/assets/src/bundles/webapp/webapp.css @@ -675,3 +675,27 @@ .sidebar-collapse .swh-search-navbar { right: 4rem; } + +.swh-corner-ribbon { + width: 200px; + background: #fecd1b; + color: #e20026; + position: absolute; + text-align: center; + line-height: 50px; + letter-spacing: 1px; + box-shadow: 0 0 3px rgba(0, 0, 0, 0.3); + top: 55px; + right: -50px; + left: auto; + transform: rotate(45deg); + z-index: 2000; +} + +@media screen and (max-width: 600px) { + .swh-corner-ribbon { + line-height: 30px; + top: 53px; + right: -65px; + } +} diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -256,6 +256,7 @@ # To avoid django.template.base.VariableDoesNotExist errors # when rendering templates when standard Django user is logged in. request.user.backend = "django.contrib.auth.backends.ModelBackend" + site_base_url = request.build_absolute_uri("/") return { "swh_object_icons": swh_object_icons, "available_languages": None, @@ -263,9 +264,15 @@ "oidc_enabled": bool(config["keycloak"]["server_url"]), "browsers_supported_image_mimes": browsers_supported_image_mimes, "keycloak": config["keycloak"], - "site_base_url": request.build_absolute_uri("/"), + "site_base_url": site_base_url, "DJANGO_SETTINGS_MODULE": os.environ["DJANGO_SETTINGS_MODULE"], "status": config["status"], + "swh_web_staging": any( + [ + server_name in site_base_url + for server_name in config["staging_server_names"] + ] + ), } diff --git a/swh/web/config.py b/swh/web/config.py --- a/swh/web/config.py +++ b/swh/web/config.py @@ -16,6 +16,11 @@ SWH_WEB_INTERNAL_SERVER_NAME = "archive.internal.softwareheritage.org" +STAGING_SERVER_NAMES = [ + "webapp.staging.swh.network", + "webapp.internal.staging.swh.network", +] + SETTINGS_DIR = os.path.dirname(settings.__file__) DEFAULT_CONFIG = { @@ -104,6 +109,7 @@ }, ), "metadata_search_backend": ("string", "swh-indexer-storage"), # or "swh-search" + "staging_server_names": ("list", STAGING_SERVER_NAMES), } swhweb_config = {} # type: Dict[str, Any] diff --git a/swh/web/settings/tests.py b/swh/web/settings/tests.py --- a/swh/web/settings/tests.py +++ b/swh/web/settings/tests.py @@ -104,6 +104,7 @@ ) else: ALLOWED_HOSTS += ["testserver", SWH_WEB_INTERNAL_SERVER_NAME] + ALLOWED_HOSTS += get_config()["staging_server_names"] # Silent DEBUG output when running unit tests LOGGING["handlers"]["console"]["level"] = "INFO" # type: ignore diff --git a/swh/web/templates/layout.html b/swh/web/templates/layout.html --- a/swh/web/templates/layout.html +++ b/swh/web/templates/layout.html @@ -227,6 +227,9 @@
+ {% if swh_web_staging %} +
Staging
+ {% endif %} {% block content %}{% endblock %}
diff --git a/swh/web/tests/test_templates.py b/swh/web/tests/test_templates.py new file mode 100644 --- /dev/null +++ b/swh/web/tests/test_templates.py @@ -0,0 +1,25 @@ +# Copyright (C) 2021 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import random + +from swh.web.common.utils import reverse +from swh.web.config import STAGING_SERVER_NAMES +from swh.web.tests.django_asserts import assert_contains, assert_not_contains +from swh.web.tests.utils import check_http_get_response + + +def test_layout_without_staging_ribbon(client): + url = reverse("swh-web-homepage") + resp = check_http_get_response(client, url, status_code=200) + assert_not_contains(resp, "swh-corner-ribbon") + + +def test_layout_with_staging_ribbon(client): + url = reverse("swh-web-homepage") + resp = check_http_get_response( + client, url, status_code=200, server_name=random.choice(STAGING_SERVER_NAMES), + ) + assert_contains(resp, "swh-corner-ribbon")