Skip to content

Commit

Permalink
Affiche le lien "Exports du contenu" sur la page publique
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink committed Jun 16, 2024
1 parent 975e859 commit ab0591f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
<h3>{% trans "Administration" %}</h3>

<ul>
{% if administration_actions.show_exports_request %}
<li>
{% include "tutorialv2/includes/sidebar/exports.part.html" %}
</li>
{% endif %}

{% if administration_actions.show_versions_history_link %}
<li>
<a href="{% url "content:history" content.pk content.slug_repository %}" class="ico-after history blue">
Expand Down
3 changes: 2 additions & 1 deletion templates/tutorialv2/includes/sidebar/exports.part.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{% load get_item %}
{% load i18n %}

<a href="#exports-modal" class="open-modal ico-after gear blue"
data-exports-id="{{ content.pk }}"
data-exports-api="{% url "api:content:list_exports" content.pk %}"
data-request-export-api="{% url "api:content:generate_export" content.pk %}">
{% trans "Exports du contenu" %}
{{ public_actions.messages|get_item:"export_content" }}
</a>

<div class="modal modal-flex" id="exports-modal" data-modal-close="Fermer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ <h3>{% trans "Version publique" %}</h3>
</li>
{% endif %}

{% if public_actions.show_exports_request %}
<li>
{% include "tutorialv2/includes/sidebar/exports.part.html" %}
</li>
{% endif %}

{% if public_actions.show_content_revoke %}
<li>
<a href="#unpublish" class="ico-after open-modal cross blue">
Expand Down
10 changes: 10 additions & 0 deletions zds/tutorialv2/tests/tests_views/tests_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ def test_sidebar_items(self):
self.assertContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

# Create a new draft version:
Expand All @@ -71,13 +73,15 @@ def test_sidebar_items(self):
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertContains(draft_page, "Modified introduction")
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

# Ask validation:
Expand All @@ -87,12 +91,14 @@ def test_sidebar_items(self):
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertContains(draft_page, ValidationActions.messages["validation_is_same"])
# Validation page:
validation_page = self.client.get(
Expand All @@ -101,6 +107,7 @@ def test_sidebar_items(self):
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(validation_page, PublicActionsState.messages["export_content"])
self.assertNotContains(validation_page, ValidationActions.messages["validation_is_same"])

# Now a new draft version, to have different version from validation:
Expand All @@ -126,13 +133,15 @@ def test_sidebar_items(self):
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
# Draft page:
draft_page = self.client.get(reverse("content:view", args=[article.pk, article.slug]), follow=False)
self.assertContains(draft_page, "Modified introduction")
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])
# Validation page:
validation_page = self.client.get(
Expand All @@ -141,4 +150,5 @@ def test_sidebar_items(self):
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(validation_page, PublicActionsState.messages["export_content"])
self.assertNotContains(validation_page, ValidationActions.messages["validation_is_same"])
11 changes: 6 additions & 5 deletions zds/tutorialv2/views/display/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def show_block(self) -> bool:
self.enabled
and self.is_allowed
and (
self.show_exports_request()
or self.show_versions_history_link()
self.show_versions_history_link()
or self.show_events_history_link()
or self.show_opinion_publish()
or self.show_opinion_moderated()
Expand All @@ -29,9 +28,6 @@ def show_block(self) -> bool:
)
)

def show_exports_request(self) -> bool:
return self.is_allowed

def show_versions_history_link(self) -> bool:
return self.is_allowed

Expand All @@ -56,6 +52,7 @@ class PublicActionsState:
"draft_is_same": _("La version brouillon est identique à cette version."),
"draft_is_more_recent": _("La version brouillon est plus récente que cette version."),
"public_is_same": _("La version publique est identique à cette version."),
"export_content": _("Exports du contenu"),
}

def __init__(self, user, content: PublishableContent, versioned_content: VersionedContent):
Expand All @@ -74,6 +71,7 @@ def show_block(self) -> bool:
and self.is_author_or_staff
and (
self.show_stats_link()
or self.show_exports_request()
or self.show_identical_public_version_message()
or self.show_identical_draft_version_message()
or self.show_more_recent_draft_version_link()
Expand All @@ -85,6 +83,9 @@ def show_block(self) -> bool:
)
)

def show_exports_request(self) -> bool:
return self.is_author_or_staff and self.in_public and self.is_public_page

def show_stats_link(self) -> bool:
return self.is_author_or_staff and self.in_public

Expand Down

0 comments on commit ab0591f

Please sign in to comment.