Skip to content

Commit

Permalink
Améliore l'historique de modération pour le staff (#4202)
Browse files Browse the repository at this point in the history
* Début

* Début du test

* Test complété
  • Loading branch information
Guillaume authored and pierre-24 committed Feb 13, 2017
1 parent c859b40 commit ce81ce5
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 23 deletions.
79 changes: 62 additions & 17 deletions templates/member/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ <h1 id="infos-generales">
{% endif %}
</ul>

{% if perms.member.change_profile and not profile.is_private %}
<div>
{% trans "Remarques sur cet utilisateur" %} ({{ profile.karma }}) :
<ul>
{% if karmanotes.count > 0 %}
{% for note in karmanotes %}
<li><strong>{{ note.karma }}</strong> {{ note.pubdate|format_date:True }} {% trans "par" %} {{ note.moderator.username }} : {{ note.note }}</li>
{% endfor %}
{% else %}
<li>{% trans "Cet utilisateur n'a reçu aucune remarque" %}</li>
{% endif %}
</ul>
<a href="#karmatiser-modal" class="open-modal">{% trans "Ajouter une remarque" %}</a>
{% crispy karmaform %}
</div>
{% endif %}

{% if profile.sign %}
<h2 id="signature">{% trans "Signature" %}</h2>
{{ profile.sign|emarkdown_inline }}
Expand Down Expand Up @@ -159,6 +142,43 @@ <h2 id="biographie">{% trans "Biographie" %}</h2>
</section>
{% endif %}

{% if perms.member.change_profile and actions %}
<hr class="clearfix" />
<section class="full-content-wrapper without-margin article-content">
<h2 id="historique-moderation">{% trans "Historique de modération" %}</h2>
<table class="fullwidth">
<thead>
<th>{% trans "Action" %}</th>
<th>{% trans "Explication" %}</th>
<th class="wide">{% trans "Modérateur" %}</th>
<th class="wide">{% trans "Date" %}</th>
</thead>
<tbody>
{% for action in actions %}
<tr>
<td>
{% if action.karma %}
{% trans "Modification du karma" %} : {{ action.karma }}
{% else %}
{{ action.type }}
{% endif %}
</td>
<td>
{% if action.note %}
{{ action.note }}
{% else %}
{% endif %}
</td>
<td class="wide"><a href="{% url "member-detail" action.moderator.username %}">{{ action.moderator.username }}</a></td>
<td class="wide">{{ action.pubdate|format_date|capfirst }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</section>
{% endif %}

{% if stats_filename and perms.member.change_profile %}
<hr class="clearfix" />
<section class="full-content-wrapper without-margin">
Expand Down Expand Up @@ -303,6 +323,13 @@ <h3>{% trans "Accès rapide" %}</h3>
</a>
</li>
{% endif %}
{% if perms.member.change_profile and actions %}
<li>
<a href="#historique-moderation">
{% trans "Historique de modération" %}
</a>
</li>
{% endif %}
</ul>
</div>

Expand Down Expand Up @@ -500,6 +527,24 @@ <h4>{% trans "Statistiques" %}</h4>
</li>
</ul>

{% if not profile.is_private %}
<h4>{% trans "Karma" %}</h4>
<ul>
<li class="inactive">
<span>
{% trans "Valeur actuelle" %}
<span class="count">{{ profile.karma }}</span>
</span>
</li>
<li>
<a href="#karmatiser-modal" class="open-modal">
{% trans "Ajouter une remarque" %}
</a>
{% crispy karmaform %}
</li>
</ul>
{% endif %}

{% if not profile.is_private and usr != user %}
<h4>{% trans "Sanctions" %}</h4>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion templates/misc/message_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{% if perms.forum.change_post and profile.karma != 0 %}
<div class="user-metadata">
<a href="{{ member.get_absolute_url }}"
<a href="{{ member.get_absolute_url }}#historique-moderation"
class="user-karma
{% if profile.karma < 0 %}
negative
Expand Down
52 changes: 49 additions & 3 deletions zds/member/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ def test_karma(self):
'note': 'warn'
}, follow=True)
self.assertEqual(200, r.status_code)
self.assertIn('<strong>42</strong>', r.content.decode('utf-8'))
self.assertIn('42', r.content.decode('utf-8'))
# more than 100 karma must unvalidate the karma
r = self.client.post(reverse('member-modify-karma'), {
'profile_pk': user.pk,
'karma': 420,
'note': 'warn'
}, follow=True)
self.assertEqual(200, r.status_code)
self.assertNotIn('<strong>420</strong>', r.content.decode('utf-8'))
self.assertNotIn('420', r.content.decode('utf-8'))
# empty warning must unvalidate the karma
r = self.client.post(reverse('member-modify-karma'), {
'profile_pk': user.pk,
'karma': 41,
'note': ''
}, follow=True)
self.assertEqual(200, r.status_code)
self.assertNotIn('<strong>41</strong>', r.content.decode('utf-8'))
self.assertNotIn('41', r.content.decode('utf-8'))

def test_list_members(self):
"""
Expand Down Expand Up @@ -192,6 +192,52 @@ def test_details_member(self):
)
self.assertEqual(result.status_code, 404)

def test_moderation_history(self):
user = ProfileFactory().user

ban = Ban(
user=user,
moderator=self.staff,
type='Lecture Seule Temporaire',
note='Test de LS',
pubdate=datetime.now(),
)
ban.save()

note = KarmaNote(
user=user,
moderator=self.staff,
karma=5,
note='Test de karma',
pubdate=datetime.now(),
)
note.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(
user.profile.get_absolute_url(),
follow=False
)
self.assertNotContains(result, 'Historique de modération')

self.client.logout()
self.client.login(username=self.staff.username, password='hostel77')
result = self.client.get(
user.profile.get_absolute_url(),
follow=False
)
self.assertContains(result, 'Historique de modération')

# check that the note and the sanction are in the context
self.assertIn(ban, result.context['actions'])
self.assertIn(note, result.context['actions'])

# and are displayed
self.assertContains(result, 'Test de LS')
self.assertContains(result, 'Test de karma')

def test_profile_page_of_weird_member_username(self):

# create some user with weird username
Expand Down
10 changes: 8 additions & 2 deletions zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,16 @@ def get_context_data(self, **kwargs):
topic.is_followed = topic in followed_topics
context['articles'] = PublishedContent.objects.last_articles_of_a_member_loaded(usr)
context['tutorials'] = PublishedContent.objects.last_tutorials_of_a_member_loaded(usr)
context['karmanotes'] = KarmaNote.objects.filter(user=usr).order_by('-pubdate')
context['karmaform'] = KarmaForm(profile)
context['topic_read'] = TopicRead.objects.list_read_topic_pk(self.request.user, context['topics'])
context['subscriber_count'] = NewPublicationSubscription.objects.get_subscriptions(self.object).count()
if self.request.user.has_perm('member.change_profile'):
sanctions = list(Ban.objects.filter(user=usr).select_related('moderator'))
notes = list(KarmaNote.objects.filter(user=usr).select_related('moderator'))
actions = sanctions + notes
actions.sort(key=lambda action: action.pubdate)
actions.reverse()
context['actions'] = actions
context['karmaform'] = KarmaForm(profile)
return context


Expand Down

0 comments on commit ce81ce5

Please sign in to comment.