also forbid subscribers, old subscribers and public

This commit is contained in:
imperosol committed 2026-12-02 13:47:55 +01:00
1 parent c219958e48
commit 2c19e7b3fe
3 files changed
+47 -20

No files matched your search

+6 -1
View File
@@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "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" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n" "Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@@ -5412,6 +5412,11 @@ msgstr[1] ""
"que n'importe qui pourrait devenir éditeur simplement en rejoignant un des " "que n'importe qui pourrait devenir éditeur simplement en rejoignant un des "
"club." "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 #: sas/forms.py
msgid "You already requested moderation for this picture." msgid "You already requested moderation for this picture."
msgstr "Vous avez déjà déposé une demande de retrait pour cette photo." msgstr "Vous avez déjà déposé une demande de retrait pour cette photo."
+38 -17
View File
@@ -4,7 +4,9 @@ from pathlib import Path
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
from django import forms from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db.models import Q
from django.utils.timezone import get_current_timezone from django.utils.timezone import get_current_timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext_lazy 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 from sas.widgets.ajax_select import AutoCompleteSelectAlbum
if TYPE_CHECKING: if TYPE_CHECKING:
from django.db.models import QuerySet
from django.db.models.fields.files import FieldFile from django.db.models.fields.files import FieldFile
from core.models import Group, User from core.models import Group, User
@@ -87,23 +88,43 @@ class AlbumEditForm(forms.ModelForm):
return f return f
def clean_edit_groups(self): def clean_edit_groups(self):
groups: QuerySet[Group] = self.cleaned_data["edit_groups"] groups: list[Group] = list(
member_groups = list(groups.exclude(club=None).values_list("name", flat=True)) self.cleaned_data["edit_groups"].annotate(
if member_groups: is_club_group=Q(club__isnull=False)
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)}
) )
)
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 return groups
def save(self, commit=True): # noqa: FBT002 def save(self, commit=True): # noqa: FBT002
+3 -2
View File
@@ -111,7 +111,7 @@ def test_club_member_groups_cannot_be_edit_groups(album: Album):
"name": album.name, "name": album.name,
"parent": album.pk, "parent": album.pk,
"date": localdate(), "date": localdate(),
"edit_groups": [club.members_group_id], "edit_groups": [club.members_group_id, settings.SITH_GROUP_SUBSCRIBERS_ID],
} }
form = AlbumEditForm(data=data) form = AlbumEditForm(data=data)
assert not form.is_valid() 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}. " f"d'édition au groupe {club.members_group.name}. "
"C'est un groupe de simples membres de club, " "C'est un groupe de simples membres de club, "
"ce qui signifie que n'importe qui pourrait devenir éditeur " "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.",
] ]
} }