diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 5c4d063f..1c71b0ea 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-30 13:53+0100\n" +"POT-Creation-Date: 2026-12-02 13:40+0100\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Maréchal \n" @@ -5412,6 +5412,11 @@ msgstr[1] "" "que n'importe qui pourrait devenir éditeur simplement en rejoignant un des " "club." +#: sas/forms.py +#, python-format +msgid "%(group)s : this group cannot get album edition rights." +msgstr "%(group)s : ce groupe ne peut pas recevoir le droit d'éditer un album." + #: sas/forms.py msgid "You already requested moderation for this picture." msgstr "Vous avez déjà déposé une demande de retrait pour cette photo." diff --git a/sas/forms.py b/sas/forms.py index e5d74c28..a0bd29f1 100644 --- a/sas/forms.py +++ b/sas/forms.py @@ -4,7 +4,9 @@ from pathlib import Path from typing import TYPE_CHECKING, Any from django import forms +from django.conf import settings from django.core.exceptions import ValidationError +from django.db.models import Q from django.utils.timezone import get_current_timezone from django.utils.translation import gettext_lazy as _ from django.utils.translation import ngettext_lazy @@ -18,7 +20,6 @@ from sas.models import Album, Picture, PictureModerationRequest from sas.widgets.ajax_select import AutoCompleteSelectAlbum if TYPE_CHECKING: - from django.db.models import QuerySet from django.db.models.fields.files import FieldFile from core.models import Group, User @@ -87,23 +88,43 @@ class AlbumEditForm(forms.ModelForm): return f def clean_edit_groups(self): - groups: QuerySet[Group] = self.cleaned_data["edit_groups"] - member_groups = list(groups.exclude(club=None).values_list("name", flat=True)) - if member_groups: - raise ValidationError( - ngettext_lazy( - "You cannot grant the edit rights " - "to the %(groups)s group. " - "It is a club simple member group, which means anyone " - "could become an editor by merely joining the club.", - "You cannot grant the edit rights " - "to the following groups : %(groups)s. " - "They are club simple member groups, which means anyone " - "could become an editor by merely joining one of the clubs.", - number=len(member_groups), - ) - % {"groups": ", ".join(member_groups)} + groups: list[Group] = list( + self.cleaned_data["edit_groups"].annotate( + is_club_group=Q(club__isnull=False) ) + ) + member_groups = [g.name for g in groups if g.is_club_group] + if member_groups: + self.add_error( + "edit_groups", + ValidationError( + ngettext_lazy( + "You cannot grant the edit rights " + "to the %(groups)s group. " + "It is a club simple member group, which means anyone " + "could become an editor by merely joining the club.", + "You cannot grant the edit rights " + "to the following groups : %(groups)s. " + "They are club simple member groups, which means anyone " + "could become an editor by merely joining one of the clubs.", + number=len(member_groups), + ) + % {"groups": ", ".join(member_groups)} + ), + ) + for group in groups: + if group.id in [ + settings.SITH_GROUP_SUBSCRIBERS_ID, + settings.SITH_GROUP_OLD_SUBSCRIBERS_ID, + settings.SITH_GROUP_PUBLIC_ID, + ]: + self.add_error( + "edit_groups", + ValidationError( + _("%(group)s : this group cannot get album edition rights.") + % {"group": group.name} + ), + ) return groups def save(self, commit=True): # noqa: FBT002 diff --git a/sas/tests/test_update_album.py b/sas/tests/test_update_album.py index bc61f13f..0d54888e 100644 --- a/sas/tests/test_update_album.py +++ b/sas/tests/test_update_album.py @@ -111,7 +111,7 @@ def test_club_member_groups_cannot_be_edit_groups(album: Album): "name": album.name, "parent": album.pk, "date": localdate(), - "edit_groups": [club.members_group_id], + "edit_groups": [club.members_group_id, settings.SITH_GROUP_SUBSCRIBERS_ID], } form = AlbumEditForm(data=data) assert not form.is_valid() @@ -121,7 +121,8 @@ def test_club_member_groups_cannot_be_edit_groups(album: Album): f"d'édition au groupe {club.members_group.name}. " "C'est un groupe de simples membres de club, " "ce qui signifie que n'importe qui pourrait devenir éditeur " - "simplement en rejoignant le club." + "simplement en rejoignant le club.", + "Cotisants : ce groupe ne peut pas recevoir le droit d'éditer un album.", ] }