Skip to content

Commit

Permalink
feat: ajout du chemin de fer dans l'espace d'échanges et la documenta…
Browse files Browse the repository at this point in the history
…tion (#649)

## Description

🎸 Ajout du chemin de fer sur les vues de detail de `Forum` et de `Topic`


## Type de changement

🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une
fonctionnalité).
🎨 changement d'UI

### Points d'attention

🦺 prise en compte du top_level parent pour déterminer si le `Forum`
appartient à l'espace d'échanges ou à la documentation
🦺 les liens vers documentation sont nécessairement `/documentation`
🦺 l'espace d'échange est le premier forum public de niveau 0, les liens
vers ce forum sont remplacés par `/topics/`

🦺 #651 requise pour cette PR 🦺

### Captures d'écran (optionnel)

Thème de la documentation


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/252596bc-eb0a-4435-9731-b0779cc90194)

Fiche pratique dans un thème de la documentation


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/c4c9bbb0-6ef4-4c87-95b0-eee9b26f8d03)

Topic dans une fiche pratique


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/2729ac62-f663-46aa-bdb2-2e4b670f0fe5)

Sous forum dans l'espace d'échanges


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/fd6e702b-ab1d-42a0-9b1f-0eb2a5b7988d)

Topic dans un sous forum de l'espace d'échanges


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/378375b6-3281-4060-9ed8-532425a3b83f)

Topic dans l'espace d'échanges


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/73dc6607-678f-4620-9be3-829185a30099)
  • Loading branch information
vincentporte authored and calummackervoy committed Jun 5, 2024
1 parent 28a8078 commit 770a47f
Show file tree
Hide file tree
Showing 18 changed files with 479 additions and 25 deletions.
3 changes: 2 additions & 1 deletion lacommunaute/forum/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ def upvoted_by(self, create, extracted, **kwargs):

class CategoryForumFactory(ForumFactory):
type = Forum.FORUM_CAT
name = factory.Sequence(lambda n: f"Theme {n}")

@factory.post_generation
def with_child(self, create, extracted, **kwargs):
if not create or not extracted:
return

ForumFactory(parent=self, with_public_perms=True, with_image=True)
ForumFactory(parent=self, with_public_perms=True, with_image=True, name=f"{self.name} - Forum")
14 changes: 14 additions & 0 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ def count_unanswered_topics(self):

def upvotes_count(self):
return self.upvotes.count()

@cached_property
def is_in_documentation_area(self):
return self.type == Forum.FORUM_CAT or (
self.get_ancestors() and self.get_ancestors().first().type == Forum.FORUM_CAT
)

@cached_property
def is_toplevel_discussion_area(self):
return self == Forum.objects.filter(kind=Forum_Kind.PUBLIC_FORUM, lft=1, level=0).first()

@cached_property
def is_newsfeed(self):
return self.kind == Forum_Kind.NEWS
139 changes: 139 additions & 0 deletions lacommunaute/forum/tests/__snapshots__/tests_views.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# serializer version: 1
# name: TestBreadcrumb.test_category_forum[category_forum]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>

</li>


</ol>
</nav>
'''
# ---
# name: TestBreadcrumb.test_child_category_forum[child_category_forum]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>

</li>


<li class="breadcrumb-item">
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="forum" href="/forum/a-category-[PK of Forum]/">A Category</a>
</li>



</ol>
</nav>
'''
# ---
# name: TestBreadcrumb.test_forum[forum]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="topics_breadcrumb" href="/topics/">Espace d'échanges</a>

</li>


</ol>
</nav>
'''
# ---
# name: TestBreadcrumb.test_grandchild_category_forum[grandchild_category_forum]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>

</li>


<li class="breadcrumb-item">
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="forum" href="/forum/b-category-[PK of Forum]/">B Category</a>
</li>



<li class="breadcrumb-item">
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="forum" href="/forum/b-category-forum-[PK of Forum]/">B Category - Forum</a>
</li>



</ol>
</nav>
'''
# ---
# name: TestBreadcrumb.test_newsfeed_forum[newsfeed_forum]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="newsfeed_breadcrumb" href="/news/">Actualités</a>

