forbid club simple member groups in album edit groups.

This commit is contained in:
imperosol committed 2026-11-30 14:10:07 +01:00
1 parent ebb43658e1
commit c219958e48
3 files changed
+69 -3

No files matched your search

+23 -1
View File
@@ -7,6 +7,7 @@ from django import forms
from django.core.exceptions import ValidationError
from django.utils.timezone import get_current_timezone
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext_lazy
from PIL import Image
from core.utils import resize_image
@@ -17,9 +18,10 @@ 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 User
from core.models import Group, User
class AlbumCreateForm(forms.ModelForm):
@@ -84,6 +86,26 @@ class AlbumEditForm(forms.ModelForm):
f.file = resize_image(Image.open(f.file), 200, "WEBP")
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)}
)
return groups
def save(self, commit=True): # noqa: FBT002
initial_file = copy.copy(self.initial["file"])
if not self.cleaned_data["file"]: