Skip to content

Commit

Permalink
Teste et corrige l'affichage de quelques éléments de la sidebar des c…
Browse files Browse the repository at this point in the history
…ontenus (#6599)

* Corrige l'affichage des versions identiques dans la sidebar
* Affiche le lien "Exports du contenu" sur la page publique
  • Loading branch information
philippemilink authored Jul 20, 2024
1 parent 3505295 commit ab676f6
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 39 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
39 changes: 31 additions & 8 deletions templates/tutorialv2/includes/sidebar/public_actions.part.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n %}
{% load captureas %}
{% load crispy_forms_tags %}
{% load get_item %}

{% if public_actions.show_block %}
<div class="mobile-menu-bloc mobile-all-links mobile-show-ico" data-title="Version publique">
Expand All @@ -14,26 +15,35 @@ <h3>{% trans "Version publique" %}</h3>
</li>
{% endif %}

{% if public_actions.show_identical_version_message %}
{% if public_actions.show_identical_public_version_message %}
<li class="inactive">
<span class="ico-after pin disabled">
{% trans "La version publique est identique à cette version." %}
{{ public_actions.messages|get_item:"public_is_same" }}
</span>
</li>
{% endif %}

{% if public_actions.show_page_link %}
{% if public_actions.show_identical_draft_version_message %}
<li class="inactive">
<span class="ico-after pin disabled">
{{ public_actions.messages|get_item:"draft_is_same" }}
</span>
</li>
{% endif %}

{% if public_actions.show_more_recent_draft_version_link %}
<li>
<a href="{{ public_content_object.get_absolute_url_online }}" class="ico-after online blue">
{% trans "Voir la page publique" %}
<a href="{{ object.get_absolute_url }}" class="ico-after online blue">
{{ public_actions.messages|get_item:"draft_is_more_recent" }}
</a>
</li>
{% endif %}

{% if public_actions.show_stats_link %}
{% if public_actions.show_page_link %}
<li>
{% url "content:stats-content" content.pk content.slug as stats_url %}
<a href="{{ stats_url }}" class="ico-after stats blue">{% trans "Voir les statistiques" %}</a>
<a href="{{ public_content_object.get_absolute_url_online }}" class="ico-after online blue">
{% trans "Voir la page publique" %}
</a>
</li>
{% endif %}

Expand All @@ -47,6 +57,19 @@ <h3>{% trans "Version publique" %}</h3>
</li>
{% endif %}

{% if public_actions.show_stats_link %}
<li>
{% url "content:stats-content" content.pk content.slug as stats_url %}
<a href="{{ stats_url }}" class="ico-after stats blue">{% trans "Voir les statistiques" %}</a>
</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
3 changes: 2 additions & 1 deletion templates/tutorialv2/includes/sidebar/validation.part.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n %}
{% load crispy_forms_tags %}
{% load captureas %}
{% load get_item %}


