Skip to content

Commit f3ab831

Browse files
Merge branch 'dev' into en-avant-guingamp
2 parents f7a9eec + ab676f6 commit f3ab831

File tree

9 files changed

+245
-39
lines changed

9 files changed

+245
-39
lines changed

templates/tutorialv2/includes/sidebar/administration_actions.part.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
<h3>{% trans "Administration" %}</h3>
88

99
<ul>
10-
{% if administration_actions.show_exports_request %}
11-
<li>
12-
{% include "tutorialv2/includes/sidebar/exports.part.html" %}
13-
</li>
14-
{% endif %}
15-
1610
{% if administration_actions.show_versions_history_link %}
1711
<li>
1812
<a href="{% url "content:history" content.pk content.slug_repository %}" class="ico-after history blue">

templates/tutorialv2/includes/sidebar/exports.part.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
{% load get_item %}
12
{% load i18n %}
23

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

1011
<div class="modal modal-flex" id="exports-modal" data-modal-close="Fermer">

templates/tutorialv2/includes/sidebar/public_actions.part.html

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% load i18n %}
22
{% load captureas %}
33
{% load crispy_forms_tags %}
4+
{% load get_item %}
45

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

17-
{% if public_actions.show_identical_version_message %}
18+
{% if public_actions.show_identical_public_version_message %}
1819
<li class="inactive">
1920
<span class="ico-after pin disabled">
20-
{% trans "La version publique est identique à cette version." %}
21+
{{ public_actions.messages|get_item:"public_is_same" }}
2122
</span>
2223
</li>
2324
{% endif %}
2425

25-
{% if public_actions.show_page_link %}
26+
{% if public_actions.show_identical_draft_version_message %}
27+
<li class="inactive">
28+
<span class="ico-after pin disabled">
29+
{{ public_actions.messages|get_item:"draft_is_same" }}
30+
</span>
31+
</li>
32+
{% endif %}
33+
34+
{% if public_actions.show_more_recent_draft_version_link %}
2635
<li>
27-
<a href="{{ public_content_object.get_absolute_url_online }}" class="ico-after online blue">
28-
{% trans "Voir la page publique" %}
36+
<a href="{{ object.get_absolute_url }}" class="ico-after online blue">
37+
{{ public_actions.messages|get_item:"draft_is_more_recent" }}
2938
</a>
3039
</li>
3140
{% endif %}
3241

33-
{% if public_actions.show_stats_link %}
42+
{% if public_actions.show_page_link %}
3443
<li>
35-
{% url "content:stats-content" content.pk content.slug as stats_url %}
36-
<a href="{{ stats_url }}" class="ico-after stats blue">{% trans "Voir les statistiques" %}</a>
44+
<a href="{{ public_content_object.get_absolute_url_online }}" class="ico-after online blue">
45+
{% trans "Voir la page publique" %}
46+
</a>
3747
</li>
3848
{% endif %}
3949

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

60+
{% if public_actions.show_stats_link %}
61+
<li>
62+
{% url "content:stats-content" content.pk content.slug as stats_url %}
63+
<a href="{{ stats_url }}" class="ico-after stats blue">{% trans "Voir les statistiques" %}</a>
64+
</li>
65+
{% endif %}
66+
67+
{% if public_actions.show_exports_request %}
68+
<li>
69+
{% include "tutorialv2/includes/sidebar/exports.part.html" %}
70+
</li>
71+
{% endif %}
72+
5073
{% if public_actions.show_content_revoke %}
5174
<li>
5275
<a href="#unpublish" class="ico-after open-modal cross blue">

templates/tutorialv2/includes/sidebar/validation.part.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% load i18n %}
22
{% load crispy_forms_tags %}
33
{% load captureas %}
4+
{% load get_item %}
45

56

