diff --git a/lacommunaute/forum_member/forms.py b/lacommunaute/forum_member/forms.py index a542e23fd..c9328e5fc 100644 --- a/lacommunaute/forum_member/forms.py +++ b/lacommunaute/forum_member/forms.py @@ -5,14 +5,6 @@ from lacommunaute.forum_member.models import ForumProfile -class JoinForumForm(forms.Form): - invitation_token = forms.HiddenInput() - - def join_forum(self): - if not self.forum.members_group.user_set.filter(id=self.user.id).exists(): - self.forum.members_group.user_set.add(self.user) - - class ForumProfileForm(BaseForumProfileForm): cv = forms.FileField(label="Curriculum Vitae", required=False) linkedin = forms.URLField(label="Lien vers votre profil LinkedIn", required=False) diff --git a/lacommunaute/forum_member/tests/tests_view.py b/lacommunaute/forum_member/tests/tests_view.py index 1009979fc..82405a0bc 100644 --- a/lacommunaute/forum_member/tests/tests_view.py +++ b/lacommunaute/forum_member/tests/tests_view.py @@ -1,5 +1,3 @@ -import uuid - from django.contrib.auth.models import Group from django.test import RequestFactory, TestCase from django.urls import reverse @@ -12,7 +10,7 @@ from lacommunaute.forum_member.models import ForumProfile from lacommunaute.forum_member.shortcuts import get_forum_member_display_name from lacommunaute.forum_member.views import ForumProfileUpdateView -from lacommunaute.users.factories import DEFAULT_PASSWORD, UserFactory +from lacommunaute.users.factories import UserFactory PermissionHandler = get_class("forum_permission.handler", "PermissionHandler") @@ -104,19 +102,6 @@ def test_profile_in_group(self): self.assertEqual(response.context["forum_profiles"][0].user.first_name, "bob_is_a_member") self.assertContains(response, "1 membre") - def test_join_url_is_shown(self): - self.client.force_login(self.profile.user) - response = self.client.get(self.url) - self.assertContains( - response, - reverse( - "members:join_forum_form", - kwargs={ - "token": self.forum.invitation_token, - }, - ), - ) - def test_queries_number(self): profiles = ForumProfileFactory.create_batch(10) self.forum.members_group.user_set.add(*[profile.user for profile in profiles]) @@ -127,72 +112,6 @@ def test_queries_number(self): self.client.get(self.url) -class JoinForumLandingView(TestCase): - def test_token_doesnt_exists(self): - user = UserFactory() - wrong_token = uuid.uuid4() - self.client.login(username=user.username, password=DEFAULT_PASSWORD) - url = reverse("members:join_forum_form", kwargs={"token": wrong_token}) - response = self.client.get(url) - self.assertEqual(response.status_code, 404) - self.assertTemplateUsed(response, "404.html") - - -class JoinForumFormViewTest(TestCase): - @classmethod - def setUpTestData(cls): - cls.token = uuid.uuid4() - cls.forum = create_forum(invitation_token=cls.token) - cls.forum.members_group = Group.objects.create(name="members") - cls.forum.save() - cls.user = UserFactory() - cls.url = reverse("members:join_forum_form", kwargs={"token": cls.token}) - - cls.perm_handler = PermissionHandler() - assign_perm("can_read_forum", cls.forum.members_group, cls.forum) - assign_perm("can_see_forum", cls.forum.members_group, cls.forum) - - def test_anonymous_redirection(self): - response = self.client.get(self.url) - self.assertRedirects( - response, reverse("members:join_forum_landing", kwargs={"token": self.token}) + "?next=" + self.url - ) - - def test_token_doesnt_exists(self): - wrong_token = uuid.uuid4() - self.client.force_login(self.user) - url = reverse("members:join_forum_form", kwargs={"token": wrong_token}) - response = self.client.get(url) - self.assertEqual(response.status_code, 404) - self.assertTemplateUsed(response, "404.html") - - def test_get(self): - self.client.force_login(self.user) - response = self.client.get(self.url) - self.assertContains(response, self.forum.name, status_code=200) - - def test_post(self): - self.client.force_login(self.user) - response = self.client.post(self.url) - self.assertRedirects( - response, - reverse( - "forum_extension:forum", - kwargs={ - "slug": self.forum.slug, - "pk": self.forum.pk, - }, - ), - ) - self.assertTrue(self.forum.members_group.user_set.filter(id=self.user.id).exists()) - - def test_already_in_group(self): - self.forum.members_group.user_set.add(self.user) - self.client.force_login(self.user) - self.client.post(self.url) - self.assertTrue(self.forum.members_group.user_set.filter(id=self.user.id).exists()) - - class TestLeaderBoardListView: def test_content(self, client, db): undesired_forum_profile = ForumProfileFactory() diff --git a/lacommunaute/forum_member/urls.py b/lacommunaute/forum_member/urls.py index 44b875ccf..4003e3932 100644 --- a/lacommunaute/forum_member/urls.py +++ b/lacommunaute/forum_member/urls.py @@ -3,8 +3,6 @@ from lacommunaute.forum_member.views import ( ForumProfileDetailView, ForumProfileUpdateView, - JoinForumFormView, - JoinForumLandingView, LeaderBoardListView, ModeratorProfileListView, SeekersListView, @@ -17,8 +15,6 @@ path("profile/edit/", ForumProfileUpdateView.as_view(), name="profile_update"), path("profile//", ForumProfileDetailView.as_view(), name="profile"), path("forum/-/", ModeratorProfileListView.as_view(), name="forum_profiles"), - path("join-forum-landing//", JoinForumLandingView.as_view(), name="join_forum_landing"), - path("join-forum//", JoinForumFormView.as_view(), name="join_forum_form"), path("leaderboard/", LeaderBoardListView.as_view(), name="leaderboard"), path("seekers/", SeekersListView.as_view(), name="seekers"), ] diff --git a/lacommunaute/forum_member/views.py b/lacommunaute/forum_member/views.py index 49ccbae47..2f612f724 100644 --- a/lacommunaute/forum_member/views.py +++ b/lacommunaute/forum_member/views.py @@ -1,10 +1,8 @@ import logging -from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import get_object_or_404 from django.urls import reverse -from django.utils.http import urlencode -from django.views.generic import FormView, ListView, TemplateView +from django.views.generic import ListView from machina.apps.forum_member.views import ( ForumProfileDetailView as BaseForumProfileDetailView, ForumProfileUpdateView as BaseForumProfileUpdateView, @@ -12,9 +10,8 @@ from machina.core.loading import get_class from lacommunaute.forum.models import Forum -from lacommunaute.forum_member.forms import ForumProfileForm, JoinForumForm +from lacommunaute.forum_member.forms import ForumProfileForm from lacommunaute.forum_member.models import ForumProfile -from lacommunaute.utils.urls import get_safe_url logger = logging.getLogger(__name__) @@ -65,75 +62,6 @@ def get_context_data(self, **kwargs): return context -class JoinForumLandingView(TemplateView): - template_name = "forum_member/join_forum_landing.html" - - def get_forum(self): - if not hasattr(self, "forum"): - self.forum = get_object_or_404( - Forum, - invitation_token=self.kwargs["token"], - ) - return self.forum - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - forum = self.get_forum() - context["forum"] = forum - params = { - "previous_url": reverse( - "members:join_forum_landing", - kwargs={ - "token": forum.invitation_token, - }, - ), - "next_url": get_safe_url(self.request, "next"), - } - context["inclusion_connect_url"] = f"{reverse('inclusion_connect:authorize')}?{urlencode(params)}" - return context - - -class JoinForumFormView(LoginRequiredMixin, FormView): - template_name = "forum_member/join_forum_form.html" - form_class = JoinForumForm - - def get_forum(self): - if not hasattr(self, "forum"): - self.forum = get_object_or_404( - Forum, - invitation_token=self.kwargs["token"], - ) - return self.forum - - def form_valid(self, form): - form.forum = self.get_forum() - form.user = self.request.user - form.join_forum() - return super().form_valid(form) - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context["forum"] = self.get_forum() - return context - - def get_login_url(self): - return reverse( - "members:join_forum_landing", - kwargs={ - "token": self.kwargs["token"], - }, - ) - - def get_success_url(self): - return reverse( - "forum_extension:forum", - kwargs={ - "slug": self.forum.slug, - "pk": self.forum.pk, - }, - ) - - class LeaderBoardListView(ListView): model = ForumProfile template_name = "forum_member/profiles.html" diff --git a/lacommunaute/templates/forum_member/moderator_profiles.html b/lacommunaute/templates/forum_member/moderator_profiles.html index 1e66bece0..e68fa7c5e 100644 --- a/lacommunaute/templates/forum_member/moderator_profiles.html +++ b/lacommunaute/templates/forum_member/moderator_profiles.html @@ -43,34 +43,6 @@

{% endwith %} -
-
-
- -
- -
- -
-
-
-
-
diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 03f2e2dcb..2dd9583a6 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -852,15 +852,6 @@ msgstr "S'inscrire" msgid "Login" msgstr "Se connecter" -#: lacommunaute/templates/forum_member/join_forum_form.html: 32 -#, python-format -msgid "Join forum %(name)s" -msgstr "Vous êtes invité à rejoindre la thématique %(name)s" - -#: lacommunaute/templates/forum_member/join_forum_form.html: 60 -msgid "Join forum" -msgstr "Rejoindre la thématique" - #: lacommunaute/templates/pages/home.html:84 msgid "Go to this forum" msgstr "Accéder à cette thématique"