Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Création d'un historique de sanctions pour le staff #4177

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions templates/member/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ <h4>{% trans "Sanctions" %}</h4>
</form>
</li>
{% endif %}

<li><a href="{% url 'member-sanctions-history' usr.pk %}">Historique</a></li>
</ul>
{% endif %}
</div>
Expand Down
54 changes: 54 additions & 0 deletions templates/member/sanctions_history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{% extends "member/base.html" %}
{% load i18n %}
{% load date %}


{% block title %}
{% trans "Historique des sanctions de" %} {{ usr.username }}
{% endblock %}



{% block breadcrumb %}
<li><a href="{% url "member-detail" usr.username %}">{{ usr.username }}</a></li>
<li>{% trans "Historique des sanctions" %}</li>
{% endblock %}



{% block headline %}
{% trans "Historique des sanctions de" %} {{ usr.username }}
{% endblock %}



{% block content %}
{% if sanctions %}
<table class="fullwidth">
<thead>
<th>{% trans "Type" %}</th>
<th>{% trans "Explication" %}</th>
<th class="wide">{% trans "Modérateur" %}</th>
<th class="wide">{% trans "Date" %}</th>
</thead>
<tbody>
{% for sanction in sanctions %}
<tr>
<td>{{ sanction.type }}</td>
<td>
{% if sanction.note %}
{{ sanction.note }}
{% else %}
{% endif %}
</td>
<td class="wide"><a href="{% url "member-detail" sanction.moderator.username %}">{{ sanction.moderator.username }}</a></td>
<td class="wide">{{ sanction.pubdate|format_date|capfirst }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>{{ usr.username }} {% trans "n'a jamais été sanctionné." %}</p>
{% endif %}
{% endblock %}
12 changes: 6 additions & 6 deletions zds/member/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand All @@ -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', '')
Expand All @@ -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', '')
Expand All @@ -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', '')
Expand All @@ -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', '')
Expand All @@ -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', '')
Expand Down
60 changes: 54 additions & 6 deletions zds/member/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux même aller plus loin et utiliser result.context['sanctions'] pour vérifier ce que la liste de sanctions contient effectivement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonne idée :)


def test_profile_page_of_weird_member_username(self):

# create some user with weird username
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion zds/member/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +24,7 @@
# moderation
url(r'^profil/karmatiser/$', modify_karma, name='member-modify-karma'),
url(r'^profil/modifier/(?P<user_pk>\d+)/$', modify_profile, name='member-modify-profile'),
url(r'^profil/historique-sanctions/(?P<user_pk>\d+)/$', sanctions_history, name='member-sanctions-history'),
url(r'^parametres/mini_profil/(?P<user_name>.+)/$', settings_mini_profile, name='member-settings-mini-profile'),
url(r'^profil/multi/(?P<ip_address>.+)/$', member_from_ip, name='member-from-ip'),

Expand Down
15 changes: 15 additions & 0 deletions zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,21 @@ def modify_profile(request, user_pk):
return redirect(profile.get_absolute_url())


@login_required
@permission_required('member.change_profile', raise_exception=True)
def sanctions_history(request, user_pk):
"""Display the history of a member sanctions"""

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."""
Expand Down