Skip to content

Commit

Permalink
✨(header) add maintenance message
Browse files Browse the repository at this point in the history
Add a maintenance message on the header if the
environment variable `MAINTENANCE_HEADER_MSG` is true.
GN-1012
  • Loading branch information
igobranco committed Nov 11, 2022
1 parent a802f3b commit 5ece2ba
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 10 deletions.
2 changes: 2 additions & 0 deletions env.d/development
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ WEB_ANALYTICS_ID=UA-123456789-1

# Google Tag Manager
# GOOGLE_TAG_MANAGER_ID=GTM-WHZV2TB

# MAINTENANCE_HEADER_MSG=true
5 changes: 5 additions & 0 deletions sites/nau/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- ✨(header) add maintenance message on header if setting
`MAINTENANCE_HEADER_MSG` is true

### Changed

- ⬆️(nau) upgrade richie to v2.17.0
Expand Down
18 changes: 13 additions & 5 deletions sites/nau/src/backend/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-10-19 17:04+0100\n"
"POT-Creation-Date: 2022-11-11 16:33+0000\n"
"PO-Revision-Date: 2021-07-14 16:32+0100\n"
"Last-Translator: Ivo Branco <ivo.branco@fccn.pt>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -114,15 +114,15 @@ msgstr ""
msgid "{base_url:s}/u/(username)"
msgstr ""

#: nau/settings.py:337
#: nau/settings.py:338
msgid "Teaser"
msgstr ""

#: nau/settings.py:425 nau/settings.py:440
#: nau/settings.py:426 nau/settings.py:441
msgid "English"
msgstr "English"

#: nau/settings.py:425 nau/settings.py:448
#: nau/settings.py:426 nau/settings.py:449
msgid "Portuguese"
msgstr "Português"

Expand Down Expand Up @@ -160,7 +160,15 @@ msgstr "/en/legal/cookies/"
msgid "Need Help"
msgstr ""

#: templates/richie/base.html:40
#: templates/richie/base.html:35
msgid "Go to homepage"
msgstr ""

#: templates/richie/base.html:36
msgid "In maintenance"
msgstr ""

#: templates/richie/base.html:48
msgid "Help"
msgstr ""

Expand Down
20 changes: 15 additions & 5 deletions sites/nau/src/backend/locale/pt/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-10-19 17:04+0100\n"
"POT-Creation-Date: 2022-11-11 16:33+0000\n"
"PO-Revision-Date: 2021-07-14 16:32+0100\n"
"Last-Translator: Ivo Branco <ivo.branco@fccn.pt>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -114,15 +114,15 @@ msgstr "Perfil"
msgid "{base_url:s}/u/(username)"
msgstr ""

#: nau/settings.py:337
#: nau/settings.py:338
msgid "Teaser"
msgstr ""

#: nau/settings.py:425 nau/settings.py:440
#: nau/settings.py:426 nau/settings.py:441
msgid "English"
msgstr "English"

#: nau/settings.py:425 nau/settings.py:448
#: nau/settings.py:426 nau/settings.py:449
msgid "Portuguese"
msgstr "Português"

Expand Down Expand Up @@ -160,7 +160,17 @@ msgstr "/pt/legal/cookies/"
msgid "Need Help"
msgstr "Preciso de Ajuda"

#: templates/richie/base.html:40
#: templates/richie/base.html:35
#, fuzzy
#| msgid "Back to home"
msgid "Go to homepage"
msgstr "Voltar à página principal"

#: templates/richie/base.html:36
msgid "In maintenance"
msgstr "Em manutenção"

#: templates/richie/base.html:48
msgid "Help"
msgstr "Ajuda"

