From ea1bf8a073df2394e7173e0afae9ba2d54b9e5f2 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Sun, 5 Feb 2017 14:25:26 +0100 Subject: [PATCH 1/4] Historique des sanctions --- templates/member/profile.html | 2 + templates/member/sanctions_history.html | 54 +++++++++++++++++++++++++ zds/member/urls.py | 4 +- zds/member/views.py | 17 ++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 templates/member/sanctions_history.html diff --git a/templates/member/profile.html b/templates/member/profile.html index 3ac7bc1147..3a32933d7b 100644 --- a/templates/member/profile.html +++ b/templates/member/profile.html @@ -603,6 +603,8 @@

{% trans "Sanctions" %}

{% endif %} + +
  • Historique
  • {% endif %} diff --git a/templates/member/sanctions_history.html b/templates/member/sanctions_history.html new file mode 100644 index 0000000000..16a5855fe4 --- /dev/null +++ b/templates/member/sanctions_history.html @@ -0,0 +1,54 @@ +{% extends "member/base.html" %} +{% load i18n %} +{% load date %} + + +{% block title %} + {% trans "Historique des sanctions de" %} {{ usr.username }} +{% endblock %} + + + +{% block breadcrumb %} +
  • {{ usr.username }}
  • +
  • {% trans "Historique des sanctions" %}
  • +{% endblock %} + + + +{% block headline %} + {% trans "Historique des sanctions de" %} {{ usr.username }} +{% endblock %} + + + +{% block content %} + {% if sanctions %} + + + + + + + + + {% for sanction in sanctions %} + + + + + + + {% endfor %} + +
    {% trans "Type" %}{% trans "Explication" %}{% trans "Modérateur" %}{% trans "Date" %}
    {{ sanction.type }} + {% if sanction.note %} + {{ sanction.note }} + {% else %} + – + {% endif %} + {{ sanction.moderator.username }}{{ sanction.pubdate|format_date|capfirst }}
    + {% else %} +

    {{ usr.username }} {% trans "n'a jamais été sanctionné." %}

    + {% endif %} +{% endblock %} diff --git a/zds/member/urls.py b/zds/member/urls.py index f7d0096d27..66795ae527 100644 --- a/zds/member/urls.py +++ b/zds/member/urls.py @@ -5,7 +5,8 @@ from zds.member.views import MemberList, MemberDetail, UpdateMember, UpdateAvatarMember, UpdatePasswordMember, \ UpdateUsernameEmailMember, RegisterView, SendValidationEmailView, modify_karma, \ modify_profile, settings_mini_profile, member_from_ip, tutorials, articles, settings_promote, login_view, \ - logout_view, forgot_password, new_password, activate_account, generate_token_account, unregister, warning_unregister + logout_view, forgot_password, new_password, activate_account, generate_token_account, unregister, warning_unregister, \ + sanctions_history urlpatterns = [ # list @@ -23,6 +24,7 @@ # moderation url(r'^profil/karmatiser/$', modify_karma, name='member-modify-karma'), url(r'^profil/modifier/(?P\d+)/$', modify_profile, name='member-modify-profile'), + url(r'^profil/historique-sanctions/(?P\d+)/$', sanctions_history, name='member-sanctions-history'), url(r'^parametres/mini_profil/(?P.+)/$', settings_mini_profile, name='member-settings-mini-profile'), url(r'^profil/multi/(?P.+)/$', member_from_ip, name='member-from-ip'), diff --git a/zds/member/views.py b/zds/member/views.py index 3222312473..c0028316d1 100644 --- a/zds/member/views.py +++ b/zds/member/views.py @@ -496,6 +496,23 @@ def modify_profile(request, user_pk): return redirect(profile.get_absolute_url()) +@login_required +def sanctions_history(request, user_pk): + """Display the history of a member sanctions""" + + if not request.user.has_perm('member.change_profile'): + raise PermissionDenied + + user = get_object_or_404(User, pk=user_pk) + + sanctions = Ban.objects.filter(user=user).order_by('-pubdate').select_related('moderator') + + return render(request, 'member/sanctions_history.html', { + 'usr': user, + 'sanctions': sanctions, + }) + + @login_required def tutorials(request): """Returns all tutorials of the authenticated user.""" From a5681ae5c17c35a2d1eaff6e3cc9da2a638d8aaa Mon Sep 17 00:00:00 2001 From: Guillaume Date: Sun, 5 Feb 2017 17:11:21 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Cr=C3=A9e=20une=20historique=20des=20sancti?= =?UTF-8?q?ons=20pour=20le=20staff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zds/member/commons.py | 12 +++---- zds/member/tests/tests_views.py | 60 +++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/zds/member/commons.py b/zds/member/commons.py index 970d399b10..178943669a 100644 --- a/zds/member/commons.py +++ b/zds/member/commons.py @@ -224,7 +224,7 @@ class ReadingOnlySanction(MemberSanctionState): """ def get_type(self): - return _(u'Lecture Seule') + return _(u'Lecture seule définitive') def get_text(self): return self.array_infos.get('ls-text', '') @@ -246,7 +246,7 @@ class TemporaryReadingOnlySanction(MemberSanctionState): """ def get_type(self): - return _(u'Lecture Seule Temporaire') + return _(u'Lecture seule temporaire') def get_text(self): return self.array_infos.get('ls-text', '') @@ -271,7 +271,7 @@ class DeleteReadingOnlySanction(MemberSanctionState): """ def get_type(self): - return _(u"Autorisation d'écrire") + return _(u'Fin de lecture seule') def get_text(self): return self.array_infos.get('unls-text', '') @@ -293,7 +293,7 @@ class BanSanction(MemberSanctionState): """ def get_type(self): - return _(u'Ban définitif') + return _(u'Bannissement définitif') def get_text(self): return self.array_infos.get('ban-text', '') @@ -315,7 +315,7 @@ class TemporaryBanSanction(MemberSanctionState): """ def get_type(self): - return _(u'Ban Temporaire') + return _(u'Bannissement temporaire') def get_text(self): return self.array_infos.get('ban-text', '') @@ -341,7 +341,7 @@ class DeleteBanSanction(MemberSanctionState): """ def get_type(self): - return _(u'Autorisation de se connecter') + return _(u'Fin de bannissement') def get_text(self): return self.array_infos.get('unban-text', '') diff --git a/zds/member/tests/tests_views.py b/zds/member/tests/tests_views.py index 457926a8eb..d2a72baf5a 100644 --- a/zds/member/tests/tests_views.py +++ b/zds/member/tests/tests_views.py @@ -192,6 +192,54 @@ def test_details_member(self): ) self.assertEqual(result.status_code, 404) + def test_sanctions_history(self): + user = ProfileFactory().user + + ban = Ban( + user=user, + moderator=self.staff, + type='Lecture seule temporaire', + note='Test de LS' + ) + ban.save() + + # staff rights are required to view the history, check that + self.client.logout() + self.client.login(username=user.username, password='hostel77') + + result = self.client.get( + reverse('member-sanctions-history', args=[user.pk]), + follow=False + ) + + self.assertEqual(result.status_code, 403) + + self.client.logout() + self.client.login(username=self.staff.username, password='hostel77') + + result = self.client.get( + reverse('member-sanctions-history', args=[user.pk]), + follow=False + ) + + self.assertEqual(result.status_code, 200) + + # now, check that the history of a unknown user returns a 404 + result = self.client.get( + reverse('member-sanctions-history', args=[0]), + follow=False + ) + + self.assertEqual(result.status_code, 404) + + # finally, check that the history contains the note + result = self.client.get( + reverse('member-sanctions-history', args=[user.pk]), + follow=False + ) + + self.assertContains(result, 'Test de LS') + def test_profile_page_of_weird_member_username(self): # create some user with weird username @@ -635,7 +683,7 @@ def test_sanctions(self): self.assertIsNone(user.end_ban_write) self.assertIsNone(user.end_ban_read) ban = Ban.objects.filter(user__id=user.user.id).order_by('-pubdate')[0] - self.assertEqual(ban.type, 'Lecture Seule') + self.assertEqual(ban.type, 'Lecture seule définitive') self.assertEqual(ban.note, 'Texte de test pour LS') self.assertEquals(len(mail.outbox), 1) @@ -657,7 +705,7 @@ def test_sanctions(self): self.assertIsNone(user.end_ban_write) self.assertIsNone(user.end_ban_read) ban = Ban.objects.filter(user__id=user.user.id).order_by('-id')[0] - self.assertEqual(ban.type, u'Autorisation d\'écrire') + self.assertEqual(ban.type, u'Fin de lecture seule') self.assertEqual(ban.note, 'Texte de test pour un-LS') self.assertEquals(len(mail.outbox), 2) @@ -681,7 +729,7 @@ def test_sanctions(self): self.assertIsNotNone(user.end_ban_write) self.assertIsNone(user.end_ban_read) ban = Ban.objects.filter(user__id=user.user.id).order_by('-id')[0] - self.assertEqual(ban.type, u'Lecture Seule Temporaire') + self.assertEqual(ban.type, u'Lecture seule temporaire') self.assertEqual(ban.note, u'Texte de test pour LS TEMP') self.assertEquals(len(mail.outbox), 3) @@ -704,7 +752,7 @@ def test_sanctions(self): self.assertIsNone(user.end_ban_write) self.assertIsNone(user.end_ban_read) ban = Ban.objects.filter(user__id=user.user.id).order_by('-id')[0] - self.assertEqual(ban.type, u'Ban définitif') + self.assertEqual(ban.type, u'Bannissement définitif') self.assertEqual(ban.note, u'Texte de test pour BAN') self.assertEquals(len(mail.outbox), 4) @@ -727,7 +775,7 @@ def test_sanctions(self): self.assertIsNone(user.end_ban_write) self.assertIsNone(user.end_ban_read) ban = Ban.objects.filter(user__id=user.user.id).order_by('-id')[0] - self.assertEqual(ban.type, u'Autorisation de se connecter') + self.assertEqual(ban.type, u'Fin de bannissement') self.assertEqual(ban.note, u'Texte de test pour BAN') self.assertEquals(len(mail.outbox), 5) @@ -751,7 +799,7 @@ def test_sanctions(self): self.assertIsNone(user.end_ban_write) self.assertIsNotNone(user.end_ban_read) ban = Ban.objects.filter(user__id=user.user.id).order_by('-id')[0] - self.assertEqual(ban.type, u'Ban Temporaire') + self.assertEqual(ban.type, u'Bannissement temporaire') self.assertEqual(ban.note, u'Texte de test pour BAN TEMP') self.assertEquals(len(mail.outbox), 6) From fbc31e44570f48ce73116e251ffbee6635e18166 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Sun, 5 Feb 2017 21:02:35 +0100 Subject: [PATCH 3/4] PEP-8 --- zds/member/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zds/member/urls.py b/zds/member/urls.py index 66795ae527..3ac55cfe43 100644 --- a/zds/member/urls.py +++ b/zds/member/urls.py @@ -5,8 +5,8 @@ from zds.member.views import MemberList, MemberDetail, UpdateMember, UpdateAvatarMember, UpdatePasswordMember, \ UpdateUsernameEmailMember, RegisterView, SendValidationEmailView, modify_karma, \ modify_profile, settings_mini_profile, member_from_ip, tutorials, articles, settings_promote, login_view, \ - logout_view, forgot_password, new_password, activate_account, generate_token_account, unregister, warning_unregister, \ - sanctions_history + logout_view, forgot_password, new_password, activate_account, generate_token_account, unregister, \ + warning_unregister, sanctions_history urlpatterns = [ # list From e39fe7b1b880cf04a29bce1e72a5efcc33d7dba1 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 8 Feb 2017 21:08:09 +0100 Subject: [PATCH 4/4] =?UTF-8?q?D=C3=A9j=C3=A0=20la=20modif=20de=20permissi?= =?UTF-8?q?on=5Frequired=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zds/member/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zds/member/views.py b/zds/member/views.py index 97019a2239..d5413d6a97 100644 --- a/zds/member/views.py +++ b/zds/member/views.py @@ -481,12 +481,10 @@ def modify_profile(request, user_pk): @login_required +@permission_required('member.change_profile', raise_exception=True) def sanctions_history(request, user_pk): """Display the history of a member sanctions""" - if not request.user.has_perm('member.change_profile'): - raise PermissionDenied - user = get_object_or_404(User, pk=user_pk) sanctions = Ban.objects.filter(user=user).order_by('-pubdate').select_related('moderator')