</li>


</ol>
</nav>
'''
# ---
# name: TestBreadcrumb.test_sub_discussion_area_forum[sub_discussion_area_forum]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="topics_breadcrumb" href="/topics/">Espace d'échanges</a>

</li>




</ol>
</nav>
'''
# ---
# name: TestBreadcrumb.test_sub_forum[sub_forum]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="topics_breadcrumb" href="/topics/">Espace d'échanges</a>

</li>


<li class="breadcrumb-item">
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="forum" href="/forum/b-forum-[PK of Forum]/">B Forum</a>
</li>



</ol>
</nav>
'''
# ---
40 changes: 39 additions & 1 deletion lacommunaute/forum/tests/tests_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.test import TestCase

from lacommunaute.forum.enums import Kind as ForumKind
from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory
from lacommunaute.forum.models import Forum
from lacommunaute.forum_conversation.factories import TopicFactory
from lacommunaute.users.factories import UserFactory
Expand Down Expand Up @@ -69,3 +69,41 @@ def test_image_url(self):
forum.image.url.split("?")[0], f"{settings.MEDIA_URL}{settings.AWS_STORAGE_BUCKET_NAME}/{forum.image.name}"
)
self.assertIn("AWSAccessKeyId=", forum.image.url)

def test_is_in_documentation_area(self):
top_level_category_forum = CategoryForumFactory(with_child=True)
documentation_forum = top_level_category_forum.children.first()
sub_documentation_forum = ForumFactory(parent=documentation_forum)

top_level_forum = ForumFactory()
forum = ForumFactory(parent=top_level_forum)

self.assertTrue(top_level_category_forum.is_in_documentation_area)
self.assertTrue(documentation_forum.is_in_documentation_area)
self.assertTrue(sub_documentation_forum.is_in_documentation_area)
self.assertFalse(top_level_forum.is_in_documentation_area)
self.assertFalse(forum.is_in_documentation_area)

def test_is_toplevel_discussion_area(self):
discussion_area_forum = ForumFactory()
sub_discussion_area_forum = ForumFactory(parent=discussion_area_forum)
forum = ForumFactory()
sub_forum = ForumFactory(parent=forum)
private_forum = ForumFactory(kind=ForumKind.PRIVATE_FORUM)
news_forum = ForumFactory(kind=ForumKind.NEWS)

self.assertTrue(discussion_area_forum.is_toplevel_discussion_area)
self.assertFalse(sub_discussion_area_forum.is_toplevel_discussion_area)
self.assertFalse(forum.is_toplevel_discussion_area)
self.assertFalse(sub_forum.is_toplevel_discussion_area)
self.assertFalse(private_forum.is_toplevel_discussion_area)
self.assertFalse(news_forum.is_toplevel_discussion_area)

def test_is_newsfeed(self):
news_forum = ForumFactory(kind=ForumKind.NEWS)
discussion_area_forum = ForumFactory()
private_forum = ForumFactory(kind=ForumKind.PRIVATE_FORUM)

self.assertTrue(news_forum.is_newsfeed)
self.assertFalse(discussion_area_forum.is_newsfeed)
self.assertFalse(private_forum.is_newsfeed)
73 changes: 70 additions & 3 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest # noqa
from django.contrib.contenttypes.models import ContentType
from django.template.defaultfilters import truncatechars_html
from django.test import RequestFactory, TestCase
Expand All @@ -11,6 +12,7 @@
from lacommunaute.forum_conversation.forms import PostForm
from lacommunaute.forum_conversation.models import Topic
from lacommunaute.users.factories import UserFactory
from lacommunaute.utils.testing import parse_response_to_soup


faker = Faker()
Expand Down Expand Up @@ -286,15 +288,17 @@ def test_show_add_forum_button_for_superuser_if_forum_is_category_type(self):
)

def test_siblings_in_context(self):
forum = CategoryForumFactory(with_public_perms=True, with_child=True)
forum = CategoryForumFactory(with_public_perms=True)
ForumFactory.create_batch(3, parent=forum, with_public_perms=True)
child_forum = forum.get_children().first()
url = reverse("forum_extension:forum", kwargs={"pk": child_forum.pk, "slug": child_forum.slug})

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

self.assertEqual(response.context_data["forums"].get(), child_forum)
self.assertEqual(response.context_data["parent_forum"], forum)
self.assertEqual(response.context_data["forums"].count(), 3)
for f in forum.get_children():
self.assertContains(response, f.name)

def test_next_url_in_context(self):
response = self.client.get(self.url)
Expand Down Expand Up @@ -427,3 +431,66 @@ def test_banner_display_on_subcategory_forum(self):
forum = category_forum.get_children().first()
response = self.client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
self.assertContains(response, forum.image.url.split("=")[0])


@pytest.fixture(name="discussion_area_forum")
def discussion_area_forum_fixture():
return ForumFactory(with_public_perms=True, name="A Forum")


class TestBreadcrumb:
def test_sub_discussion_area_forum(self, client, db, snapshot, discussion_area_forum):
forum = ForumFactory(parent=discussion_area_forum, with_public_perms=True, name="b")
response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
assert response.status_code == 200
content = parse_response_to_soup(response, selector="nav.c-breadcrumb")
assert str(content) == snapshot(name="sub_discussion_area_forum")

def test_forum(self, client, db, snapshot, discussion_area_forum):
forum = ForumFactory(with_public_perms=True)
response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
assert response.status_code == 200
content = parse_response_to_soup(response, selector="nav.c-breadcrumb")
assert str(content) == snapshot(name="forum")

def test_sub_forum(self, client, db, snapshot, discussion_area_forum):
parent_forum = ForumFactory(with_public_perms=True, name="B Forum")
forum = ForumFactory(parent=parent_forum, with_public_perms=True)
response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
assert response.status_code == 200
content = parse_response_to_soup(response, selector="nav.c-breadcrumb", replace_in_href=[parent_forum])
assert str(content) == snapshot(name="sub_forum")

def test_category_forum(self, client, db, snapshot, discussion_area_forum):
forum = CategoryForumFactory(with_public_perms=True)
response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
assert response.status_code == 200
content = parse_response_to_soup(response, selector="nav.c-breadcrumb")
assert str(content) == snapshot(name="category_forum")

def test_child_category_forum(self, client, db, snapshot, discussion_area_forum):
parent_forum = CategoryForumFactory(with_child=True, with_public_perms=True, name="A Category")
forum = parent_forum.get_children().first()
response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
assert response.status_code == 200
content = parse_response_to_soup(response, selector="nav.c-breadcrumb", replace_in_href=[parent_forum])
assert str(content) == snapshot(name="child_category_forum")

def test_grandchild_category_forum(self, client, db, snapshot, discussion_area_forum):
parent_forum = CategoryForumFactory(with_public_perms=True, with_child=True, name="B Category")
forum = ForumFactory(parent=parent_forum.get_children().first(), with_public_perms=True)
response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
assert response.status_code == 200
content = parse_response_to_soup(
response,
selector="nav.c-breadcrumb",
replace_in_href=[parent_forum, parent_forum.get_children().first()],
)
assert str(content) == snapshot(name="grandchild_category_forum")

def test_newsfeed_forum(self, client, db, snapshot, discussion_area_forum):
forum = ForumFactory(kind="NEWS", with_public_perms=True)
response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug}))
assert response.status_code == 200
content = parse_response_to_soup(response, selector="nav.c-breadcrumb")
assert str(content) == snapshot(name="newsfeed_forum")
5 changes: 2 additions & 3 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ def get_context_data(self, **kwargs):
)
.filter(type=Topic.TOPIC_ANNOUNCE)
)
if forum.parent and forum.parent.type == Forum.FORUM_CAT:
context["forums"] = Forum.objects.filter(parent=forum.parent).order_by("lft")
context["parent_forum"] = forum.parent
if forum.parent and forum.is_in_documentation_area:
context["forums"] = forum.get_siblings(include_self=True)
return context


Expand Down
Loading

0 comments on commit 770a47f

Please sign in to comment.