Expand Down
14 changes: 14 additions & 0 deletions sites/nau/src/backend/nau/maintenance/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Jira Service desk widget context processor
"""
from django.conf import settings


def maintenance_header_message_setting(request):
"""
Maintenance header message
"""
context = {}
if hasattr(settings, "MAINTENANCE_HEADER_MSG"):
context["MAINTENANCE_HEADER_MSG"] = getattr(settings, "MAINTENANCE_HEADER_MSG")
return context
5 changes: 5 additions & 0 deletions sites/nau/src/backend/nau/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class Base(StyleguideMixin, DRFMixin, RichieCoursesConfigurationMixin, Configura
"nau.facebook_pixel.context_processors.facebook_pixel_setting",
"nau.google_tag_manager.context_processors.google_tag_manager_setting",
"nau.help_desk.context_processors.help_desk_url_setting",
"nau.maintenance.context_processors.maintenance_header_message_setting",
],
"loaders": [
"django.template.loaders.filesystem.Loader",
Expand Down Expand Up @@ -649,6 +650,10 @@ class Base(StyleguideMixin, DRFMixin, RichieCoursesConfigurationMixin, Configura

CMS_LIMIT_TTL_CACHE_FUNCTION = "nau.cache.cache_ttl.limit_course_page_cache_ttl"

MAINTENANCE_HEADER_MSG = values.BooleanValue(
False, environ_name="MAINTENANCE_HEADER_MSG", environ_prefix=None
)

# pylint: disable=invalid-name
@property
def ENVIRONMENT(self):
Expand Down
63 changes: 63 additions & 0 deletions sites/nau/src/backend/nau/tests/test_maintenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
End-to-end tests for the course detail view
"""
from django.test.utils import override_settings

from cms.test_utils.testcases import CMSTestCase
from richie.apps.courses.factories import CourseFactory


class JiraServiceDeskWidgetBaseTemplateRenderingCMSTestCase(CMSTestCase):
"""
Test case that verifies if the maintenance message is being displayed and the search on header
if not visible.
"""

@override_settings(MAINTENANCE_HEADER_MSG=True)
def test_template_base_maintenance_is_true(self):
"""
Test if the maintenance message is visible on header if MAINTENANCE_HEADER_MSG is true.
"""
course = CourseFactory()
page = course.extended_object
page.publish("en")

url = course.extended_object.get_absolute_url()
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.assertContains(response, "topbar__maintenance")
self.assertNotContains(response, "topbar__search")

def test_template_base_maintenance_is_absent(self):
"""
Test if the maintenance message is not visible if the `MAINTENANCE_HEADER_MSG` not defined
and the top bar search is visible.
"""
course = CourseFactory()
page = course.extended_object
page.publish("en")

url = course.extended_object.get_absolute_url()
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.assertNotContains(response, "topbar__maintenance")
self.assertContains(response, "topbar__search")

@override_settings(MAINTENANCE_HEADER_MSG=False)
def test_template_base_maintenance_is_false(self):
"""
Test if the maintenance message is not visible if the `MAINTENANCE_HEADER_MSG` is False
and the top bar search is visible.
"""
course = CourseFactory()
page = course.extended_object
page.publish("en")

url = course.extended_object.get_absolute_url()
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.assertNotContains(response, "topbar__maintenance")
self.assertContains(response, "topbar__search")
8 changes: 8 additions & 0 deletions sites/nau/src/backend/templates/richie/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@
{% endblock body_header %}

{% block topbar_searchbar %}
{% if MAINTENANCE_HEADER_MSG %}
<div class="topbar__maintenance">
<a href="/" title="{% trans "Go to homepage" %}" rel="home">
{% trans "In maintenance" %}
</a>
</div>
{% else %}
<div class="topbar__search richie-react richie-react--root-search-suggest-field"
data-props='{"courseSearchPageUrl": "{% page_url 'courses-search' %}"}'></div>
{% endif %}
{% endblock topbar_searchbar %}

{% block topbar_contact %}
Expand Down
14 changes: 14 additions & 0 deletions sites/nau/src/frontend/scss/extras/components/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,18 @@
}
}

&__maintenance {
display: flex;
align-items: center;
justify-content: center;
font-size: $font-size-base;
box-shadow: 4px 2px 12px rgb(10 31 80 / 45%);
border-radius: 2rem;
border: solid red;
padding: 0.5rem;
a {
font-size: 1.5rem;
}
}

}

0 comments on commit 5ece2ba

Please sign in to comment.