mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-04 06:42:47 +00:00
also forbid subscribers, old subscribers and public
This commit is contained in:
1 parent
c219958e48
commit
2c19e7b3fe
3 files changed
+47
-20
No files matched your search
+38
-17
@@ -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
|
||||
|
||||
Reference in new issue
Block a user