{% if display_config.validation_actions.show_validation_actions %}
Expand All @@ -19,7 +20,7 @@ <h3>{% if content.requires_validation %}{% trans "Validation"%}{%else %}{%trans
{% if display_config.validation_actions.show_identical_message %}
<li class="inactive">
<span class="ico-after pin disabled">
{% trans "La version en validation est identique à cette version." %}
{{ display_config.validation_actions.messages|get_item:"validation_is_same" }}
</span>
</li>
{% endif %}
Expand Down
4 changes: 4 additions & 0 deletions zds/tutorialv2/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ def is_public(self, sha: str) -> bool:
"""Return True if the given sha corresponds to the public version, and False otherwise."""
return self.in_public() and sha == self.sha_public

def is_draft_more_recent_than_public(self) -> bool:
"""Return True if there is a draft version more recent than the published version, and False otherwise."""
return self.in_public() and self.in_drafting() and self.sha_public != self.sha_draft

def is_picked(self):
return self.in_public() and self.sha_public == self.sha_picked

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
from zds.tutorialv2.tests import TutorialTestMixin, override_for_contents
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory
from zds.tutorialv2.tests.factories import PublishableContentFactory, ValidationFactory


def request_validation(content):
"""Emulate a proper validation request."""
ValidationFactory(content=content, status="PENDING")
content.sha_validation = content.sha_draft
content.save()
from zds.tutorialv2.tests.utils import request_validation


@override_for_contents()
Expand Down
159 changes: 159 additions & 0 deletions zds/tutorialv2/tests/tests_views/tests_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
from copy import deepcopy

from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from zds.member.tests.factories import ProfileFactory
from zds.tutorialv2.tests import TutorialTestMixin
from zds.tutorialv2.tests.factories import PublishedContentFactory
from zds.tutorialv2.tests.utils import request_validation
from zds.tutorialv2.views.display.config import PublicActionsState, ValidationActions
from zds.utils.tests.factories import LicenceFactory


overridden_zds_app = deepcopy(settings.ZDS_APP)
overridden_zds_app["content"]["repo_private_path"] = settings.BASE_DIR / "contents-private-test"
overridden_zds_app["content"]["repo_public_path"] = settings.BASE_DIR / "contents-public-test"
overridden_zds_app["content"]["extra_content_generation_policy"] = "NONE"


@override_settings(MEDIA_ROOT=settings.BASE_DIR / "media-test")
@override_settings(ZDS_APP=overridden_zds_app)
@override_settings(ES_ENABLED=False)
class DisplayConfigTests(TutorialTestMixin, TestCase):
TEXT_FIRST_MODIFICATION = "Modified introduction"
TEXT_SECOND_MODIFICATION = "Modified Introduction"

def setUp(self):
self.overridden_zds_app = overridden_zds_app
overridden_zds_app["content"]["default_licence_pk"] = LicenceFactory().pk

self.user_author = ProfileFactory().user
self.client.force_login(self.user_author)

# Publish an article:
self.article = PublishedContentFactory(author_list=[self.user_author], type="ARTICLE")

def _new_draft_version(self, text):
# Create a new draft version:
versioned = self.article.load_version()
result = self.client.post(
reverse("content:edit", args=[self.article.pk, self.article.slug]),
{
"title": self.article.title,
"description": self.article.description,
"introduction": text,
"conclusion": "Modified conclusion",
"type": self.article.type,
"subcategory": self.article.subcategory.first().pk,
"last_hash": versioned.compute_hash(),
},
follow=False,
)
self.assertEqual(result.status_code, 302)
self.article.refresh_from_db() # the previous request changes sha_draft

def test_sidebar_items_on_public_page(self):
def common_tests():
public_page = self.client.get(self.article.get_absolute_url_online())

self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
self.assertContains(public_page, PublicActionsState.messages["export_content"])
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])

return public_page

public_page = common_tests()
self.assertContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_more_recent"])

self._new_draft_version(self.TEXT_FIRST_MODIFICATION)

public_page = common_tests()
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])

request_validation(self.article)

public_page = common_tests()
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])

# Now a new draft version, to have different version from validation:
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)

public_page = common_tests()
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(public_page, self.TEXT_SECOND_MODIFICATION)
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])

def test_sidebar_items_on_draft_page(self):
def common_tests():
draft_page = self.client.get(
reverse("content:view", args=[self.article.pk, self.article.slug]), follow=False
)

self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])

return draft_page

draft_page = common_tests()
self.assertContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

self._new_draft_version(self.TEXT_FIRST_MODIFICATION)

draft_page = common_tests()
self.assertContains(draft_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

request_validation(self.article)

draft_page = common_tests()
self.assertContains(draft_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertContains(draft_page, ValidationActions.messages["validation_is_same"])

# Now a new draft version, to have different version from validation:
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)

draft_page = common_tests()
self.assertContains(draft_page, self.TEXT_SECOND_MODIFICATION)
self.assertNotContains(draft_page, self.TEXT_FIRST_MODIFICATION)
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])

def test_sidebar_items_on_validation_page(self):
def common_tests():
validation_page = self.client.get(
reverse("content:validation-view", args=[self.article.pk, self.article.slug]), follow=False
)

self.assertContains(validation_page, self.TEXT_FIRST_MODIFICATION)
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"])

return validation_page

self._new_draft_version(self.TEXT_FIRST_MODIFICATION)
request_validation(self.article)

validation_page = common_tests()

# Now a new draft version, to have different version from validation:
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)

validation_page = common_tests()
self.assertNotContains(validation_page, self.TEXT_SECOND_MODIFICATION)
8 changes: 8 additions & 0 deletions zds/tutorialv2/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from zds.tutorialv2.tests.factories import ValidationFactory


def request_validation(content):
"""Emulate a proper validation request."""
ValidationFactory(content=content, status="PENDING")
content.sha_validation = content.sha_draft
content.save()
Loading

0 comments on commit ab676f6

Please sign in to comment.