mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-04 06:42:47 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16810ea39f |
No files matched your search
+2
-30
@@ -25,7 +25,6 @@ import itertools
|
||||
from operator import attrgetter
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.db.models import Exists, OuterRef, Q, QuerySet
|
||||
from django.db.models.functions import Lower
|
||||
from django.forms.models import ModelChoiceField, ModelChoiceIterator
|
||||
@@ -183,12 +182,7 @@ class ClubOldMemberForm(forms.Form):
|
||||
|
||||
|
||||
class ClubMemberForm(forms.ModelForm):
|
||||
"""Base form to create a Membership.
|
||||
|
||||
Two subclasses exist :
|
||||
- one for adding any user to a club, that is shown to board members
|
||||
- the other for users without privileges to join the club as simple members.
|
||||
"""
|
||||
"""Form to add a member to the club, as a board member."""
|
||||
|
||||
error_css_class = "error"
|
||||
required_css_class = "required"
|
||||
@@ -253,29 +247,9 @@ class ClubAddMemberForm(ClubMemberForm):
|
||||
)
|
||||
return user
|
||||
|
||||
def clean(self):
|
||||
res = super().clean()
|
||||
if self.errors:
|
||||
return res
|
||||
user, role = self.cleaned_data["user"], self.cleaned_data["role"]
|
||||
if (
|
||||
role.is_board
|
||||
and user.ban_groups.filter(
|
||||
id=settings.SITH_GROUP_BANNED_RESPONSIBILITY_ID
|
||||
).exists()
|
||||
):
|
||||
raise forms.ValidationError(
|
||||
_("This user is banned from being in the board of a club"),
|
||||
code="banned",
|
||||
)
|
||||
return res
|
||||
|
||||
|
||||
class JoinClubForm(ClubMemberForm):
|
||||
"""Form to join a club.
|
||||
|
||||
Only member roles can be obtained through this form.
|
||||
"""
|
||||
"""Form to join a club."""
|
||||
|
||||
def __init__(self, *args, club: Club, request_user: User, **kwargs):
|
||||
super().__init__(*args, club=club, request_user=request_user, **kwargs)
|
||||
@@ -287,8 +261,6 @@ class JoinClubForm(ClubMemberForm):
|
||||
|
||||
def clean(self):
|
||||
"""Check that the user is subscribed and isn't already in the club."""
|
||||
# note: we don't check here if users are ban from joining a club board,
|
||||
# because this form manages only member roles.
|
||||
if not self.request_user.is_subscribed:
|
||||
raise forms.ValidationError(
|
||||
_("You must be subscribed to join a club"), code="invalid"
|
||||
|
||||
+6
-12
@@ -421,24 +421,18 @@ class MembershipQuerySet(models.QuerySet):
|
||||
"""Remove users from club groups they are no more in
|
||||
and add them in the club groups they should be in.
|
||||
|
||||
Be aware that this adds four db queries (on top of the UPDATE query) :
|
||||
Be aware that this adds three db queries :
|
||||
|
||||
- two to retrieve the updated memberships
|
||||
- one to retrieve the updated memberships
|
||||
- one to perform group removal
|
||||
- and one to perform group attribution.
|
||||
"""
|
||||
memberships = set(self.values_list("id", flat=True))
|
||||
if not memberships:
|
||||
# if there is no selected membership,there is nothing to do
|
||||
return 0
|
||||
nb_rows = super().update(**kwargs)
|
||||
if nb_rows == 0:
|
||||
# if no row was affected, no need to edit club groups
|
||||
return 0
|
||||
|
||||
# re-fetch the updated objects, with their new state.
|
||||
memberships = set(
|
||||
Membership.objects.filter(id__in=memberships)
|
||||
.select_related("club", "role")
|
||||
.prefetch_related("role__linked_groups")
|
||||
)
|
||||
memberships = set(self.select_related("club"))
|
||||
# delete all User-Group relations and recreate the necessary ones
|
||||
Membership._remove_club_groups(memberships)
|
||||
Membership._add_club_groups(memberships)
|
||||
|
||||
@@ -4,7 +4,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.core.cache import cache
|
||||
from django.db.models import Max
|
||||
@@ -18,7 +17,7 @@ from club.forms import ClubAddMemberForm, JoinClubForm
|
||||
from club.models import Club, ClubRole, Membership
|
||||
from club.tests.base import TestClub
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.models import AnonymousUser, Group, User, UserBan
|
||||
from core.models import AnonymousUser, Group, User
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
@@ -387,25 +386,6 @@ class TestMembership(TestClub):
|
||||
"user": ["Vous ne pouvez pas ajouter deux fois le même utilisateur"]
|
||||
}
|
||||
|
||||
def test_add_banned_user(self):
|
||||
user = subscriber_user.make()
|
||||
baker.make(
|
||||
UserBan,
|
||||
ban_group_id=settings.SITH_GROUP_BANNED_RESPONSIBILITY_ID,
|
||||
user=user,
|
||||
)
|
||||
form = ClubAddMemberForm(
|
||||
data={"user": user, "role": self.board_role},
|
||||
request_user=self.root,
|
||||
club=self.club,
|
||||
)
|
||||
assert not form.is_valid()
|
||||
assert form.errors == {
|
||||
"__all__": [
|
||||
"Cette personne a l'interdiction de rejoindre le bureau d'un club."
|
||||
]
|
||||
}
|
||||
|
||||
def test_add_other_member_forbidden(self):
|
||||
non_member = subscriber_user.make()
|
||||
simple_member = baker.make(
|
||||
|
||||
@@ -1006,7 +1006,6 @@ class Command(BaseCommand):
|
||||
BanGroup.objects.create(name="Banned from buying alcohol", description="")
|
||||
BanGroup.objects.create(name="Banned from counters", description="")
|
||||
BanGroup.objects.create(name="Banned to subscribe", description="")
|
||||
BanGroup.objects.create(name="Responsibility ban", description="")
|
||||
|
||||
def _create_elections(
|
||||
self,
|
||||
|
||||
@@ -775,8 +775,6 @@ class UserBan(models.Model):
|
||||
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
]:
|
||||
self.user.counters.clear()
|
||||
if self.ban_group_id == settings.SITH_GROUP_BANNED_RESPONSIBILITY_ID:
|
||||
self.user.memberships.ongoing().board().update(end_date=localdate())
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
+3
-19
@@ -5,7 +5,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import transaction
|
||||
from django.db.models import Count
|
||||
from django.forms.models import ModelChoiceIterator, ModelChoiceIteratorValue
|
||||
@@ -55,7 +54,9 @@ class CandidateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Candidature
|
||||
fields = ["user", "role", "program", "election_list"]
|
||||
labels = {"user": _("User to candidate")}
|
||||
labels = {
|
||||
"user": _("User to candidate"),
|
||||
}
|
||||
widgets = {
|
||||
"program": MarkdownInput,
|
||||
"user": AutoCompleteSelectUser,
|
||||
@@ -70,23 +71,6 @@ class CandidateForm(forms.ModelForm):
|
||||
if not can_edit:
|
||||
self.fields["user"].widget = forms.HiddenInput()
|
||||
|
||||
def clean_user(self):
|
||||
user = self.cleaned_data.get("user")
|
||||
if (
|
||||
user
|
||||
and user.ban_groups.filter(
|
||||
id__in=[
|
||||
settings.SITH_GROUP_BANNED_RESPONSIBILITY_ID,
|
||||
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
]
|
||||
).exists()
|
||||
):
|
||||
raise ValidationError(
|
||||
_("%(user)s is forbidden to run in a election.")
|
||||
% {"user": user.get_full_name()}
|
||||
)
|
||||
return user
|
||||
|
||||
|
||||
class VoteForm(forms.Form):
|
||||
def __init__(self, election: Election, user: User, *args, **kwargs):
|
||||
|
||||
@@ -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-14 13:59+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"
|
||||
@@ -227,10 +227,6 @@ msgstr "L'utilisateur doit être cotisant pour faire partie d'un club"
|
||||
msgid "You can not add the same user twice"
|
||||
msgstr "Vous ne pouvez pas ajouter deux fois le même utilisateur"
|
||||
|
||||
#: club/forms.py
|
||||
msgid "This user is banned from being in the board of a club"
|
||||
msgstr "Cette personne a l'interdiction de rejoindre le bureau d'un club."
|
||||
|
||||
#: club/forms.py
|
||||
msgid "You must be subscribed to join a club"
|
||||
msgstr "Vous devez être cotisant pour faire partie d'un club"
|
||||
@@ -1320,7 +1316,7 @@ msgstr "Nos services"
|
||||
msgid "UE Guide"
|
||||
msgstr "Guide des UEs"
|
||||
|
||||
#: com/templates/com/news_list.jinja core/views/user.py
|
||||
#: com/templates/com/news_list.jinja
|
||||
msgid "Timetable"
|
||||
msgstr "Emploi du temps"
|
||||
|
||||
@@ -4570,11 +4566,6 @@ msgstr "Vous avez sélectionné trop de candidats."
|
||||
msgid "User to candidate"
|
||||
msgstr "Utilisateur se présentant"
|
||||
|
||||
#: election/forms.py
|
||||
#, python-format
|
||||
msgid "%(user)s is forbidden to run in a election."
|
||||
msgstr "%(user)s n'a pas le droit de se présenter à une élection."
|
||||
|
||||
#: election/forms.py election/templates/election/election_detail.jinja
|
||||
msgid "Blank vote"
|
||||
msgstr "Vote blanc"
|
||||
@@ -5392,31 +5383,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
-1
@@ -85,7 +85,7 @@ tests = [
|
||||
docs = [
|
||||
"mkdocs>=1.6.1,<2.0.0",
|
||||
"mkdocs-material>=9.8.2,<10.0.0",
|
||||
"mkdocstrings>=1.0.6,<2.0.0",
|
||||
"mkdocstrings>=1.0.8,<2.0.0",
|
||||
"mkdocstrings-python>=2.0.11,<3.0.0",
|
||||
"mkdocs-include-markdown-plugin>=7.3.0,<8.0.0",
|
||||
]
|
||||
|
||||
@@ -4,11 +4,10 @@ from typing import TYPE_CHECKING
|
||||
import pytest
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.urls import reverse
|
||||
from django.utils.timezone import localdate, localtime
|
||||
from django.utils.timezone import localtime
|
||||
from model_bakery import baker
|
||||
from pytest_django.asserts import assertRedirects
|
||||
|
||||
from club.models import ClubRole, Membership
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.models import BanGroup, User, UserBan
|
||||
from counter.models import Counter
|
||||
@@ -67,28 +66,6 @@ def test_ban_counter_ends_barmanship():
|
||||
assert not user.counters.exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ban_responsability_ends_board_memberships():
|
||||
user = subscriber_user.make()
|
||||
roles = baker.make(ClubRole, is_board=iter([False, True]), _quantity=2)
|
||||
membership = baker.make(
|
||||
Membership, role=roles[0], club=roles[0].club, user=user, end_date=None
|
||||
)
|
||||
board_membership = baker.make(
|
||||
Membership, role=roles[1], club=roles[1].club, user=user, end_date=None
|
||||
)
|
||||
UserBan.objects.create(
|
||||
user=user,
|
||||
ban_group_id=settings.SITH_GROUP_BANNED_RESPONSIBILITY_ID,
|
||||
reason="ban responsabilités",
|
||||
)
|
||||
# only the board membership should be concluded
|
||||
membership.refresh_from_db()
|
||||
assert not membership.end_date
|
||||
board_membership.refresh_from_db()
|
||||
assert board_membership.end_date == localdate()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_remove_ban(client: Client, operator: User):
|
||||
client.force_login(operator)
|
||||
|
||||
+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))
|
||||
|
||||
@@ -403,9 +403,6 @@ SITH_GROUP_BANNED_COUNTER_ID = env.int("SITH_GROUP_BANNED_COUNTER_ID", default=1
|
||||
SITH_GROUP_BANNED_SUBSCRIPTION_ID = env.int(
|
||||
"SITH_GROUP_BANNED_SUBSCRIPTION_ID", default=14
|
||||
)
|
||||
SITH_GROUP_BANNED_RESPONSIBILITY_ID = env.int(
|
||||
"SITH_GROUP_BANNED_RESPONSIBILITY_ID", default=15
|
||||
)
|
||||
|
||||
SITH_CLUB_REFOUND_ID = env.int("SITH_CLUB_REFOUND_ID", default=89)
|
||||
SITH_COUNTER_REFOUND_ID = env.int("SITH_COUNTER_REFOUND_ID", default=38)
|
||||
|
||||
Reference in new issue
Block a user