67
{% if display_config.validation_actions.show_validation_actions %}
@@ -19,7 +20,7 @@ <h3>{% if content.requires_validation %}{% trans "Validation"%}{%else %}{%trans
1920
{% if display_config.validation_actions.show_identical_message %}
2021
<li class="inactive">
2122
<span class="ico-after pin disabled">
22-
{% trans "La version en validation est identique à cette version." %}
23+
{{ display_config.validation_actions.messages|get_item:"validation_is_same" }}
2324
</span>
2425
</li>
2526
{% endif %}

zds/tutorialv2/models/database.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ def is_public(self, sha: str) -> bool:
302302
"""Return True if the given sha corresponds to the public version, and False otherwise."""
303303
return self.in_public() and sha == self.sha_public
304304

305+
def is_draft_more_recent_than_public(self) -> bool:
306+
"""Return True if there is a draft version more recent than the published version, and False otherwise."""
307+
return self.in_public() and self.in_drafting() and self.sha_public != self.sha_draft
308+
305309
def is_picked(self):
306310
return self.in_public() and self.sha_public == self.sha_picked
307311

zds/tutorialv2/tests/tests_views/tests_contentvalidationview.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
from zds.tutorialv2.tests import TutorialTestMixin, override_for_contents
55
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory
66
from zds.tutorialv2.tests.factories import PublishableContentFactory, ValidationFactory
7-
8-
9-
def request_validation(content):
10-
"""Emulate a proper validation request."""
11-
ValidationFactory(content=content, status="PENDING")
12-
content.sha_validation = content.sha_draft
13-
content.save()
7+
from zds.tutorialv2.tests.utils import request_validation
148

159

1610
@override_for_contents()
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
from copy import deepcopy
2+
3+
from django.conf import settings
4+
from django.test import TestCase
5+
from django.test.utils import override_settings
6+
from django.urls import reverse
7+
from django.utils.translation import gettext_lazy as _
8+
9+
from zds.member.tests.factories import ProfileFactory
10+
from zds.tutorialv2.tests import TutorialTestMixin
11+
from zds.tutorialv2.tests.factories import PublishedContentFactory
12+
from zds.tutorialv2.tests.utils import request_validation
13+
from zds.tutorialv2.views.display.config import PublicActionsState, ValidationActions
14+
from zds.utils.tests.factories import LicenceFactory
15+
16+
17+
overridden_zds_app = deepcopy(settings.ZDS_APP)
18+
overridden_zds_app["content"]["repo_private_path"] = settings.BASE_DIR / "contents-private-test"
19+
overridden_zds_app["content"]["repo_public_path"] = settings.BASE_DIR / "contents-public-test"
20+
overridden_zds_app["content"]["extra_content_generation_policy"] = "NONE"
21+
22+
23+
@override_settings(MEDIA_ROOT=settings.BASE_DIR / "media-test")
24+
@override_settings(ZDS_APP=overridden_zds_app)
25+
@override_settings(ES_ENABLED=False)
26+
class DisplayConfigTests(TutorialTestMixin, TestCase):
27+
TEXT_FIRST_MODIFICATION = "Modified introduction"
28+
TEXT_SECOND_MODIFICATION = "Modified Introduction"
29+
30+
def setUp(self):
31+
self.overridden_zds_app = overridden_zds_app
32+
overridden_zds_app["content"]["default_licence_pk"] = LicenceFactory().pk
33+
34+
self.user_author = ProfileFactory().user
35+
self.client.force_login(self.user_author)
36+
37+
# Publish an article:
38+
self.article = PublishedContentFactory(author_list=[self.user_author], type="ARTICLE")
39+
40+
def _new_draft_version(self, text):
41+
# Create a new draft version:
42+
versioned = self.article.load_version()
43+
result = self.client.post(
44+
reverse("content:edit", args=[self.article.pk, self.article.slug]),
45+
{
46+
"title": self.article.title,
47+
"description": self.article.description,
48+
"introduction": text,
49+
"conclusion": "Modified conclusion",
50+
"type": self.article.type,
51+
"subcategory": self.article.subcategory.first().pk,
52+
"last_hash": versioned.compute_hash(),
53+
},
54+
follow=False,
55+
)
56+
self.assertEqual(result.status_code, 302)
57+
self.article.refresh_from_db() # the previous request changes sha_draft
58+
59+
def test_sidebar_items_on_public_page(self):
60+
def common_tests():
61+
public_page = self.client.get(self.article.get_absolute_url_online())
62+
63+
self.assertNotContains(public_page, PublicActionsState.messages["public_is_same"])
64+
self.assertContains(public_page, PublicActionsState.messages["export_content"])
65+
self.assertNotContains(public_page, ValidationActions.messages["validation_is_same"])
66+
67+
return public_page
68+
69+
public_page = common_tests()
70+
self.assertContains(public_page, PublicActionsState.messages["draft_is_same"])
71+
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
72+
73+
self._new_draft_version(self.TEXT_FIRST_MODIFICATION)
74+
75+
public_page = common_tests()
76+
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
77+
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
78+
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
79+
80+
request_validation(self.article)
81+
82+
public_page = common_tests()
83+
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
84+
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
85+
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
86+
87+
# Now a new draft version, to have different version from validation:
88+
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)
89+
90+
public_page = common_tests()
91+
self.assertNotContains(public_page, self.TEXT_FIRST_MODIFICATION)
92+
self.assertNotContains(public_page, self.TEXT_SECOND_MODIFICATION)
93+
self.assertNotContains(public_page, PublicActionsState.messages["draft_is_same"])
94+
self.assertContains(public_page, PublicActionsState.messages["draft_is_more_recent"])
95+
96+
def test_sidebar_items_on_draft_page(self):
97+
def common_tests():
98+
draft_page = self.client.get(
99+
reverse("content:view", args=[self.article.pk, self.article.slug]), follow=False
100+
)
101+
102+
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_same"])
103+
self.assertNotContains(draft_page, PublicActionsState.messages["draft_is_more_recent"])
104+
self.assertNotContains(draft_page, PublicActionsState.messages["export_content"])
105+
106+
return draft_page
107+
108+
draft_page = common_tests()
109+
self.assertContains(draft_page, PublicActionsState.messages["public_is_same"])
110+
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])
111+
112+
self._new_draft_version(self.TEXT_FIRST_MODIFICATION)
113+
114+
draft_page = common_tests()
115+
self.assertContains(draft_page, self.TEXT_FIRST_MODIFICATION)
116+
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
117+
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])
118+
119+
request_validation(self.article)
120+
121+
draft_page = common_tests()
122+
self.assertContains(draft_page, self.TEXT_FIRST_MODIFICATION)
123+
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
124+
self.assertContains(draft_page, ValidationActions.messages["validation_is_same"])
125+
126+
# Now a new draft version, to have different version from validation:
127+
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)
128+
129+
draft_page = common_tests()
130+
self.assertContains(draft_page, self.TEXT_SECOND_MODIFICATION)
131+
self.assertNotContains(draft_page, self.TEXT_FIRST_MODIFICATION)
132+
self.assertNotContains(draft_page, PublicActionsState.messages["public_is_same"])
133+
self.assertNotContains(draft_page, ValidationActions.messages["validation_is_same"])
134+
135+
def test_sidebar_items_on_validation_page(self):
136+
def common_tests():
137+
validation_page = self.client.get(
138+
reverse("content:validation-view", args=[self.article.pk, self.article.slug]), follow=False
139+
)
140+
141+
self.assertContains(validation_page, self.TEXT_FIRST_MODIFICATION)
142+
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_same"])
143+
self.assertNotContains(validation_page, PublicActionsState.messages["public_is_same"])
144+
self.assertNotContains(validation_page, PublicActionsState.messages["draft_is_more_recent"])
145+
self.assertNotContains(validation_page, PublicActionsState.messages["export_content"])
146+
self.assertNotContains(validation_page, ValidationActions.messages["validation_is_same"])
147+
148+
return validation_page
149+
150+
self._new_draft_version(self.TEXT_FIRST_MODIFICATION)
151+
request_validation(self.article)
152+
153+
validation_page = common_tests()
154+
155+
# Now a new draft version, to have different version from validation:
156+
self._new_draft_version(self.TEXT_SECOND_MODIFICATION)
157+
158+
validation_page = common_tests()
159+
self.assertNotContains(validation_page, self.TEXT_SECOND_MODIFICATION)

zds/tutorialv2/tests/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from zds.tutorialv2.tests.factories import ValidationFactory
2+
3+
4+
def request_validation(content):
5+
"""Emulate a proper validation request."""
6+
ValidationFactory(content=content, status="PENDING")
7+
content.sha_validation = content.sha_draft
8+
content.save()

0 commit comments

Comments
 (0)