Skip to content

Commit

Permalink
Corrige une erreur si la durée d'une sanction temporaire est manquante
Browse files Browse the repository at this point in the history
Et rend obligatoire la durée des sanctions temporaires pour valider le
formulaire.
  • Loading branch information
philippemilink committed Dec 25, 2023
1 parent e0e78e2 commit 8994aad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 3 additions & 1 deletion templates/member/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ <h3>{% trans 'Sanctions' %}</h3>
name="ls-jrs"
class="expand"
placeholder="{% trans 'Durée de la lecture seule, en jours' %}"
required="required"
min="1">
{% csrf_token %}
<button type="submit"
Expand Down Expand Up @@ -795,12 +796,13 @@ <h3>{% trans 'Sanctions' %}</h3>
<input type="number"
name="ban-jrs"
class="expand"
required="required"
placeholder="{% trans 'Durée du bannissement, en jours' %}"
min="1">
{% csrf_token %}
<button type="submit"
name="ban-temp"
class="btn btn-submit">
class="btn btn-submit">
{% trans "Confirmer" %}
</button>
</form>
Expand Down
14 changes: 14 additions & 0 deletions zds/member/tests/views/tests_moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ def test_ls_followed_by_unls(self):
self.assertEqual(result.status_code, 200)
self.assertEqual(nb_users + 1, len(result.context["members"])) # LS guy still shows up, good

def test_temp_ban_missing_duration(self):
# Test error is caught when the duration for temporary sanction is missing in submitted form.
staff = StaffProfileFactory()
self.client.force_login(staff.user)

profile = ProfileFactory()
ls_text = "Texte de test pour LS TEMP"
result = self.client.post(
reverse("member-modify-profile", kwargs={"user_pk": profile.user.id}),
{"ls-temp": "", "ls-text": ls_text},
follow=False,
)
self.assertEqual(result.status_code, 302)

def test_temp_ls_followed_by_unls(self):
"""
Test various sanctions.
Expand Down
23 changes: 12 additions & 11 deletions zds/member/views/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,20 @@ def modify_profile(request, user_pk):

try:
ban = state.get_sanction(request.user, profile.user)
except ValueError:
raise HttpResponseBadRequest
except (ValueError, TypeError):
messages.error(request, _("Une erreur est survenue lors de la récupération de la sanction."))
else:
state.apply_sanction(profile, ban)

state.apply_sanction(profile, ban)
if "un-ls" in request.POST or "un-ban" in request.POST:
msg = state.get_message_unsanction()
else:
msg = state.get_message_sanction()

if "un-ls" in request.POST or "un-ban" in request.POST:
msg = state.get_message_unsanction()
else:
msg = state.get_message_sanction()
msg = msg.format(
ban.user, ban.moderator, ban.type, state.get_detail(), ban.note, settings.ZDS_APP["site"]["literal_name"]
)

msg = msg.format(
ban.user, ban.moderator, ban.type, state.get_detail(), ban.note, settings.ZDS_APP["site"]["literal_name"]
)
state.notify_member(ban, msg)

state.notify_member(ban, msg)
return redirect(profile.get_absolute_url())

0 comments on commit 8994aad

Please sign in to comment.