mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-04 06:42:47 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b883e7b17a | ||
|
|
2c3580f776 |
No files matched your search
+7
-2
@@ -33,7 +33,11 @@ from django.contrib import messages
|
||||
from django.contrib.auth import login, views
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.forms import SetPasswordForm
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
||||
from django.contrib.auth.mixins import (
|
||||
LoginRequiredMixin,
|
||||
PermissionRequiredMixin,
|
||||
UserPassesTestMixin,
|
||||
)
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db.models import DateField, F, QuerySet, Sum
|
||||
@@ -591,7 +595,7 @@ class UserPreferencesView(UserTabsMixin, UseFragmentsMixin, CanEditMixin, Update
|
||||
return kwargs
|
||||
|
||||
|
||||
class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
|
||||
class UserUpdateGroupView(PermissionRequiredMixin, UserTabsMixin, UpdateView):
|
||||
"""Edit a user's groups."""
|
||||
|
||||
model = User
|
||||
@@ -600,6 +604,7 @@ class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
|
||||
form_class = UserGroupsForm
|
||||
context_object_name = "profile"
|
||||
current_tab = "groups"
|
||||
permission_required = "core.change_group"
|
||||
|
||||
|
||||
class UserToolsView(LoginRequiredMixin, UserTabsMixin, TemplateView):
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-12-02 13:40+0100\n"
|
||||
"POT-Creation-Date: 2026-11-27 11:02+0100\n"
|
||||
"PO-Revision-Date: 2016-07-18\n"
|
||||
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||
@@ -5392,31 +5392,6 @@ msgstr "Vous n'avez pas la permission de faire cela"
|
||||
msgid "Upload 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
|
||||
#, 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."
|
||||
|
||||
+1
-44
@@ -4,12 +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
|
||||
from PIL import Image
|
||||
|
||||
from core.utils import resize_image
|
||||
@@ -22,7 +19,7 @@ from sas.widgets.ajax_select import AutoCompleteSelectAlbum
|
||||
if TYPE_CHECKING:
|
||||
from django.db.models.fields.files import FieldFile
|
||||
|
||||
from core.models import Group, User
|
||||
from core.models import User
|
||||
|
||||
|
||||
class AlbumCreateForm(forms.ModelForm):
|
||||
@@ -87,46 +84,6 @@ class AlbumEditForm(forms.ModelForm):
|
||||
f.file = resize_image(Image.open(f.file), 200, "WEBP")
|
||||
return f
|
||||
|
||||
def clean_edit_groups(self):
|
||||
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
|
||||
initial_file = copy.copy(self.initial["file"])
|
||||
if not self.cleaned_data["file"]:
|
||||
|
||||
@@ -15,7 +15,6 @@ from model_bakery import baker
|
||||
from PIL import Image
|
||||
from pytest_django.asserts import assertInHTML, assertRedirects
|
||||
|
||||
from club.models import Club
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.models import Group, User
|
||||
from core.utils import RED_PIXEL_PNG
|
||||
@@ -91,8 +90,7 @@ def test_form_required(album: Album, excluded: str, is_valid: bool): # noqa: FB
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_form_album_name_length(album: Album):
|
||||
"""Test that the album name length constraint is enforced"""
|
||||
def test_form_album_name(album: Album):
|
||||
data = {
|
||||
"name": "a" * Album.NAME_MAX_LENGTH,
|
||||
"parent": album.pk,
|
||||
@@ -104,29 +102,6 @@ def test_form_album_name_length(album: Album):
|
||||
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, settings.SITH_GROUP_SUBSCRIBERS_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.",
|
||||
"Cotisants : ce groupe ne peut pas recevoir le droit d'éditer un album.",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_update_recursive_parent(client: Client, album: Album):
|
||||
client.force_login(baker.make(User, is_superuser=True))
|
||||
|
||||
Reference in new issue
Block a user