Skip to content

Commit

Permalink
Gérer l'accès aux pages privées (#216)
Browse files Browse the repository at this point in the history
* Manage access to restricted pages

* Update set_config command
  • Loading branch information
Ash-Crow authored Sep 17, 2024
1 parent 93afb20 commit ef743a7
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 12 deletions.
Binary file modified blog/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
16 changes: 8 additions & 8 deletions blog/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-10 18:18+0200\n"
"PO-Revision-Date: 2024-09-10 18:18+0200\n"
"POT-Creation-Date: 2024-09-17 12:04+0200\n"
"PO-Revision-Date: 2024-09-17 12:04+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
Expand Down Expand Up @@ -87,19 +87,19 @@ msgstr "Catégories"
msgid "Posts per page"
msgstr "Articles par page"

#: blog/models.py:203 blog/templates/blog/blog_index_page.html:76
#: blog/models.py:203 blog/templates/blog/blog_index_page.html:77
msgid "Filter by category"
msgstr "Filtrer par catégorie"

#: blog/models.py:204 blog/templates/blog/blog_index_page.html:93
#: blog/models.py:204 blog/templates/blog/blog_index_page.html:94
msgid "Filter by tag"
msgstr "Filtrer par étiquette"

#: blog/models.py:205 blog/templates/blog/blog_index_page.html:110
#: blog/models.py:205 blog/templates/blog/blog_index_page.html:111
msgid "Filter by author"
msgstr "Filtrer par auteur"

#: blog/models.py:207 blog/templates/blog/blog_index_page.html:125
#: blog/models.py:207 blog/templates/blog/blog_index_page.html:126
msgid "Filter by source"
msgstr "Filtrer par source"

Expand Down Expand Up @@ -167,8 +167,8 @@ msgstr "Aucun article trouvé."
msgid "Posted by:"
msgstr "Écrit par :"

#: blog/templates/blog/blog_index_page.html:71
#: blog/templates/blog/blog_index_page.html:73
#: blog/templates/blog/blog_index_page.html:72
#: blog/templates/blog/blog_index_page.html:74
msgid "Filters"
msgstr "Filtres"

Expand Down
1 change: 1 addition & 0 deletions blog/templates/blog/blog_index_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<h1>
{{ page.title }}
{% if extra_title %}: {{ extra_title }}{% endif %}
{% include "content_manager/blocks/page_visibility.html" %}
</h1>
{% endif %}

Expand Down
3 changes: 3 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def show_toolbar(request):

WAGTAILADMIN_PATH = os.getenv("WAGTAILADMIN_PATH", "cms-admin/")

WAGTAIL_FRONTEND_LOGIN_URL = LOGIN_URL = f"/{WAGTAILADMIN_PATH}login/"
WAGTAIL_PASSWORD_REQUIRED_TEMPLATE = "content_manager/password_required.html"

# Disable Gravatar service
WAGTAIL_GRAVATAR_PROVIDER_URL = None

Expand Down
Binary file modified content_manager/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
45 changes: 43 additions & 2 deletions content_manager/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-10 18:18+0200\n"
"PO-Revision-Date: 2024-09-10 18:18+0200\n"
"POT-Creation-Date: 2024-09-17 12:04+0200\n"
"PO-Revision-Date: 2024-09-17 12:06+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
Expand Down Expand Up @@ -1255,6 +1255,22 @@ msgstr "Dans cette rubrique"
msgid "Go to page"
msgstr "Aller à la page"

#: content_manager/templates/content_manager/blocks/page_visibility.html:4
msgid "Page visibility restricted to logged in users only"
msgstr "Visibilité de la page restreinte aux utilisateurs connectés"

#: content_manager/templates/content_manager/blocks/page_visibility.html:6
msgid "Page visibility restricted by group"
msgstr "Visibilité de la page restreinte par groupe"

#: content_manager/templates/content_manager/blocks/page_visibility.html:8
msgid "Page visibility restricted by password"
msgstr "Visibilité de la page restreinte par mot de passe"

#: content_manager/templates/content_manager/blocks/page_visibility.html:10
msgid "Page with restricted visibility"
msgstr "Visibilité de la page restreinte"

#: content_manager/templates/content_manager/blocks/tabs.html:3
msgid "Tabs group"
msgstr "Groupe d’onglets"
Expand All @@ -1263,6 +1279,31 @@ msgstr "Groupe d’onglets"
msgid "Watch on the site"
msgstr "Voir sur le site"

#: content_manager/templates/content_manager/password_required.html:5
#: content_manager/templates/content_manager/password_required.html:15
msgid "Password required"
msgstr "Mot de passe requis"

#: content_manager/templates/content_manager/password_required.html:24
msgid "You need a password to access this page."
msgstr "L’accès à cette page nécessite un mot de passe."

#: content_manager/templates/content_manager/password_required.html:35
msgid "Password:"
msgstr "Mot de passe :"

#: content_manager/templates/content_manager/password_required.html:42
msgid "Show password"
msgstr "Afficher le mot de passe"

#: content_manager/templates/content_manager/password_required.html:47
msgid "Show"
msgstr "Afficher"

#: content_manager/templates/content_manager/password_required.html:63
msgid "Continue"
msgstr "Continuer"

#: content_manager/templates/content_manager/tags_list_page.html:31
#: content_manager/views.py:46 content_manager/views.py:77
msgid "Tags"
Expand Down
16 changes: 15 additions & 1 deletion content_manager/management/commands/set_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.conf import settings
from django.core.management.base import BaseCommand
from wagtail.models import Site
from wagtail.models import Group, Site

from content_manager.models import CmsDsfrConfig

