mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-09 14:04:36 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f3e2d13ba | ||
|
|
ff72939503 | ||
|
|
ecaef644b3 | ||
|
|
564baf3b56 | ||
|
|
d4432a4963 | ||
|
|
43eedb274a | ||
|
|
c4cbcc3560 | ||
|
|
11206fae90 | ||
|
|
bacf100f6d
|
||
|
|
cbd80c17a2
|
+2
-2
@@ -50,8 +50,8 @@ class ClubAdmin(admin.ModelAdmin):
|
||||
@admin.register(ClubRole)
|
||||
class ClubRoleAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "club", "is_board", "is_presidency")
|
||||
search_fields = ("name",)
|
||||
autocomplete_fields = ("club",)
|
||||
search_fields = ("name", "club__name")
|
||||
autocomplete_fields = ("club", "linked_groups")
|
||||
list_select_related = ("club",)
|
||||
list_filter = (
|
||||
"is_board",
|
||||
|
||||
@@ -479,6 +479,13 @@ class ClubRoleCreateForm(forms.ModelForm):
|
||||
class ClubRoleBaseFormSet(forms.BaseInlineFormSet):
|
||||
ordering_widget = forms.HiddenInput()
|
||||
|
||||
def __init__(self, *args, queryset=None, **kwargs):
|
||||
if queryset is None:
|
||||
queryset = self.model._default_manager
|
||||
super().__init__(
|
||||
*args, queryset=queryset.prefetch_related("linked_groups"), **kwargs
|
||||
)
|
||||
|
||||
|
||||
ClubRoleFormSet = forms.inlineformset_factory(
|
||||
Club,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 5.2.17 on 2026-09-01 14:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("club", "0017_linktype_clublink"),
|
||||
("core", "0050_alter_sithfile_moderator"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="clubrole",
|
||||
name="linked_groups",
|
||||
field=models.ManyToManyField(
|
||||
help_text=(
|
||||
"Groups that are automatically given or removed "
|
||||
"to user receiving or losing this club role"
|
||||
),
|
||||
related_name="club_roles",
|
||||
to="core.group",
|
||||
verbose_name="Linked groups",
|
||||
),
|
||||
),
|
||||
]
|
||||
+33
-12
@@ -23,6 +23,8 @@
|
||||
#
|
||||
from __future__ import annotations
|
||||
|
||||
import operator
|
||||
from functools import reduce
|
||||
from typing import Iterable, Self
|
||||
|
||||
from django.conf import settings
|
||||
@@ -282,6 +284,15 @@ class ClubRole(OrderedModel):
|
||||
"If the role is inactive, people joining the club won't be able to get it."
|
||||
),
|
||||
)
|
||||
linked_groups = models.ManyToManyField(
|
||||
Group,
|
||||
verbose_name=_("Linked groups"),
|
||||
help_text=_(
|
||||
"Groups that are automatically given or removed "
|
||||
"to user receiving or losing this club role"
|
||||
),
|
||||
related_name="linked_roles",
|
||||
)
|
||||
|
||||
order_with_respect_to = "club"
|
||||
|
||||
@@ -534,7 +545,7 @@ class Membership(models.Model):
|
||||
def _remove_club_groups(
|
||||
memberships: Iterable[Membership],
|
||||
) -> tuple[int, dict[str, int]]:
|
||||
"""Remove users of those memberships from the club groups.
|
||||
"""Remove users of those memberships from the club and club role groups.
|
||||
|
||||
For example, if a user is in the Troll club board,
|
||||
he is in the board group and the members group of the Troll.
|
||||
@@ -553,15 +564,19 @@ class Membership(models.Model):
|
||||
clubs = {m.club_id for m in memberships}
|
||||
users = {m.user_id for m in memberships}
|
||||
groups = Group.objects.filter(Q(club__in=clubs) | Q(club_board__in=clubs))
|
||||
role_groups = [
|
||||
Q(user_id=m.user_id, group__linked_roles=m.role_id) for m in memberships
|
||||
]
|
||||
return User.groups.through.objects.filter(
|
||||
Q(group__in=groups) & Q(user__in=users)
|
||||
(Q(group__in=groups) & Q(user__in=users))
|
||||
| reduce(operator.or_, role_groups)
|
||||
).delete()
|
||||
|
||||
@staticmethod
|
||||
def _add_club_groups(
|
||||
memberships: Iterable[Membership],
|
||||
) -> list[User.groups.through]:
|
||||
"""Add users of those memberships to the club groups.
|
||||
"""Add users of those memberships to the club and club role groups.
|
||||
|
||||
For example, if a user just joined the Troll club board,
|
||||
he will be added in both the members group and the board group
|
||||
@@ -582,34 +597,40 @@ class Membership(models.Model):
|
||||
memberships = [m for m in memberships if m.end_date is None]
|
||||
if not memberships:
|
||||
return []
|
||||
|
||||
if sum(1 for m in memberships if not hasattr(m, "club")) > 1:
|
||||
nb_prefetched = sum(
|
||||
1 for m in memberships if not hasattr(m, "club") or not hasattr(m, "role")
|
||||
)
|
||||
if nb_prefetched > 1:
|
||||
# if more than one membership hasn't its `club` attribute set
|
||||
# it's less expensive to reload the whole query with
|
||||
# a select_related than perform a distinct query
|
||||
# to fetch each club.
|
||||
ids = {m.id for m in memberships}
|
||||
memberships = list(
|
||||
Membership.objects.filter(id__in=ids).select_related("club")
|
||||
Membership.objects.filter(id__in=ids)
|
||||
.select_related("club", "role")
|
||||
.prefetch_related("role__linked_groups")
|
||||
)
|
||||
club_groups = []
|
||||
groups = []
|
||||
for membership in memberships:
|
||||
club_groups.append(
|
||||
groups.append(
|
||||
User.groups.through(
|
||||
user_id=membership.user_id,
|
||||
group_id=membership.club.members_group_id,
|
||||
)
|
||||
)
|
||||
if membership.role.is_board:
|
||||
club_groups.append(
|
||||
groups.append(
|
||||
User.groups.through(
|
||||
user_id=membership.user_id,
|
||||
group_id=membership.club.board_group_id,
|
||||
)
|
||||
)
|
||||
return User.groups.through.objects.bulk_create(
|
||||
club_groups, ignore_conflicts=True
|
||||
)
|
||||
groups.extend(
|
||||
User.groups.through(user_id=membership.user_id, group_id=g.id)
|
||||
for g in membership.role.linked_groups.all()
|
||||
)
|
||||
return User.groups.through.objects.bulk_create(groups, ignore_conflicts=True)
|
||||
|
||||
|
||||
class Mailing(models.Model):
|
||||
|
||||
@@ -49,6 +49,20 @@
|
||||
{{ subform.is_active.help_text }}
|
||||
</span>
|
||||
</div>
|
||||
{% set groups = subform.instance.linked_groups.all()|list %}
|
||||
{% if groups %}
|
||||
<div>
|
||||
<p>
|
||||
<strong>{% trans %}Linked groups : {% endtrans %}</strong>
|
||||
{{ groups|map(attribute="name")|join(", ") }}
|
||||
</p>
|
||||
<p class="helptext">
|
||||
{% trans trimmed %}
|
||||
Users receiving this role will also be assigned to those groups
|
||||
{% endtrans %}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
@@ -17,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, User
|
||||
from core.models import AnonymousUser, Group, User
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
@@ -503,6 +503,29 @@ class TestMembership(TestClub):
|
||||
assert self.subscriber.groups.contains(self.club.members_group)
|
||||
assert self.subscriber.groups.contains(self.club.board_group)
|
||||
|
||||
def test_add_to_club_role_group(self):
|
||||
groups = baker.make(Group, _quantity=4)
|
||||
self.subscriber.groups.set(groups[:1])
|
||||
self.board_role.linked_groups.set(groups[1:3])
|
||||
baker.make(
|
||||
Membership, club=self.club, user=self.subscriber, role=self.board_role
|
||||
)
|
||||
assert set(self.subscriber.groups.all()) == {
|
||||
*groups[:3],
|
||||
self.club.board_group,
|
||||
self.club.members_group,
|
||||
}
|
||||
|
||||
def test_remove_from_club_role_group(self):
|
||||
groups = baker.make(Group, _quantity=3)
|
||||
baker.make(
|
||||
Membership, club=self.club, user=self.subscriber, role=self.board_role
|
||||
)
|
||||
self.subscriber.groups.set(groups[:1])
|
||||
self.board_role.linked_groups.set(groups[1:])
|
||||
self.subscriber.memberships.update(end_date=localdate())
|
||||
assert set(self.subscriber.groups.all()) == {groups[0]}
|
||||
|
||||
def test_change_position_in_club(self):
|
||||
"""Test that when moving from board to members, club group change"""
|
||||
membership = baker.make(
|
||||
|
||||
@@ -48,19 +48,26 @@ polyfillCountryFlagEmojis();
|
||||
/**
|
||||
* HTMX
|
||||
*/
|
||||
document.body.addEventListener(
|
||||
"htmx:before:request" as keyof HTMLElementEventMap,
|
||||
(event) => {
|
||||
(event as CustomEvent).detail.ctx.target.ariaBusy = true;
|
||||
htmx.registerExtension("aria-busy", {
|
||||
// biome-ignore lint/style/useNamingConvention: api's name
|
||||
htmx_before_request: (
|
||||
_: HTMLElement,
|
||||
detail: { ctx: { target: HTMLElement | undefined } },
|
||||
) => {
|
||||
if (detail.ctx.target !== undefined) {
|
||||
(detail.ctx.target as HTMLElement).ariaBusy = "true";
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
document.body.addEventListener(
|
||||
"htmx:before:swap" as keyof HTMLElementEventMap,
|
||||
(event) => {
|
||||
(event as CustomEvent).detail.ctx.target.ariaBusy = null;
|
||||
// biome-ignore lint/style/useNamingConvention: api's name
|
||||
htmx_after_swap: (
|
||||
_: HTMLElement,
|
||||
detail: { ctx: { target: HTMLElement | undefined } },
|
||||
) => {
|
||||
if (detail.ctx.target !== undefined) {
|
||||
(detail.ctx.target as HTMLElement).ariaBusy = null;
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Object.assign(window, { htmx });
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-09-04 11:24+0200\n"
|
||||
"POT-Creation-Date: 2026-09-08 23:36+0200\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"
|
||||
@@ -260,6 +260,18 @@ msgstr ""
|
||||
"Si ce rôle est inactif, il ne pourra pas être attribué aux gens qui "
|
||||
"rejoignent le club."
|
||||
|
||||
#: club/models.py
|
||||
msgid "Linked groups"
|
||||
msgstr "Groupes liés"
|
||||
|
||||
#: club/models.py
|
||||
msgid ""
|
||||
"Groups that are automatically given or removed to user receiving or losing "
|
||||
"this club role"
|
||||
msgstr ""
|
||||
"Les groupes qui sont automatiquement donnés ou retirés quand l'utilisateur "
|
||||
"reçoit ou perd ce rôle de club"
|
||||
|
||||
#: club/models.py election/models.py
|
||||
msgid "club role"
|
||||
msgstr "rôle de club"
|
||||
@@ -485,6 +497,14 @@ msgstr "Du"
|
||||
msgid "To"
|
||||
msgstr "Au"
|
||||
|
||||
#: club/templates/club/club_roles.jinja
|
||||
msgid "Linked groups : "
|
||||
msgstr "Groupes liés : "
|
||||
|
||||
#: club/templates/club/club_roles.jinja
|
||||
msgid "Users receiving this role will also be assigned to those groups"
|
||||
msgstr "Les utilisateurs recevant ce rôle seront aussi assignés à ces groupes"
|
||||
|
||||
#: club/templates/club/club_roles.jinja
|
||||
msgid ""
|
||||
"Roles give rights on the club. Higher roles grant more rights, and the "
|
||||
@@ -5832,6 +5852,17 @@ msgstr "les groupes pouvant créer des cotisations"
|
||||
msgid "Timetable generator"
|
||||
msgstr "Générateur d'emploi du temps"
|
||||
|
||||
#: timetable/templates/timetable/generator.jinja
|
||||
msgid ""
|
||||
"Wrong timetable format. Make sure you copied if from your student folder."
|
||||
msgstr ""
|
||||
"Mauvais format d'emploi du temps. Assurez-vous que vous l'avez copié depuis "
|
||||
"votre dossier étudiant."
|
||||
|
||||
#: timetable/templates/timetable/generator.jinja
|
||||
msgid "Incorrect row"
|
||||
msgstr "Ligne incorrecte"
|
||||
|
||||
#: timetable/templates/timetable/generator.jinja
|
||||
msgid "Generate"
|
||||
msgstr "Générer"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-05-17 10:03+0200\n"
|
||||
"POT-Creation-Date: 2026-09-08 23:36+0200\n"
|
||||
"PO-Revision-Date: 2024-09-17 11:54+0200\n"
|
||||
"Last-Translator: Sli <antoine@bartuccio.fr>\n"
|
||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||
@@ -22,8 +22,8 @@ msgid ""
|
||||
"You're going to remove your own role from the presidency. You may lock "
|
||||
"yourself out of this page. Do you want to continue ? "
|
||||
msgstr ""
|
||||
"Vous vous apprêtez à retirer votre propre rôle de la présidence. Vous risquez "
|
||||
"de perdre l'accès à cette page. Voulez-vous continuer ?"
|
||||
"Vous vous apprêtez à retirer votre propre rôle de la présidence. Vous "
|
||||
"risquez de perdre l'accès à cette page. Voulez-vous continuer ?"
|
||||
|
||||
#: com/static/bundled/com/components/ics-calendar-index.ts
|
||||
msgid "More info"
|
||||
@@ -279,9 +279,3 @@ msgstr "Il n'a pas été possible de modérer l'image"
|
||||
msgid "Couldn't delete picture"
|
||||
msgstr "Il n'a pas été possible de supprimer l'image"
|
||||
|
||||
#: timetable/static/bundled/timetable/generator-index.ts
|
||||
msgid ""
|
||||
"Wrong timetable format. Make sure you copied if from your student folder."
|
||||
msgstr ""
|
||||
"Mauvais format d'emploi du temps. Assurez-vous que vous l'avez copié depuis "
|
||||
"votre dossier étudiant."
|
||||
|
||||
+3
-3
@@ -92,11 +92,11 @@ docs = [
|
||||
default-groups = ["dev", "tests", "docs"]
|
||||
|
||||
[tool.xapian]
|
||||
version = "2.0.0"
|
||||
version = "2.1.0"
|
||||
# Those hashes are here to protect against supply chains attacks
|
||||
# See `https://ae-utbm.github.io/sith/howto/xapian/` for more information
|
||||
core-sha256 = "6cea3f49952a47224439a40bdb3608f928d121ad8721b9921cc42802d548ecf8"
|
||||
bindings-sha256 = "9a544b69c31355a92edbcd4102cf0f1ec4407fd0a4645f4870fb52300b736910"
|
||||
core-sha256 = "8e1259586d342e3d12b5e1f772e9185a10f2ba16e541566b5c3c239f71b8aacc"
|
||||
bindings-sha256 = "f52ec189f13b4fa66ea625a6eb94bb32dd651b9ec806be6a911dda54cbe3875c"
|
||||
|
||||
[tool.ruff]
|
||||
output-format = "concise" # makes ruff error logs easier to read
|
||||
|
||||
@@ -59,7 +59,7 @@ function parseSlots(s: string): TimetableSlot[] {
|
||||
.map((row: string) => {
|
||||
const parsed = TIMETABLE_ROW_RE.exec(row);
|
||||
if (!parsed?.groups) {
|
||||
throw new Error(`Couldn't parse row ${row}`);
|
||||
throw new Error(`Couldn't parse row ${row}`, { cause: { row: row } });
|
||||
}
|
||||
const [startHour, startMin] = parsed.groups.startHour
|
||||
.split(":")
|
||||
@@ -78,7 +78,7 @@ function parseSlots(s: string): TimetableSlot[] {
|
||||
document.addEventListener("alpine:init", () => {
|
||||
Alpine.data("timetableGenerator", () => ({
|
||||
content: DEFAULT_TIMETABLE,
|
||||
error: "",
|
||||
error: null as { incorrectRow?: string },
|
||||
displayedWeekdays: [] as WeekDay[],
|
||||
courses: [] as TimetableSlot[],
|
||||
startSlot: 0,
|
||||
@@ -106,10 +106,9 @@ document.addEventListener("alpine:init", () => {
|
||||
generate() {
|
||||
try {
|
||||
this.courses = parseSlots(this.content);
|
||||
} catch {
|
||||
this.error = gettext(
|
||||
"Wrong timetable format. Make sure you copied if from your student folder.",
|
||||
);
|
||||
this.error = null;
|
||||
} catch (err) {
|
||||
this.error = { incorrectRow: err?.cause?.row };
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,23 @@
|
||||
<div x-data="timetableGenerator">
|
||||
<form @submit.prevent="generate()">
|
||||
<h1>Générateur d'emploi du temps</h1>
|
||||
<div class="alert alert-red" x-show="!!error" x-cloak>
|
||||
<span class="alert-main" x-text="error"></span>
|
||||
</div>
|
||||
<template x-if="error !== null" x-cloak>
|
||||
<div class="alert alert-red">
|
||||
<div class="alert-main">
|
||||
<p>
|
||||
{% trans trimmed %}
|
||||
Wrong timetable format. Make sure you copied if from your student folder.
|
||||
{% endtrans %}
|
||||
</p>
|
||||
<template x-if="!!error.incorrectRow">
|
||||
<p>
|
||||
{% trans %}Incorrect row{% endtrans %} :
|
||||
<code x-text="error.incorrectRow"></code>
|
||||
</p>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="form-group">
|
||||
<label for="timetable-input">Colle ton emploi du temps (sans l'entête)</label>
|
||||
<textarea id="timetable-input" cols="30" rows="15" x-model="content"></textarea>
|
||||
|
||||
Reference in New Issue
Block a user