Skip to content

Commit

Permalink
Gère les utilisateurs désinscrits dans le journal des évenements
Browse files Browse the repository at this point in the history
Fix #6359
  • Loading branch information
philippemilink authored and Situphen committed Jul 22, 2022
1 parent 44bd916 commit 5eddc4b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
6 changes: 6 additions & 0 deletions zds/member/views/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from zds.member.views import get_client_ip
from zds.mp.models import PrivatePost, PrivateTopic
from zds.tutorialv2.models.database import PickListOperation
from zds.tutorialv2.models.events import Event
from zds.utils.models import (
Comment,
CommentVote,
Expand Down Expand Up @@ -172,6 +173,11 @@ def unregister(request):
# Nota : as of v21 all about content paternity is held by a proper receiver in zds.tutorialv2.models.database
PickListOperation.objects.filter(staff_user=current).update(staff_user=anonymous)
PickListOperation.objects.filter(canceler_user=current).update(canceler_user=anonymous)

Event.objects.filter(performer=current).update(performer=external)
Event.objects.filter(author=current).update(author=external)
Event.objects.filter(contributor=current).update(contributor=external)

# Comments likes / dislikes
votes = CommentVote.objects.filter(user=current)
for vote in votes:
Expand Down
61 changes: 57 additions & 4 deletions zds/tutorialv2/tests/tests_views/tests_events.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from django.conf import settings
from django.test import TestCase

from django.urls import reverse

from zds.member.tests.factories import ProfileFactory, StaffProfileFactory
from zds.tutorialv2.tests.factories import PublishableContentFactory
from zds.gallery.tests.factories import UserGalleryFactory
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory, UserFactory
from zds.tutorialv2.models.database import PublishedContent
from zds.tutorialv2.tests.factories import (
ContentContributionRoleFactory,
PublishableContentFactory,
PublishedContentFactory,
)
from zds.tutorialv2.tests import override_for_contents, TutorialTestMixin
from zds.utils.tests.factories import LicenceFactory, SubCategoryFactory


@override_for_contents()
Expand Down Expand Up @@ -46,4 +53,50 @@ def test_authenticated_outsider(self):
"""Test that unauthorized users get a 403."""
self.client.force_login(self.outsider)
response = self.client.get(self.events_list_url)
self.assertEquals(response.status_code, 403)
self.assertEqual(response.status_code, 403)


@override_for_contents()
class EventListTests(TutorialTestMixin, TestCase):
def setUp(self):
# Create users
self.author = ProfileFactory().user
self.coauthor = ProfileFactory().user
self.contributor = ProfileFactory().user
self.staff = StaffProfileFactory().user
self.anonymous = UserFactory(username=settings.ZDS_APP["member"]["anonymous_account"], password="anything")
self.external = UserFactory(username=settings.ZDS_APP["member"]["external_account"], password="anything")
self.bot = UserFactory(username=settings.ZDS_APP["member"]["bot_account"], password="anything")
self.role = ContentContributionRoleFactory()

def test_events_involving_unregistered_users(self):
"""Test accessing the event list with actions involving unregistered users."""
article = PublishedContentFactory(type="ARTICLE", author_list=[self.author])

self.client.force_login(self.author)

# Add a coauthor
result = self.client.post(
reverse("content:add-author", args=[article.pk]), {"username": self.coauthor.username}, follow=False
)
self.assertEqual(result.status_code, 302)

# Add a contributor
form_data = {
"username": self.contributor,
"contribution_role": self.role.pk,
"comment": "Foo",
}
result = self.client.post(reverse("content:add-contributor", args=[article.pk]), form_data, follow=True)
self.assertEqual(result.status_code, 200)

# Unregister users
for user in [self.author, self.coauthor, self.contributor]:
self.client.force_login(user)
response = self.client.post(reverse("member-unregister"), follow=False)
self.assertEqual(response.status_code, 302)

# Access the event list page
self.client.force_login(self.staff)
response = self.client.get(reverse("content:events", args=[article.pk]))
self.assertEqual(response.status_code, 200)

0 comments on commit 5eddc4b

Please sign in to comment.