Expand All @@ -14,6 +14,8 @@ def handle(self, *args, **kwargs):
Sets the site hostname and site_name,
and imports contents from the config.json file if present.
"""

# Set the site hostname and site_name
if "http://" in settings.HOST_URL or "https://" in settings.HOST_URL:
raise ValueError(
"""The HOST_URL environment variable must contain the domain name only,
Expand All @@ -25,6 +27,18 @@ def handle(self, *args, **kwargs):
site.site_name = settings.WAGTAIL_SITE_NAME
site.save()

# Translate the names of the default user groups.
mods_group = Group.objects.filter(name="Moderators").first()
if mods_group:
mods_group.name = "Modérateurs"
mods_group.save()

editors_group = Group.objects.filter(name="Editors").first()
if editors_group:
editors_group.name = "Éditeurs"
editors_group.save()

# Import config.json
if isfile("config.json"):
with open("config.json") as config_file:
config_data = json.load(config_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<h1 {% if block.value.large %}class="fr-display--sm"{% endif %}>
{{ page.title }}
{% if extra_title %}: {{ extra_title }}{% endif %}
{% include "content_manager/blocks/page_visibility.html" %}
</h1>
{% endif %}
{% if page.header_cta_text %}{{ page.header_cta_text|richtext }}{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% load i18n %}
{% if page.get_view_restrictions %}
{% if page.get_view_restrictions.first.restriction_type == "login" %}
{% translate "Page visibility restricted to logged in users only" as page_visibility %}
{% elif page.get_view_restrictions.first.restriction_type == "groups" %}
{% translate "Page visibility restricted by group" as page_visibility %}
{% elif page.get_view_restrictions.first.restriction_type == "password" %}
{% translate "Page visibility restricted by password" as page_visibility %}
{% else %}
{% translate "Page with restricted visibility" as page_visibility %}
{% endif %}
<button class="fr-icon-eye-off-line fr-btn fr-btn--tertiary-no-outline"
type="button"
id="cmsfr-page-visibility-btn"
aria-describedby="cmsfr-page-visibility">{{ page_visibility }}</button>
<span class="fr-tooltip fr-placement"
id="cmsfr-page-visibility"
role="tooltip"
aria-hidden="true">{{ page_visibility }}</span>
{% endif %}
7 changes: 6 additions & 1 deletion content_manager/templates/content_manager/content_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
{% include "content_manager/blocks/heading.html" %}
<div class="fr-container fr-pt-4w">
{% include "content_manager/blocks/breadcrumbs.html" %}
{% if not page.header_with_title %}<h1>{{ page.title }}</h1>{% endif %}
{% if not page.header_with_title %}
<h1>
{{ page.title }}
{% include "content_manager/blocks/page_visibility.html" %}
</h1>
{% endif %}
</div>

{% include "content_manager/blocks/messages.html" %}
Expand Down
76 changes: 76 additions & 0 deletions content_manager/templates/content_manager/password_required.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends "base.html" %}
{% load widget_tweaks i18n static dsfr_tags %}

{% block title %}
<title>{% translate "Password required" %} — {{ settings.content_manager.CmsDsfrConfig.site_title }}</title>
{% endblock title %}

{% block content %}
<div class="fr-container fr-container--fluid fr-my-md-14v">
<div class="fr-grid-row fr-grid-row-gutters fr-grid-row--center">
<div class="fr-col-12 fr-col-md-8 fr-col-lg-6">
<div class="fr-container fr-background-alt--grey fr-px-md-0 fr-py-10v fr-py-md-14v">
<div class="fr-grid-row fr-grid-row-gutters fr-grid-row--center">
<div class="fr-col-12 fr-col-md-9 fr-col-lg-8">
<h1>{% translate "Password required" %}</h1>

<form action="{{ action_url }}" method="post">
<fieldset class="fr-fieldset"
id="login-form-fieldset"
aria-labelledby="login-form-fieldset-legend login-form-fieldset-messages">
<legend class="fr-fieldset__legend" id="login-form-fieldset-legend">
<h2>
{% block password_required_message %}
<p>{% translate "You need a password to access this page." %}</p>
{% endblock password_required_message %}
</h2>
</legend>

{% csrf_token %}

{{ form.non_field_errors }}

<div class="fr-fieldset__element">
<div class="fr-password{% if form.password.errors %} fr-input-group--error{% endif %}">
<label class="fr-label" for="id_password">{% translate "Password:" %}</label>
{% if form.password.errors %}
{{ form.password |add_class:"fr-password__input fr-input fr-input--error" }}
{% else %}
{{ form.password |add_class:"fr-password__input fr-input" }}
{% endif %}
<div class="fr-password__checkbox fr-checkbox-group fr-checkbox-group--sm">
{% translate "Show password" as show_password %}
<input aria-label="{{ show_password }}"
id="id_password-show"
type="checkbox"
aria-describedby="id_password-show-messages">
<label class="fr-password__checkbox fr-label" for="id_password-show">{% translate "Show" %}</label>
<div class="fr-messages-group"
id="id_password-show-messages"
aria-live="assertive"></div>
</div>
{% if form.password.errors %}
<div id="text-input-error-desc-error" class="fr-error-text">{{ form.password.errors }}</div>
{% endif %}
</div>
</div>

{% for field in form.hidden_fields %}{{ field }}{% endfor %}

<div class="fr-fieldset__element">
<ul class="fr-btns-group">
<li>
{% translate "Continue" as continue_label %}
<input class="fr-btn" type="submit" value="{{ continue_label }}" />
</li>
</ul>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}

0 comments on commit ef743a7

Please sign in to comment.