mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-04 06:42:47 +00:00
forbid club simple member groups in album edit groups.
This commit is contained in:
1 parent
ebb43658e1
commit
c219958e48
3 files changed
+69
-3
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2026-11-27 11:02+0100\n"
|
"POT-Creation-Date: 2026-11-30 13:53+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"
|
||||||
@@ -5392,6 +5392,26 @@ msgstr "Vous n'avez pas la permission de faire cela"
|
|||||||
msgid "Upload images"
|
msgid "Upload images"
|
||||||
msgstr "Envoyer les images"
|
msgstr "Envoyer les images"
|
||||||
|
|
||||||
|
#: sas/forms.py
|
||||||
|
#, python-format
|
||||||
|
msgid ""
|
||||||
|
"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."
|
||||||
|
msgid_plural ""
|
||||||
|
"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."
|
||||||
|
msgstr[0] ""
|
||||||
|
"Vous ne pouvez pas accorder les droits d'édition au groupe %(groups)s. C'est "
|
||||||
|
"un groupe de simples membres de club, ce qui signifie que n'importe qui "
|
||||||
|
"pourrait devenir éditeur simplement en rejoignant le club."
|
||||||
|
msgstr[1] ""
|
||||||
|
"Vous ne pouvez pas accorder les droits d'édition aux groupes suivants : "
|
||||||
|
"%(groups)s. Ce sont des groupes de simples membres de club, ce qui signifie "
|
||||||
|
"que n'importe qui pourrait devenir éditeur simplement en rejoignant un des "
|
||||||
|
"club."
|
||||||
|
|
||||||
#: 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."
|
||||||
|
|||||||
+23
-1
@@ -7,6 +7,7 @@ from django import forms
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
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 PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from core.utils import resize_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
|
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 User
|
from core.models import Group, User
|
||||||
|
|
||||||
|
|
||||||
class AlbumCreateForm(forms.ModelForm):
|
class AlbumCreateForm(forms.ModelForm):
|
||||||
@@ -84,6 +86,26 @@ class AlbumEditForm(forms.ModelForm):
|
|||||||
f.file = resize_image(Image.open(f.file), 200, "WEBP")
|
f.file = resize_image(Image.open(f.file), 200, "WEBP")
|
||||||
return f
|
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
|
def save(self, commit=True): # noqa: FBT002
|
||||||
initial_file = copy.copy(self.initial["file"])
|
initial_file = copy.copy(self.initial["file"])
|
||||||
if not self.cleaned_data["file"]:
|
if not self.cleaned_data["file"]:
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from model_bakery import baker
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pytest_django.asserts import assertInHTML, assertRedirects
|
from pytest_django.asserts import assertInHTML, assertRedirects
|
||||||
|
|
||||||
|
from club.models import Club
|
||||||
from core.baker_recipes import subscriber_user
|
from core.baker_recipes import subscriber_user
|
||||||
from core.models import Group, User
|
from core.models import Group, User
|
||||||
from core.utils import RED_PIXEL_PNG
|
from core.utils import RED_PIXEL_PNG
|
||||||
@@ -90,7 +91,8 @@ def test_form_required(album: Album, excluded: str, is_valid: bool): # noqa: FB
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_form_album_name(album: Album):
|
def test_form_album_name_length(album: Album):
|
||||||
|
"""Test that the album name length constraint is enforced"""
|
||||||
data = {
|
data = {
|
||||||
"name": "a" * Album.NAME_MAX_LENGTH,
|
"name": "a" * Album.NAME_MAX_LENGTH,
|
||||||
"parent": album.pk,
|
"parent": album.pk,
|
||||||
@@ -102,6 +104,28 @@ def test_form_album_name(album: Album):
|
|||||||
assert not AlbumEditForm(data=data).is_valid()
|
assert not AlbumEditForm(data=data).is_valid()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_club_member_groups_cannot_be_edit_groups(album: Album):
|
||||||
|
club = baker.make(Club)
|
||||||
|
data = {
|
||||||
|
"name": album.name,
|
||||||
|
"parent": album.pk,
|
||||||
|
"date": localdate(),
|
||||||
|
"edit_groups": [club.members_group_id],
|
||||||
|
}
|
||||||
|
form = AlbumEditForm(data=data)
|
||||||
|
assert not form.is_valid()
|
||||||
|
assert form.errors == {
|
||||||
|
"edit_groups": [
|
||||||
|
f"Vous ne pouvez pas accorder les droits "
|
||||||
|
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."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_update_recursive_parent(client: Client, album: Album):
|
def test_update_recursive_parent(client: Client, album: Album):
|
||||||
client.force_login(baker.make(User, is_superuser=True))
|
client.force_login(baker.make(User, is_superuser=True))
|
||||||
|
|||||||
Reference in new issue
Block a user