mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-20 16:09:54 +00:00
Merge pull request #1556 from ae-utbm/taiste
uv-managed uwsgi, model translation, some user tools and bugfixes
This commit is contained in:
64 files changed
+1827
-2340
No files matched your search
@@ -18,10 +18,7 @@ runs:
|
||||
version: 1.0 # increment to reset cache
|
||||
|
||||
- name: Install Redis
|
||||
if: ${{ inputs.full == 'true' }}
|
||||
uses: shogo82148/actions-setup-redis@v1
|
||||
with:
|
||||
redis-version: "7.x"
|
||||
|
||||
- name: "Set up Python"
|
||||
uses: actions/setup-python@v6
|
||||
|
||||
@@ -26,6 +26,17 @@ jobs:
|
||||
with:
|
||||
extra_args: --all-files
|
||||
|
||||
migration-check:
|
||||
name: Check missing migrations
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: ./.github/actions/setup_project
|
||||
with:
|
||||
full: false
|
||||
- name: check migrations
|
||||
run: uv run ./manage.py makemigrations --check
|
||||
|
||||
tests:
|
||||
name: Run tests and generate coverage report
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ from django import forms
|
||||
from django.core.validators import EmailValidator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from antispam.models import ToxicDomain
|
||||
from antispam.models.models import ToxicDomain
|
||||
|
||||
|
||||
class AntiSpamEmailValidator(EmailValidator):
|
||||
@@ -17,6 +17,6 @@ validate_antispam_email = AntiSpamEmailValidator()
|
||||
|
||||
|
||||
class AntiSpamEmailField(forms.EmailField):
|
||||
"""An email field that email addresses with a known toxic domain."""
|
||||
"""An email field that forbids email addresses with a known toxic domain."""
|
||||
|
||||
default_validators = [validate_antispam_email]
|
||||
@@ -38,22 +38,31 @@ class Command(BaseCommand):
|
||||
return domains
|
||||
|
||||
def _update_domains(self, domains: set[str]):
|
||||
# Cleanup database
|
||||
ToxicDomain.objects.filter(is_externally_managed=True).delete()
|
||||
|
||||
# Create database
|
||||
ToxicDomain.objects.bulk_create(
|
||||
[
|
||||
ToxicDomain(domain=domain, is_externally_managed=True)
|
||||
for domain in domains
|
||||
],
|
||||
ignore_conflicts=True,
|
||||
)
|
||||
existing = set(ToxicDomain.objects.values_list("domain", flat=True))
|
||||
if existing == domains:
|
||||
self.stdout.write("Domain database was up to date")
|
||||
return
|
||||
if to_remove := (existing - domains):
|
||||
# Cleanup database
|
||||
ToxicDomain.objects.filter(
|
||||
domain__in=to_remove, is_externally_managed=True
|
||||
).delete()
|
||||
if to_create := (domains - existing):
|
||||
# Create database
|
||||
ToxicDomain.objects.bulk_create(
|
||||
[
|
||||
ToxicDomain(domain=domain, is_externally_managed=True)
|
||||
for domain in to_create
|
||||
],
|
||||
ignore_conflicts=True,
|
||||
)
|
||||
self.stdout.write("Domain database updated")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not self._should_update(force=options["force"]):
|
||||
self.stdout.write("Domain database is up to date")
|
||||
self.stdout.write(
|
||||
"No update required. Use --force if you want to do it anyway."
|
||||
)
|
||||
return
|
||||
self.stdout.write("Updating domain database")
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from antispam.models.fields import AntiSpamEmailField
|
||||
from antispam.models.models import ToxicDomain
|
||||
|
||||
__all__ = ["AntiSpamEmailField", "ToxicDomain"]
|
||||
@@ -0,0 +1,21 @@
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
from antispam import forms
|
||||
|
||||
|
||||
class AntiSpamEmailField(models.EmailField):
|
||||
"""An email field that forbids email addresses with a known toxic domain."""
|
||||
|
||||
default_validators = [forms.validate_antispam_email]
|
||||
|
||||
|
||||
if settings.TESTING:
|
||||
from model_bakery import baker
|
||||
|
||||
baker.generators.add(
|
||||
AntiSpamEmailField, lambda: baker.random_gen.gen_email(max_length=100)
|
||||
)
|
||||
else: # pragma: no cover
|
||||
# baker is only used in tests, so we don't need coverage for this part
|
||||
pass
|
||||
File renamed without changes.
Whitespace-only changes.
+17
-115
@@ -31,20 +31,10 @@ from django.forms.models import ModelChoiceField, ModelChoiceIterator
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from club.models import (
|
||||
Club,
|
||||
ClubLink,
|
||||
ClubRole,
|
||||
Mailing,
|
||||
MailingSubscription,
|
||||
Membership,
|
||||
)
|
||||
from club.models import Club, ClubLink, ClubRole, Membership
|
||||
from core.models import User
|
||||
from core.views.forms import SelectDateTime
|
||||
from core.views.widgets.ajax_select import (
|
||||
AutoCompleteSelectMultipleUser,
|
||||
AutoCompleteSelectUser,
|
||||
)
|
||||
from core.views.widgets.ajax_select import AutoCompleteSelectUser
|
||||
from counter.models import Counter, Selling
|
||||
from counter.schemas import SaleFilterSchema
|
||||
|
||||
@@ -131,107 +121,6 @@ class ClubAdminEditForm(ClubEditForm):
|
||||
fields = ["name", "parent", "is_active", *ClubEditForm.Meta.fields]
|
||||
|
||||
|
||||
class MailingForm(forms.Form):
|
||||
"""Form handling mailing lists right."""
|
||||
|
||||
ACTION_NEW_MAILING = 1
|
||||
ACTION_NEW_SUBSCRIPTION = 2
|
||||
ACTION_REMOVE_SUBSCRIPTION = 3
|
||||
|
||||
subscription_users = forms.ModelMultipleChoiceField(
|
||||
label=_("Users to add"),
|
||||
help_text=_("Search users to add (one or more)."),
|
||||
required=False,
|
||||
widget=AutoCompleteSelectMultipleUser,
|
||||
queryset=User.objects.all(),
|
||||
)
|
||||
|
||||
def __init__(self, club_id, user_id, mailings, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.fields["action"] = forms.TypedChoiceField(
|
||||
choices=(
|
||||
(self.ACTION_NEW_MAILING, _("New Mailing")),
|
||||
(self.ACTION_NEW_SUBSCRIPTION, _("Subscribe")),
|
||||
(self.ACTION_REMOVE_SUBSCRIPTION, _("Remove")),
|
||||
),
|
||||
coerce=int,
|
||||
label=_("Action"),
|
||||
initial=1,
|
||||
required=True,
|
||||
widget=forms.HiddenInput(),
|
||||
)
|
||||
|
||||
# Generate bulk removal forms, they are never required
|
||||
for mailing in mailings:
|
||||
self.fields["removal_" + str(mailing.id)] = forms.ModelMultipleChoiceField(
|
||||
mailing.subscriptions.all(),
|
||||
label=_("Remove"),
|
||||
required=False,
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
)
|
||||
|
||||
# Include fields for handling mailing creation
|
||||
mailing_fields = ("email",)
|
||||
self.fields.update(forms.fields_for_model(Mailing, fields=mailing_fields))
|
||||
for field in mailing_fields:
|
||||
self.fields["mailing_" + field] = self.fields.pop(field)
|
||||
self.fields["mailing_" + field].required = False
|
||||
|
||||
# Include fields for handling subscription creation
|
||||
subscription_fields = ("mailing", "email")
|
||||
self.fields.update(
|
||||
forms.fields_for_model(MailingSubscription, fields=subscription_fields)
|
||||
)
|
||||
for field in subscription_fields:
|
||||
self.fields["subscription_" + field] = self.fields.pop(field)
|
||||
self.fields["subscription_" + field].required = False
|
||||
|
||||
self.fields["subscription_mailing"].queryset = Mailing.objects.filter(
|
||||
club__id=club_id, is_moderated=True
|
||||
)
|
||||
|
||||
def check_required(self, cleaned_data, field):
|
||||
"""If the given field doesn't exist or has no value, add a required error on it."""
|
||||
if not cleaned_data.get(field, None):
|
||||
self.add_error(field, _("This field is required"))
|
||||
|
||||
def clean_subscription_users(self):
|
||||
"""Convert given users into real users and check their validity."""
|
||||
cleaned_data = super().clean()
|
||||
users = []
|
||||
for user in cleaned_data["subscription_users"]:
|
||||
if not user.email:
|
||||
raise forms.ValidationError(
|
||||
_("One of the selected users doesn't have an email address"),
|
||||
code="invalid",
|
||||
)
|
||||
users.append(user)
|
||||
return users
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
if "action" not in cleaned_data:
|
||||
# If there is no action provided, we can stop here
|
||||
raise forms.ValidationError(_("An action is required"), code="invalid")
|
||||
|
||||
if cleaned_data["action"] == self.ACTION_NEW_MAILING:
|
||||
self.check_required(cleaned_data, "mailing_email")
|
||||
|
||||
if cleaned_data["action"] == self.ACTION_NEW_SUBSCRIPTION:
|
||||
self.check_required(cleaned_data, "subscription_mailing")
|
||||
if not cleaned_data.get(
|
||||
"subscription_users", None
|
||||
) and not cleaned_data.get("subscription_email", None):
|
||||
raise forms.ValidationError(
|
||||
_("You must specify at least an user or an email address"),
|
||||
code="invalid",
|
||||
)
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class SellingsForm(forms.Form):
|
||||
begin_date = forms.DateTimeField(
|
||||
label=_("Begin date"), widget=SelectDateTime, required=False
|
||||
@@ -413,12 +302,22 @@ class ClubRoleForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = ClubRole
|
||||
fields = ["name", "description", "is_presidency", "is_board", "is_active"]
|
||||
fields = [
|
||||
"name",
|
||||
"name_en",
|
||||
"description",
|
||||
"is_presidency",
|
||||
"is_board",
|
||||
"is_active",
|
||||
]
|
||||
widgets = {
|
||||
"is_presidency": forms.HiddenInput(),
|
||||
"is_board": forms.HiddenInput(),
|
||||
"is_active": forms.CheckboxInput(attrs={"class": "switch"}),
|
||||
}
|
||||
help_texts = {
|
||||
"name_en": _("Provide an english name for non-french speaking users.")
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
@@ -465,7 +364,10 @@ class ClubRoleCreateForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = ClubRole
|
||||
fields = ["name", "description"]
|
||||
fields = ["name", "name_en", "description"]
|
||||
help_texts = {
|
||||
"name_en": _("Provide an english name for non-french speaking users.")
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self, *args, club: Club, is_presidency: bool, is_board: bool, **kwargs
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# Generated by Django 5.2.17 on 2026-10-15 13:13
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("club", "0018_clubrole_linked_groups")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name="mailingsubscription", unique_together=None
|
||||
),
|
||||
migrations.RemoveField(model_name="mailingsubscription", name="user"),
|
||||
migrations.DeleteModel(name="Mailing"),
|
||||
migrations.DeleteModel(name="MailingSubscription"),
|
||||
]
|
||||
@@ -0,0 +1,72 @@
|
||||
# Generated by Django 5.2.18 on 2026-11-14 11:44
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db.models import F
|
||||
from django.db.models.expressions import Case, Value, When
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.db.migrations.state import StateApps
|
||||
|
||||
|
||||
def copy_name(apps: StateApps, schema_editor):
|
||||
"""Automatically populate French names and the most common English ones"""
|
||||
ClubRole = apps.get_model("club", "ClubRole")
|
||||
ClubRole.objects.update(
|
||||
name_fr=F("name"),
|
||||
name_en=Case(
|
||||
When(name="Président⸱e", then=Value("President")),
|
||||
When(name="Vice-Président⸱e", then=Value("Vice-president")),
|
||||
When(name="Trésorier⸱e", then=Value("Treasurer")),
|
||||
When(name="Responsable communication", then=Value("Communication manager")),
|
||||
When(name="Secrétaire", then=Value("Secretary")),
|
||||
When(name="Responsable info", then=Value("IT manager")),
|
||||
When(name="Membre du bureau", then=Value("Board member")),
|
||||
When(name="Membre actif⸱ve", then=Value("Active member")),
|
||||
When(name="Curieux⸱euse", then=Value("Curious")),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("club", "0019_remove_mailingsubscription_mailing_and_more")]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="clubrole",
|
||||
name="name_en",
|
||||
field=models.CharField(max_length=50, null=True, verbose_name="name"),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="clubrole",
|
||||
name="name_fr",
|
||||
field=models.CharField(max_length=50, null=True, verbose_name="name"),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="clubrole",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("club", "name"),
|
||||
name="clubrole_club_name_unique",
|
||||
violation_error_message="There is already a role with that name",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="clubrole",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("club", "name_fr"),
|
||||
name="clubrole_club_name_unique-fr",
|
||||
violation_error_message="There is already a role with that name",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="clubrole",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("club", "name_en"),
|
||||
name="clubrole_club_name_unique-en",
|
||||
violation_error_message="There is already a role with that name",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
copy_name, reverse_code=migrations.RunPython.noop, elidable=True
|
||||
),
|
||||
]
|
||||
+8
-167
@@ -28,8 +28,7 @@ from functools import reduce
|
||||
from typing import Iterable, Self
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
from django.core.validators import RegexValidator, validate_email
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import ProgrammingError, models, transaction
|
||||
from django.db.models import Exists, F, OuterRef, Q
|
||||
from django.urls import reverse
|
||||
@@ -41,7 +40,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from ordered_model.models import OrderedModel
|
||||
|
||||
from core.fields import ResizedImageField
|
||||
from core.models import Group, Notification, Page, SithFile, User
|
||||
from core.models import Group, Page, SithFile, User
|
||||
|
||||
|
||||
class ClubQuerySet(models.QuerySet):
|
||||
@@ -308,7 +307,12 @@ class ClubRole(OrderedModel):
|
||||
violation_error_message=_(
|
||||
"A role cannot be in the presidency while not being in the board"
|
||||
),
|
||||
)
|
||||
),
|
||||
models.UniqueConstraint(
|
||||
fields=("club", "name"),
|
||||
name="clubrole_club_name_unique",
|
||||
violation_error_message=_("There is already a role with that name"),
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
@@ -633,169 +637,6 @@ class Membership(models.Model):
|
||||
return User.groups.through.objects.bulk_create(groups, ignore_conflicts=True)
|
||||
|
||||
|
||||
class Mailing(models.Model):
|
||||
"""A Mailing list for a club.
|
||||
|
||||
Warning:
|
||||
Remember that mailing lists should be validated by UTBM.
|
||||
"""
|
||||
|
||||
club = models.ForeignKey(
|
||||
Club,
|
||||
verbose_name=_("Club"),
|
||||
related_name="mailings",
|
||||
null=False,
|
||||
blank=False,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
email = models.CharField(
|
||||
_("Email address"),
|
||||
unique=True,
|
||||
null=False,
|
||||
blank=False,
|
||||
max_length=256,
|
||||
validators=[
|
||||
RegexValidator(
|
||||
validate_email.user_regex,
|
||||
_("Enter a valid address. Only the root of the address is needed."),
|
||||
)
|
||||
],
|
||||
)
|
||||
is_moderated = models.BooleanField(_("is moderated"), default=False)
|
||||
moderator = models.ForeignKey(
|
||||
User,
|
||||
related_name="moderated_mailings",
|
||||
verbose_name=_("moderator"),
|
||||
null=True,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s" % (self.club, self.email_full)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.is_moderated:
|
||||
unread_notif_subquery = Notification.objects.filter(
|
||||
user=OuterRef("pk"), type="MAILING_MODERATION", viewed=False
|
||||
)
|
||||
for user in User.objects.filter(
|
||||
~Exists(unread_notif_subquery),
|
||||
groups__id__in=[settings.SITH_GROUP_COM_ADMIN_ID],
|
||||
):
|
||||
Notification(
|
||||
user=user,
|
||||
url=reverse("com:mailing_admin"),
|
||||
type="MAILING_MODERATION",
|
||||
).save(*args, **kwargs)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
if Mailing.objects.filter(email=self.email).exists():
|
||||
raise ValidationError(_("This mailing list already exists."))
|
||||
if self.can_moderate(self.moderator):
|
||||
self.is_moderated = True
|
||||
else:
|
||||
self.moderator = None
|
||||
super().clean()
|
||||
|
||||
@property
|
||||
def email_full(self):
|
||||
return self.email + "@" + settings.SITH_MAILING_DOMAIN
|
||||
|
||||
def can_moderate(self, user):
|
||||
return user.is_root or user.is_com_admin
|
||||
|
||||
def is_owned_by(self, user):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_root or user.is_com_admin
|
||||
|
||||
def can_view(self, user):
|
||||
return self.club.has_rights_in_club(user)
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
return self.club.has_rights_in_club(user)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.subscriptions.all().delete()
|
||||
super().delete()
|
||||
|
||||
def fetch_format(self):
|
||||
destination = "".join(s.fetch_format() for s in self.subscriptions.all())
|
||||
return f"{self.email}: {destination}"
|
||||
|
||||
|
||||
class MailingSubscription(models.Model):
|
||||
"""Link between user and mailing list."""
|
||||
|
||||
mailing = models.ForeignKey(
|
||||
Mailing,
|
||||
verbose_name=_("Mailing"),
|
||||
related_name="subscriptions",
|
||||
null=False,
|
||||
blank=False,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
verbose_name=_("User"),
|
||||
related_name="mailing_subscriptions",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
email = models.EmailField(_("Email address"), blank=False, null=False)
|
||||
|
||||
class Meta:
|
||||
unique_together = (("user", "email", "mailing"),)
|
||||
|
||||
def __str__(self):
|
||||
return "(%s) - %s : %s" % (self.mailing, self.get_username, self.email)
|
||||
|
||||
def clean(self):
|
||||
if not self.user and not self.email:
|
||||
raise ValidationError(_("At least user or email is required"))
|
||||
try:
|
||||
if self.user and not self.email:
|
||||
self.email = self.user.email
|
||||
if MailingSubscription.objects.filter(
|
||||
mailing=self.mailing, email=self.email
|
||||
).exists():
|
||||
raise ValidationError(
|
||||
_("This email is already suscribed in this mailing")
|
||||
)
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
super().clean()
|
||||
|
||||
def is_owned_by(self, user):
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return (
|
||||
self.mailing.club.has_rights_in_club(user)
|
||||
or user.is_root
|
||||
or self.user.is_com_admin
|
||||
)
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
return self.user is not None and user.id == self.user.id
|
||||
|
||||
@cached_property
|
||||
def get_email(self):
|
||||
if self.user and not self.email:
|
||||
return self.user.email
|
||||
return self.email
|
||||
|
||||
@cached_property
|
||||
def get_username(self):
|
||||
if self.user:
|
||||
return str(self.user)
|
||||
return _("Unregistered user")
|
||||
|
||||
def fetch_format(self):
|
||||
return self.get_email + " "
|
||||
|
||||
|
||||
class LinkType(models.Model):
|
||||
"""A link type, in order to group links and give them icons.
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
<div class="form-group">
|
||||
{{ subform.name.as_field_group() }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ subform.name_en.as_field_group() }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ subform.description.as_field_group() }}
|
||||
</div>
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
{% trans %}Post in the Weekmail{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
{% if object.can_roles_be_edited_by(user) %}
|
||||
<li><a href="{{ url("club:club_roles", club_id=object.id) }}"></a></li>
|
||||
{% endif %}
|
||||
{% if object.trombi %}
|
||||
<li> <a href="{{ url('trombi:detail', trombi_id=object.trombi.id) }}">{% trans %}Edit Trombi{% endtrans %}</a></li>
|
||||
{% else %}
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'core/macros.jinja' import select_all_checkbox %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Mailing lists{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<b>{% trans %}Remember : mailing lists need to be moderated, if your new created list is not shown wait until moderation takes action{% endtrans %}</b>
|
||||
|
||||
{% if mailings_not_moderated %}
|
||||
<p>{% trans %}Mailing lists waiting for moderation{% endtrans %}</p>
|
||||
<ul>
|
||||
{% for mailing in mailings_not_moderated %}
|
||||
<li>{{ mailing.email_full }}<a href="{{ url('club:mailing_delete', mailing_id=mailing.id) }}"> - {% trans %}Delete{% endtrans %}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% if mailings_moderated %}
|
||||
{% for mailing in mailings_moderated %}
|
||||
<h2>{% trans %}Mailing{% endtrans %} {{ mailing.email_full }}
|
||||
{%- if user.is_owner(mailing) -%}
|
||||
<a href="{{ url('club:mailing_delete', mailing_id=mailing.id) }}"> - {% trans %}Delete{% endtrans %}</a>
|
||||
{%- endif -%}
|
||||
</h2>
|
||||
<form method="GET" action="{{ url('club:mailing_generate', mailing_id=mailing.id) }}" style="display:inline-block;">
|
||||
<input type="submit" name="generateMalingList" value="{% trans %}Generate mailing list{% endtrans %}">
|
||||
</form>
|
||||
{% set form_mailing_removal = form["removal_" + mailing.id|string] %}
|
||||
{% if form_mailing_removal.field.choices %}
|
||||
{% set ms = dict(mailing.subscriptions.all() | groupby('id')) %}
|
||||
<form action="{{ url('club:mailing', club_id=club.id) }}" id="{{ form_mailing_removal.auto_id }}" method="post" enctype="multipart/form-data">
|
||||
<p style="margin-bottom: 1em;">{{ select_all_checkbox(form_mailing_removal.auto_id) }}</p>
|
||||
{% csrf_token %}
|
||||
<input hidden type="number" name="{{ form.action.name }}" value="{{ form_actions.REMOVE_SUBSCRIPTION }}" />
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}User{% endtrans %}</td>
|
||||
<td>{% trans %}Email{% endtrans %}</td>
|
||||
<td>{% trans %}Delete{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for widget in form_mailing_removal.subwidgets %}
|
||||
{% set user = ms[widget.data.value.value][0] %}
|
||||
<tr>
|
||||
<td>{{ user.get_username }}</td>
|
||||
<td>{{ user.get_email }}</td>
|
||||
<td>{{ widget.tag() }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{{ form_mailing_removal.errors }}
|
||||
<p><input type="submit" value="{% trans %}Remove from mailing list{% endtrans %}" /></p>
|
||||
</form>
|
||||
|
||||
{% else %}
|
||||
<p><b>{% trans %}There is no subscriber for this mailing list{% endtrans %}</b></p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% else %}
|
||||
<p>{% trans %}No mailing list existing for this club{% endtrans %}</p>
|
||||
{% endif %}
|
||||
|
||||
<p>{{ form.non_field_errors() }}</p>
|
||||
{% if mailings_moderated %}
|
||||
<h2>{% trans %}New member{% endtrans %}</h2>
|
||||
<form action="{{ url('club:mailing', club_id=club.id) }}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<p>
|
||||
{{ form.subscription_mailing.errors }}
|
||||
<label for="{{ form.subscription_mailing.id_for_label }}">{{ form.subscription_mailing.label }}</label>
|
||||
{{ form.subscription_mailing }}
|
||||
</p>
|
||||
<p>
|
||||
{{ form.subscription_users.errors }}
|
||||
<label for="{{ form.subscription_users.id_for_label }}">{{ form.subscription_users.label }}</label>
|
||||
{{ form.subscription_users }}
|
||||
<span class="helptext">{{ form.subscription_users.help_text }}</span>
|
||||
</p>
|
||||
<p>
|
||||
{{ form.subscription_email.errors }}
|
||||
<label for="{{ form.subscription_email.id_for_label }}">{{ form.subscription_email.label }}</label>
|
||||
{{ form.subscription_email }}
|
||||
</p>
|
||||
<input hidden type="number" name="{{ form.action.name }}" value="{{ form_actions.NEW_SUBSCRIPTION }}" />
|
||||
<p><input type="submit" value="{% trans %}Add to mailing list{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<h2>{% trans %}New mailing{% endtrans %}</h2>
|
||||
<form action="{{ url('club:mailing', club_id=club.id) }}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<p>
|
||||
{{ form.mailing_email.errors }}
|
||||
<label for="{{ form.mailing_email.id_for_label }}">{{ form.mailing_email.label }}</label>
|
||||
{{ form.mailing_email }}
|
||||
</p>
|
||||
<input hidden type="number" name="{{ form.action.name }}" value="{{ form_actions.NEW_MALING }}" />
|
||||
<p><input type="submit" value="{% trans %}Create mailing list{% endtrans %}" /></p>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -4,6 +4,7 @@ import pytest
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import translation
|
||||
from django.utils.timezone import now
|
||||
from model_bakery import baker, seq
|
||||
from model_bakery.recipe import Recipe
|
||||
@@ -281,3 +282,14 @@ class TestClubRoleUpdate(TestCase):
|
||||
# the second membership is finished, so its user shouldn't get the role
|
||||
assert members[0].user.groups.contains(self.club.board_group)
|
||||
assert not members[1].user.groups.contains(self.club.board_group)
|
||||
|
||||
def test_name_translation(self):
|
||||
"""Test that setting the english name works."""
|
||||
name_en = "something something"
|
||||
self.payload["roles-0-name_en"] = name_en
|
||||
formset = ClubRoleFormSet(data=self.payload, instance=self.club)
|
||||
assert formset.is_valid()
|
||||
formset.save()
|
||||
self.roles[0].refresh_from_db()
|
||||
with translation.override("en"):
|
||||
assert self.roles[0].name == name_en
|
||||
@@ -1,328 +0,0 @@
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext as _
|
||||
from model_bakery import baker
|
||||
|
||||
from club.forms import MailingForm
|
||||
from club.models import Club, ClubRole, Mailing, Membership
|
||||
from core.models import User
|
||||
|
||||
|
||||
class TestMailingForm(TestCase):
|
||||
"""Perform validation tests for MailingForm."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.skia = User.objects.get(username="skia")
|
||||
cls.rbatsbak = User.objects.get(username="rbatsbak")
|
||||
cls.krophil = User.objects.get(username="krophil")
|
||||
cls.comunity = User.objects.get(username="comunity")
|
||||
cls.root = User.objects.get(username="root")
|
||||
cls.club = Club.objects.get(id=settings.SITH_PDF_CLUB_ID)
|
||||
cls.mail_url = reverse("club:mailing", kwargs={"club_id": cls.club.id})
|
||||
Membership(
|
||||
user=cls.rbatsbak,
|
||||
club=cls.club,
|
||||
start_date=timezone.now(),
|
||||
role=baker.make(ClubRole, club=cls.club, is_board=True),
|
||||
).save()
|
||||
|
||||
def test_mailing_list_add_no_moderation(self):
|
||||
# Test with Communication admin
|
||||
self.client.force_login(self.comunity)
|
||||
response = self.client.post(
|
||||
self.mail_url,
|
||||
{"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "foyer"},
|
||||
)
|
||||
self.assertRedirects(response, self.mail_url)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
assert "Liste de diffusion foyer@utbm.fr" in response.text
|
||||
|
||||
# Test with Root
|
||||
self.client.force_login(self.root)
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
assert "Liste de diffusion mde@utbm.fr" in response.text
|
||||
|
||||
def test_mailing_list_add_moderation(self):
|
||||
self.client.force_login(self.rbatsbak)
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
content = response.text
|
||||
assert "Liste de diffusion mde@utbm.fr" not in content
|
||||
assert "<p>Listes de diffusions en attente de modération</p>" in content
|
||||
assert "<li>mde@utbm.fr" in content
|
||||
|
||||
def test_mailing_list_forbidden(self):
|
||||
# With anonymous user
|
||||
response = self.client.get(self.mail_url)
|
||||
self.assertContains(response, "", status_code=403)
|
||||
|
||||
# With user not in club
|
||||
self.client.force_login(self.krophil)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 403
|
||||
|
||||
def test_add_new_subscription_fail_not_moderated(self):
|
||||
self.client.force_login(self.rbatsbak)
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
|
||||
)
|
||||
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": self.skia.id,
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
assert "skia@git.an" not in response.text
|
||||
|
||||
def test_add_new_subscription_success(self):
|
||||
# Prepare mailing list
|
||||
self.client.force_login(self.comunity)
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
|
||||
)
|
||||
|
||||
# Add single user
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": self.skia.id,
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
assert "skia@git.an" in response.text
|
||||
|
||||
# Add multiple users
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": (self.comunity.id, self.rbatsbak.id),
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
content = response.text
|
||||
assert "richard@git.an" in content
|
||||
assert "comunity@git.an" in content
|
||||
assert "skia@git.an" in content
|
||||
|
||||
# Add arbitrary email
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_email": "arbitrary@git.an",
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
content = response.text
|
||||
assert "richard@git.an" in content
|
||||
assert "comunity@git.an" in content
|
||||
assert "skia@git.an" in content
|
||||
assert "arbitrary@git.an" in content
|
||||
|
||||
# Add user and arbitrary email
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_email": "more.arbitrary@git.an",
|
||||
"subscription_users": self.krophil.id,
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
content = response.text
|
||||
assert "richard@git.an" in content
|
||||
assert "comunity@git.an" in content
|
||||
assert "skia@git.an" in content
|
||||
assert "arbitrary@git.an" in content
|
||||
assert "more.arbitrary@git.an" in content
|
||||
assert "krophil@git.an" in content
|
||||
|
||||
def test_add_new_subscription_fail_form_errors(self):
|
||||
# Prepare mailing list
|
||||
self.client.force_login(self.comunity)
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
|
||||
)
|
||||
|
||||
# Neither email or email is specified
|
||||
response = self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
assert response.status_code
|
||||
self.assertInHTML(
|
||||
_("You must specify at least an user or an email address"),
|
||||
response.text,
|
||||
)
|
||||
|
||||
# No mailing specified
|
||||
response = self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": self.krophil.id,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert _("This field is required") in response.text
|
||||
|
||||
# One of the selected users doesn't exist
|
||||
response = self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": [789],
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
self.assertInHTML(
|
||||
_("You must specify at least an user or an email address"),
|
||||
response.text,
|
||||
)
|
||||
|
||||
# An user has no email address
|
||||
self.krophil.email = ""
|
||||
self.krophil.save()
|
||||
|
||||
response = self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": self.krophil.id,
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
self.assertInHTML(
|
||||
_("One of the selected users doesn't have an email address"),
|
||||
response.text,
|
||||
)
|
||||
|
||||
self.krophil.email = "krophil@git.an"
|
||||
self.krophil.save()
|
||||
|
||||
# An user is added twice
|
||||
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": self.krophil.id,
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": self.krophil.id,
|
||||
"subscription_mailing": Mailing.objects.get(email="mde").id,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
self.assertInHTML(
|
||||
_("This email is already suscribed in this mailing"),
|
||||
response.text,
|
||||
)
|
||||
|
||||
def test_remove_subscription_success(self):
|
||||
# Prepare mailing list
|
||||
self.client.force_login(self.comunity)
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{"action": MailingForm.ACTION_NEW_MAILING, "mailing_email": "mde"},
|
||||
)
|
||||
mde = Mailing.objects.get(email="mde")
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_NEW_SUBSCRIPTION,
|
||||
"subscription_users": (
|
||||
self.comunity.id,
|
||||
self.rbatsbak.id,
|
||||
self.krophil.id,
|
||||
),
|
||||
"subscription_mailing": mde.id,
|
||||
},
|
||||
)
|
||||
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
content = response.text
|
||||
|
||||
assert "comunity@git.an" in content
|
||||
assert "richard@git.an" in content
|
||||
assert "krophil@git.an" in content
|
||||
|
||||
# Delete one user
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_REMOVE_SUBSCRIPTION,
|
||||
"removal_%d" % mde.id: mde.subscriptions.get(user=self.krophil).id,
|
||||
},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
content = response.text
|
||||
|
||||
assert "comunity@git.an" in content
|
||||
assert "richard@git.an" in content
|
||||
assert "krophil@git.an" not in content
|
||||
|
||||
# Delete multiple users
|
||||
self.client.post(
|
||||
self.mail_url,
|
||||
{
|
||||
"action": MailingForm.ACTION_REMOVE_SUBSCRIPTION,
|
||||
"removal_%d" % mde.id: [
|
||||
user.id
|
||||
for user in mde.subscriptions.filter(
|
||||
user__in=[self.rbatsbak, self.comunity]
|
||||
).all()
|
||||
],
|
||||
},
|
||||
)
|
||||
response = self.client.get(self.mail_url)
|
||||
assert response.status_code == 200
|
||||
content = response.text
|
||||
|
||||
assert "comunity@git.an" not in content
|
||||
assert "richard@git.an" not in content
|
||||
assert "krophil@git.an" not in content
|
||||
@@ -0,0 +1,8 @@
|
||||
from modeltranslation.translator import TranslationOptions, register
|
||||
|
||||
from club.models import ClubRole
|
||||
|
||||
|
||||
@register(ClubRole)
|
||||
class ClubRoleTranslationOptions(TranslationOptions):
|
||||
fields = ("name",)
|
||||
@@ -29,7 +29,6 @@ from club.views import (
|
||||
ClubCreateView,
|
||||
ClubEditView,
|
||||
ClubListView,
|
||||
ClubMailingView,
|
||||
ClubMembersView,
|
||||
ClubNewsView,
|
||||
ClubOldMembersView,
|
||||
@@ -44,9 +43,6 @@ from club.views import (
|
||||
ClubSellingView,
|
||||
ClubToolsView,
|
||||
ClubView,
|
||||
MailingAutoGenerationView,
|
||||
MailingDeleteView,
|
||||
MailingSubscriptionDeleteView,
|
||||
MembershipDeleteView,
|
||||
MembershipSetOldView,
|
||||
PosterCreateView,
|
||||
@@ -97,22 +93,6 @@ urlpatterns = [
|
||||
"<int:club_id>/sellings/csv/", ClubSellingCSVView.as_view(), name="sellings_csv"
|
||||
),
|
||||
path("<int:club_id>/tools/", ClubToolsView.as_view(), name="tools"),
|
||||
path("<int:club_id>/mailing/", ClubMailingView.as_view(), name="mailing"),
|
||||
path(
|
||||
"<int:mailing_id>/mailing/generate/",
|
||||
MailingAutoGenerationView.as_view(),
|
||||
name="mailing_generate",
|
||||
),
|
||||
path(
|
||||
"<int:mailing_id>/mailing/delete/",
|
||||
MailingDeleteView.as_view(),
|
||||
name="mailing_delete",
|
||||
),
|
||||
path(
|
||||
"<int:mailing_subscription_id>/mailing/delete/subscription/",
|
||||
MailingSubscriptionDeleteView.as_view(),
|
||||
name="mailing_subscription_delete",
|
||||
),
|
||||
path(
|
||||
"membership/<int:membership_id>/set_old/",
|
||||
MembershipSetOldView.as_view(),
|
||||
|
||||
-171
@@ -34,7 +34,6 @@ from django.contrib.auth.mixins import (
|
||||
UserPassesTestMixin,
|
||||
)
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.exceptions import NON_FIELD_ERRORS, PermissionDenied, ValidationError
|
||||
from django.core.paginator import InvalidPage, Paginator
|
||||
from django.db.models import F, Prefetch, Q, Sum
|
||||
from django.db.models.expressions import OuterRef, Subquery
|
||||
@@ -60,7 +59,6 @@ from club.forms import (
|
||||
ClubRoleFormSet,
|
||||
ClubSearchForm,
|
||||
JoinClubForm,
|
||||
MailingForm,
|
||||
SellingsForm,
|
||||
)
|
||||
from club.models import (
|
||||
@@ -68,8 +66,6 @@ from club.models import (
|
||||
ClubLink,
|
||||
ClubRole,
|
||||
LinkType,
|
||||
Mailing,
|
||||
MailingSubscription,
|
||||
Membership,
|
||||
)
|
||||
from com.models import NewsDate, Poster
|
||||
@@ -166,13 +162,6 @@ class ClubTabsMixin(TabedViewMixin):
|
||||
"slug": "sellings",
|
||||
"name": _("Sellings"),
|
||||
},
|
||||
{
|
||||
"url": reverse(
|
||||
"club:mailing", kwargs={"club_id": self.object.id}
|
||||
),
|
||||
"slug": "mailing",
|
||||
"name": _("Mailing list"),
|
||||
},
|
||||
{
|
||||
"url": reverse(
|
||||
"club:poster_list", kwargs={"club_id": self.object.id}
|
||||
@@ -727,166 +716,6 @@ class MembershipDeleteView(PermissionRequiredMixin, DeleteView):
|
||||
return reverse_lazy("core:user_clubs", kwargs={"user_id": self.object.user_id})
|
||||
|
||||
|
||||
class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
"""A list of mailing for a given club."""
|
||||
|
||||
model = Club
|
||||
form_class = MailingForm
|
||||
pk_url_kwarg = "club_id"
|
||||
template_name = "club/mailing.jinja"
|
||||
current_tab = "mailing"
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs["club_id"] = self.object.id
|
||||
kwargs["user_id"] = self.request.user.id
|
||||
kwargs["mailings"] = self.object.mailings.all()
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
mailings = list(self.object.mailings.all())
|
||||
kwargs["club"] = self.object
|
||||
kwargs["user"] = self.request.user
|
||||
kwargs["mailings"] = mailings
|
||||
kwargs["mailings_moderated"] = [m for m in mailings if m.is_moderated]
|
||||
kwargs["mailings_not_moderated"] = [m for m in mailings if not m.is_moderated]
|
||||
kwargs["form_actions"] = {
|
||||
"NEW_MALING": self.form_class.ACTION_NEW_MAILING,
|
||||
"NEW_SUBSCRIPTION": self.form_class.ACTION_NEW_SUBSCRIPTION,
|
||||
"REMOVE_SUBSCRIPTION": self.form_class.ACTION_REMOVE_SUBSCRIPTION,
|
||||
}
|
||||
return kwargs
|
||||
|
||||
def add_new_mailing(self, cleaned_data) -> ValidationError | None:
|
||||
"""Create a new mailing list from the form."""
|
||||
mailing = Mailing(
|
||||
club=self.object,
|
||||
email=cleaned_data["mailing_email"],
|
||||
moderator=self.request.user,
|
||||
is_moderated=False,
|
||||
)
|
||||
try:
|
||||
mailing.clean()
|
||||
except ValidationError as validation_error:
|
||||
return validation_error
|
||||
mailing.save()
|
||||
return None
|
||||
|
||||
def add_new_subscription(self, cleaned_data) -> ValidationError | None:
|
||||
"""Add mailing subscriptions for each user given and/or for the specified email in form."""
|
||||
users_to_save = []
|
||||
|
||||
for user in cleaned_data["subscription_users"]:
|
||||
sub = MailingSubscription(
|
||||
mailing=cleaned_data["subscription_mailing"], user=user
|
||||
)
|
||||
try:
|
||||
sub.clean()
|
||||
except ValidationError as validation_error:
|
||||
return validation_error
|
||||
|
||||
sub.save()
|
||||
users_to_save.append(sub)
|
||||
|
||||
if cleaned_data["subscription_email"]:
|
||||
sub = MailingSubscription(
|
||||
mailing=cleaned_data["subscription_mailing"],
|
||||
email=cleaned_data["subscription_email"],
|
||||
)
|
||||
|
||||
try:
|
||||
sub.clean()
|
||||
except ValidationError as validation_error:
|
||||
return validation_error
|
||||
sub.save()
|
||||
|
||||
# Save users after we are sure there is no error
|
||||
for user in users_to_save:
|
||||
user.save()
|
||||
|
||||
return None
|
||||
|
||||
def remove_subscription(self, cleaned_data):
|
||||
"""Remove specified users from a mailing list."""
|
||||
fields = [
|
||||
val for key, val in cleaned_data.items() if key.startswith("removal_")
|
||||
]
|
||||
for field in fields:
|
||||
for sub in field:
|
||||
sub.delete()
|
||||
|
||||
def form_valid(self, form):
|
||||
resp = super().form_valid(form)
|
||||
|
||||
cleaned_data = form.clean()
|
||||
error = None
|
||||
|
||||
if cleaned_data["action"] == self.form_class.ACTION_NEW_MAILING:
|
||||
error = self.add_new_mailing(cleaned_data)
|
||||
|
||||
if cleaned_data["action"] == self.form_class.ACTION_NEW_SUBSCRIPTION:
|
||||
error = self.add_new_subscription(cleaned_data)
|
||||
|
||||
if cleaned_data["action"] == self.form_class.ACTION_REMOVE_SUBSCRIPTION:
|
||||
self.remove_subscription(cleaned_data)
|
||||
|
||||
if error:
|
||||
form.add_error(NON_FIELD_ERRORS, error)
|
||||
return self.form_invalid(form)
|
||||
|
||||
return resp
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return reverse("club:mailing", kwargs={"club_id": self.object.id})
|
||||
|
||||
|
||||
class MailingDeleteView(CanEditMixin, DeleteView):
|
||||
model = Mailing
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
pk_url_kwarg = "mailing_id"
|
||||
redirect_page = None
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.club_id = self.get_object().club.id
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
if self.redirect_page:
|
||||
return reverse_lazy(self.redirect_page)
|
||||
else:
|
||||
return reverse_lazy("club:mailing", kwargs={"club_id": self.club_id})
|
||||
|
||||
|
||||
class MailingSubscriptionDeleteView(CanEditMixin, DeleteView):
|
||||
model = MailingSubscription
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
pk_url_kwarg = "mailing_subscription_id"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.club_id = self.get_object().mailing.club.id
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return reverse_lazy("club:mailing", kwargs={"club_id": self.club_id})
|
||||
|
||||
|
||||
class MailingAutoGenerationView(View):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.mailing = get_object_or_404(Mailing, pk=kwargs["mailing_id"])
|
||||
if not request.user.can_edit(self.mailing):
|
||||
raise PermissionDenied
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
club = self.mailing.club
|
||||
self.mailing.subscriptions.all().delete()
|
||||
members = club.members.ongoing().filter(role__is_board=True)
|
||||
for member in members.all():
|
||||
MailingSubscription(user=member.user, mailing=self.mailing).save()
|
||||
return redirect("club:mailing", club_id=club.id)
|
||||
|
||||
|
||||
class PosterListView(
|
||||
PermissionOrClubBoardRequiredMixin, ClubTabsMixin, PosterListBaseView
|
||||
):
|
||||
|
||||
+1
-4
@@ -259,10 +259,7 @@ class Weekmail(models.Model):
|
||||
return f"Weekmail {self.id} (sent: {self.sent}) - {self.title}"
|
||||
|
||||
def send(self):
|
||||
"""Send the weekmail to all users with the receive weekmail option opt-in.
|
||||
|
||||
Also send the weekmail to the mailing list in settings.SITH_COM_EMAIL.
|
||||
"""
|
||||
"""Send the weekmail to all users with the receive weekmail option opt-in."""
|
||||
dest = [
|
||||
i[0]
|
||||
for i in Preferences.objects.filter(receive_weekmail=True).values_list(
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Mailing lists administration{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% macro display_mailings(list) %}
|
||||
<table>
|
||||
<tr>
|
||||
<th>{% trans %}Email{% endtrans %}</th>
|
||||
<th>{% trans %}Club{%endtrans%}</th>
|
||||
<th>{% trans %}Actions{% endtrans %}</th>
|
||||
</tr>
|
||||
{% for mailing in list %}
|
||||
<tr>
|
||||
<td>{{ mailing.email_full }}</td>
|
||||
<td><a href="{{ url('club:mailing', club_id=mailing.club.id) }}">{{ mailing.club }}</a></td>
|
||||
<td>
|
||||
<a href="{{ url('com:mailing_delete', mailing_id=mailing.id) }}">{% trans %}Delete{% endtrans %}</a> - {% if not mailing.is_moderated %}<a href="{{ url('com:mailing_moderate', mailing_id=mailing.id) }}">{% trans %}Moderate{% endtrans %}</a>{% else %}{% trans user=mailing.moderator %}Moderated by {{ user }}{% endtrans %}{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% trans %}This page lists all mailing lists{% endtrans %}</h1>
|
||||
|
||||
{% if has_unmoderated %}
|
||||
<h2>{% trans %}Not moderated mailing lists{% endtrans %}</h2>
|
||||
{{ display_mailings(unmoderated) }}
|
||||
{% endif %}
|
||||
|
||||
<h2>{% trans %}Moderated mailing lists{% endtrans %}</h2>
|
||||
{% if has_moderated %}
|
||||
{{ display_mailings(moderated) }}
|
||||
{% else %}
|
||||
<p>{% trans %}No mailing list existing{% endtrans %}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
+15
-49
@@ -31,8 +31,9 @@ from pytest_django.asserts import assertNumQueries, assertRedirects
|
||||
|
||||
from club.models import Club, ClubRole, Membership
|
||||
from com.models import News, NewsDate, Poster, Sith, Weekmail, WeekmailArticle
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.baker_recipes import old_subscriber_user, subscriber_user
|
||||
from core.models import AnonymousUser, Group, User
|
||||
from core.templatetags.renderer import markdown
|
||||
from core.utils import RED_PIXEL_PNG
|
||||
|
||||
|
||||
@@ -42,68 +43,32 @@ def user_community():
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize(
|
||||
"url",
|
||||
[
|
||||
reverse("com:alert_edit"),
|
||||
reverse("com:info_edit"),
|
||||
],
|
||||
)
|
||||
def test_com_page_is_working(client, url, user_community):
|
||||
def test_com_page_is_working(client, user_community):
|
||||
client.force_login(user_community)
|
||||
response = client.get(url)
|
||||
response = client.get(reverse("com:banner_edit"))
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
class TestCom(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.skia = User.objects.get(username="skia")
|
||||
cls.com_group = Group.objects.get(id=settings.SITH_GROUP_COM_ADMIN_ID)
|
||||
cls.skia.groups.set([cls.com_group])
|
||||
cls.com_admin = subscriber_user.make(groups=[cls.com_group])
|
||||
|
||||
def setUp(self):
|
||||
self.client.force_login(self.skia)
|
||||
|
||||
def test_alert_msg(self):
|
||||
def test_banner_messages(self):
|
||||
self.client.force_login(self.com_admin)
|
||||
alert_msg = "### ALERTE!\n\n**Caaaataaaapuuuulte!!!!**\n"
|
||||
info_msg = "### INFO:\n\n**Caaaataaaapuuuulte!!!!**\n"
|
||||
self.client.post(
|
||||
reverse("com:alert_edit"),
|
||||
{
|
||||
"alert_msg": """
|
||||
### ALERTE!
|
||||
|
||||
**Caaaataaaapuuuulte!!!!**
|
||||
"""
|
||||
},
|
||||
reverse("com:banner_edit"), {"alert_msg": alert_msg, "info_msg": info_msg}
|
||||
)
|
||||
r = self.client.get(reverse("core:index"))
|
||||
assert r.status_code == 200
|
||||
self.assertInHTML(
|
||||
"""<div id="alert_box"><div class="markdown"><h3>ALERTE!</h3>
|
||||
<p><strong>Caaaataaaapuuuulte!!!!</strong></p>""",
|
||||
r.content.decode(),
|
||||
)
|
||||
|
||||
def test_info_msg(self):
|
||||
self.client.post(
|
||||
reverse("com:info_edit"),
|
||||
{
|
||||
"info_msg": """
|
||||
### INFO: **Caaaataaaapuuuulte!!!!**
|
||||
"""
|
||||
},
|
||||
)
|
||||
r = self.client.get(reverse("core:index"))
|
||||
|
||||
assert r.status_code == 200
|
||||
self.assertInHTML(
|
||||
"""<div id="info_box"><div class="markdown">
|
||||
<h3>INFO: <strong>Caaaataaaapuuuulte!!!!</strong></h3>""",
|
||||
r.content.decode(),
|
||||
)
|
||||
self.assertInHTML(f'<div id="alert_box">{markdown(alert_msg)}</div>', r.text)
|
||||
self.assertInHTML(f'<div id="info_box">{markdown(info_msg)}</div>', r.text)
|
||||
|
||||
def test_birthday_non_subscribed_user(self):
|
||||
self.client.force_login(User.objects.get(username="guy"))
|
||||
self.client.force_login(baker.make(User))
|
||||
response = self.client.get(reverse("core:index"))
|
||||
self.assertContains(
|
||||
response,
|
||||
@@ -111,6 +76,7 @@ class TestCom(TestCase):
|
||||
)
|
||||
|
||||
def test_birthday_subscibed_user(self):
|
||||
self.client.force_login(subscriber_user.make())
|
||||
response = self.client.get(reverse("core:index"))
|
||||
|
||||
self.assertNotContains(
|
||||
@@ -119,7 +85,7 @@ class TestCom(TestCase):
|
||||
)
|
||||
|
||||
def test_birthday_old_subscibed_user(self):
|
||||
self.client.force_login(User.objects.get(username="old_subscriber"))
|
||||
self.client.force_login(old_subscriber_user.make())
|
||||
response = self.client.get(reverse("core:index"))
|
||||
|
||||
self.assertNotContains(
|
||||
|
||||
+2
-18
@@ -15,12 +15,8 @@
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from club.views import MailingDeleteView
|
||||
from com.views import (
|
||||
AlertMsgEditView,
|
||||
InfoMsgEditView,
|
||||
MailingListAdminView,
|
||||
MailingModerateView,
|
||||
BannerMessagesEditView,
|
||||
NewsAdminListView,
|
||||
NewsCreateView,
|
||||
NewsDeleteView,
|
||||
@@ -48,8 +44,7 @@ from com.views import (
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path("sith/edit/alert/", AlertMsgEditView.as_view(), name="alert_edit"),
|
||||
path("sith/edit/info/", InfoMsgEditView.as_view(), name="info_edit"),
|
||||
path("sith/edit/banner/", BannerMessagesEditView.as_view(), name="banner_edit"),
|
||||
path(
|
||||
"sith/edit/weekmail_destinations/",
|
||||
WeekmailDestinationEditView.as_view(),
|
||||
@@ -82,17 +77,6 @@ urlpatterns = [
|
||||
"news/<int:news_id>/moderate/", NewsModerateView.as_view(), name="news_moderate"
|
||||
),
|
||||
path("news/<int:news_id>/", NewsDetailView.as_view(), name="news_detail"),
|
||||
path("mailings/", MailingListAdminView.as_view(), name="mailing_admin"),
|
||||
path(
|
||||
"mailings/<int:mailing_id>/moderate/",
|
||||
MailingModerateView.as_view(),
|
||||
name="mailing_moderate",
|
||||
),
|
||||
path(
|
||||
"mailings/<int:mailing_id>/delete/",
|
||||
MailingDeleteView.as_view(redirect_page="com:mailing_admin"),
|
||||
name="mailing_delete",
|
||||
),
|
||||
path("poster/", PosterListView.as_view(), name="poster_list"),
|
||||
path("poster/create/", PosterCreateView.as_view(), name="poster_create"),
|
||||
path("poster/<int:poster_id>/edit/", PosterEditView.as_view(), name="poster_edit"),
|
||||
|
||||
+12
-61
@@ -30,11 +30,9 @@ from urllib.parse import urlparse
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import (
|
||||
PermissionRequiredMixin,
|
||||
)
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.contrib.syndication.views import Feed
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import Exists, Max, OuterRef, Value
|
||||
from django.forms.models import modelform_factory
|
||||
from django.http import HttpResponseRedirect
|
||||
@@ -46,7 +44,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import DetailView, ListView, TemplateView, View
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
|
||||
from club.models import Club, Mailing, Membership
|
||||
from club.models import Club, Membership
|
||||
from com.forms import NewsDateForm, NewsForm, PosterForm
|
||||
from com.ics_calendar import IcsCalendar
|
||||
from com.models import News, NewsDate, Poster, Screen, Sith, Weekmail, WeekmailArticle
|
||||
@@ -77,19 +75,9 @@ class ComTabsMixin(TabedViewMixin):
|
||||
"name": _("Weekmail destinations"),
|
||||
},
|
||||
{
|
||||
"url": reverse("com:info_edit"),
|
||||
"slug": "info",
|
||||
"name": _("Info message"),
|
||||
},
|
||||
{
|
||||
"url": reverse("com:alert_edit"),
|
||||
"slug": "alert",
|
||||
"name": _("Alert message"),
|
||||
},
|
||||
{
|
||||
"url": reverse("com:mailing_admin"),
|
||||
"slug": "mailings",
|
||||
"name": _("Mailing lists administration"),
|
||||
"url": reverse("com:banner_edit"),
|
||||
"slug": "banner",
|
||||
"name": _("Banner messages"),
|
||||
},
|
||||
{
|
||||
"url": reverse("com:poster_list"),
|
||||
@@ -112,20 +100,14 @@ class ComEditView(ComTabsMixin, CanEditPropMixin, UpdateView):
|
||||
return Sith.objects.first()
|
||||
|
||||
|
||||
class AlertMsgEditView(ComEditView):
|
||||
class BannerMessagesEditView(ComEditView):
|
||||
form_class = modelform_factory(
|
||||
Sith, fields=["alert_msg"], widgets={"alert_msg": MarkdownInput}
|
||||
Sith,
|
||||
fields=["alert_msg", "info_msg"],
|
||||
widgets={"alert_msg": MarkdownInput, "info_msg": MarkdownInput},
|
||||
)
|
||||
current_tab = "alert"
|
||||
success_url = reverse_lazy("com:alert_edit")
|
||||
|
||||
|
||||
class InfoMsgEditView(ComEditView):
|
||||
form_class = modelform_factory(
|
||||
Sith, fields=["info_msg"], widgets={"info_msg": MarkdownInput}
|
||||
)
|
||||
current_tab = "info"
|
||||
success_url = reverse_lazy("com:info_edit")
|
||||
current_tab = "banner"
|
||||
success_url = reverse_lazy("com:banner_edit")
|
||||
|
||||
|
||||
class WeekmailDestinationEditView(ComEditView):
|
||||
@@ -533,37 +515,6 @@ class WeekmailArticleDeleteView(CanEditPropMixin, DeleteView):
|
||||
pk_url_kwarg = "article_id"
|
||||
|
||||
|
||||
class MailingListAdminView(ComTabsMixin, ListView):
|
||||
template_name = "com/mailing_admin.jinja"
|
||||
model = Mailing
|
||||
current_tab = "mailings"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not (request.user.is_com_admin or request.user.is_root):
|
||||
raise PermissionDenied
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
kwargs["moderated"] = self.get_queryset().filter(is_moderated=True).all()
|
||||
kwargs["unmoderated"] = self.get_queryset().filter(is_moderated=False).all()
|
||||
kwargs["has_moderated"] = len(kwargs["moderated"]) > 0
|
||||
kwargs["has_unmoderated"] = len(kwargs["unmoderated"]) > 0
|
||||
return kwargs
|
||||
|
||||
|
||||
class MailingModerateView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
mailing = get_object_or_404(Mailing, pk=kwargs["mailing_id"])
|
||||
if mailing.can_moderate(request.user):
|
||||
mailing.is_moderated = True
|
||||
mailing.moderator = request.user
|
||||
mailing.save()
|
||||
return redirect("com:mailing_admin")
|
||||
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
class PosterListBaseView(ListView):
|
||||
"""List communication posters."""
|
||||
|
||||
|
||||
-16
@@ -1,18 +1,15 @@
|
||||
from typing import Annotated, Literal
|
||||
|
||||
from annotated_types import Ge, Le, MinLen
|
||||
from django.conf import settings
|
||||
from django.db.models import F
|
||||
from ninja import File, Query
|
||||
from ninja.security import SessionAuth
|
||||
from ninja_extra import ControllerBase, api_controller, paginate, route
|
||||
from ninja_extra.exceptions import PermissionDenied
|
||||
from ninja_extra.pagination import PageNumberPaginationExtra
|
||||
from ninja_extra.schemas import PaginatedResponseSchema
|
||||
|
||||
from api.auth import ApiKeyAuth
|
||||
from api.permissions import CanAccessLookup, CanView, HasPerm
|
||||
from club.models import Mailing
|
||||
from core.models import Group, QuickUploadImage, SithFile, User
|
||||
from core.schemas import (
|
||||
FamilyGodfatherSchema,
|
||||
@@ -48,19 +45,6 @@ class UploadController(ControllerBase):
|
||||
return image
|
||||
|
||||
|
||||
@api_controller("/mailings")
|
||||
class MailingListController(ControllerBase):
|
||||
@route.get("", response=str)
|
||||
def fetch_mailing_lists(self, key: str):
|
||||
if key != settings.SITH_MAILING_FETCH_KEY:
|
||||
raise PermissionDenied
|
||||
mailings = Mailing.objects.filter(
|
||||
is_moderated=True, club__is_active=True
|
||||
).prefetch_related("subscriptions")
|
||||
data = "\n".join(m.fetch_format() for m in mailings)
|
||||
return data
|
||||
|
||||
|
||||
@api_controller("/user")
|
||||
class UserController(ControllerBase):
|
||||
@route.get("", response=list[UserProfileSchema])
|
||||
|
||||
@@ -252,7 +252,6 @@ class Command(BaseCommand):
|
||||
date_of_birth="1942-06-12",
|
||||
password="plop",
|
||||
)
|
||||
User.objects.all().update(cgu_approved_at=now())
|
||||
User.groups.through.objects.bulk_create(
|
||||
[
|
||||
User.groups.through(group=groups.counter_admin, user=counter),
|
||||
@@ -277,6 +276,10 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
self._create_pages(groups)
|
||||
# the "approve cgu" button is shown if the cgu were approved
|
||||
# before the last version of the CGU page.
|
||||
# Hence, it's better for this update to be after page creation.
|
||||
User.objects.all().update(cgu_approved_at=now())
|
||||
|
||||
self._create_subscription(root)
|
||||
self._create_subscription(skia)
|
||||
@@ -779,28 +782,47 @@ class Command(BaseCommand):
|
||||
name="Carte AE", address="Jamais imprimée", parent=ae
|
||||
)
|
||||
roles = []
|
||||
presidency_roles = ["Président⸱e", "Vice-Président⸱e"]
|
||||
presidency_roles = [
|
||||
("Président⸱e", "President"),
|
||||
("Vice-Président⸱e", "Vice-president"),
|
||||
]
|
||||
board_roles = [
|
||||
"Trésorier⸱e",
|
||||
"Secrétaire",
|
||||
"Respo Info",
|
||||
"Respo Com",
|
||||
"Membre du bureau",
|
||||
("Trésorier⸱e", "Treasurer"),
|
||||
("Secrétaire", "Secretary"),
|
||||
("Respo Info", "IT manager"),
|
||||
("Respo Com", "Communication manager"),
|
||||
("Membre du bureau", "Board member"),
|
||||
]
|
||||
simple_roles = [
|
||||
("Membre actif⸱ve", "Active member"),
|
||||
("Curieux⸱euse", "Curious"),
|
||||
]
|
||||
simple_roles = ["Membre actif⸱ve", "Curieux⸱euse"]
|
||||
for club in ae, pdf, troll, refound:
|
||||
for i, role in enumerate(presidency_roles):
|
||||
for i, (role_fr, role_en) in enumerate(presidency_roles):
|
||||
roles.append(
|
||||
ClubRole(
|
||||
club=club, order=i, name=role, is_presidency=True, is_board=True
|
||||
club=club,
|
||||
order=i,
|
||||
name=role_fr,
|
||||
name_en=role_en,
|
||||
is_presidency=True,
|
||||
is_board=True,
|
||||
)
|
||||
)
|
||||
for i, role in enumerate(board_roles, start=len(presidency_roles)):
|
||||
roles.append(ClubRole(club=club, order=i, name=role, is_board=True))
|
||||
for i, role in enumerate(
|
||||
for i, (role_fr, role_en) in enumerate(
|
||||
board_roles, start=len(presidency_roles)
|
||||
):
|
||||
roles.append(
|
||||
ClubRole(
|
||||
club=club, order=i, name=role_fr, name_en=role_en, is_board=True
|
||||
)
|
||||
)
|
||||
for i, (role_fr, role_en) in enumerate(
|
||||
simple_roles, start=len(presidency_roles) + len(board_roles)
|
||||
):
|
||||
roles.append(ClubRole(club=club, order=i, name=role))
|
||||
roles.append(
|
||||
ClubRole(club=club, order=i, name=role_fr, name_en=role_en)
|
||||
)
|
||||
ClubRole.objects.bulk_create(roles)
|
||||
insta, fb, discord, _ = LinkType.objects.bulk_create(
|
||||
[
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 5.2.18 on 2026-11-15 11:46
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
import antispam.models.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("core", "0052_preferences_show_my_timetable")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="email",
|
||||
field=antispam.models.fields.AntiSpamEmailField(
|
||||
max_length=254, unique=True, verbose_name="email address"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="second_email",
|
||||
field=antispam.models.fields.AntiSpamEmailField(
|
||||
blank=True,
|
||||
max_length=254,
|
||||
null=True,
|
||||
verbose_name="second email address",
|
||||
),
|
||||
),
|
||||
]
|
||||
+11
-2
@@ -55,6 +55,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from phonenumber_field.modelfields import PhoneNumberField
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
from antispam.models import AntiSpamEmailField
|
||||
from core.utils import get_last_promo
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -158,7 +159,7 @@ class User(AbstractUser):
|
||||
|
||||
first_name = models.CharField(_("first name"), max_length=64)
|
||||
last_name = models.CharField(_("last name"), max_length=64)
|
||||
email = models.EmailField(_("email address"), unique=True)
|
||||
email = AntiSpamEmailField(_("email address"), unique=True)
|
||||
date_of_birth = models.DateField(_("date of birth"), blank=True, null=True)
|
||||
nick_name = models.CharField(_("nick name"), max_length=64, null=True, blank=True)
|
||||
last_update = models.DateTimeField(_("last update"), auto_now=True)
|
||||
@@ -267,7 +268,7 @@ class User(AbstractUser):
|
||||
forum_signature = models.TextField(
|
||||
_("forum signature"), max_length=256, blank=True, default=""
|
||||
)
|
||||
second_email = models.EmailField(_("second email address"), null=True, blank=True)
|
||||
second_email = AntiSpamEmailField(_("second email address"), null=True, blank=True)
|
||||
phone = PhoneNumberField(_("phone"), null=True, blank=True)
|
||||
parent_phone = PhoneNumberField(_("parent phone"), null=True, blank=True)
|
||||
address = models.CharField(_("address"), max_length=128, blank=True, default="")
|
||||
@@ -768,6 +769,14 @@ class UserBan(models.Model):
|
||||
def __str__(self):
|
||||
return f"Ban of user {self.user.id}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.ban_group_id in [
|
||||
settings.SITH_GROUP_BANNED_COUNTER_ID,
|
||||
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
]:
|
||||
self.user.counters.clear()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class GlobalPermissionRights(models.Model):
|
||||
"""Little hack to have permissions not linked to a specific db table."""
|
||||
|
||||
@@ -240,13 +240,6 @@ $background-color-hovered: #283747;
|
||||
|
||||
>.links {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 15px;
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
a {
|
||||
color: $text-color;
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
</div>
|
||||
<div class="links">
|
||||
<a href="{{ url('core:user_tools') }}">{% trans %}Tools{% endtrans %}</a>
|
||||
|
||||
<form id="logout-form" method="post" action="{{ url("core:logout") }}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="link-like link-red">
|
||||
|
||||
@@ -79,15 +79,5 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if
|
||||
profile.mailing_subscriptions.exists()
|
||||
and (profile.id == user.id or user.is_root or user.is_com_admin)
|
||||
%}
|
||||
<h4>{% trans %}Subscribed mailing lists{% endtrans %}</h4>
|
||||
{% for sub in profile.mailing_subscriptions.all() %}
|
||||
<p>{{ sub.mailing.email }} <a href="{{ url('club:mailing_subscription_delete', mailing_subscription_id=sub.id) }}">{% trans %}Unsubscribe{% endtrans %}</a></p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<h3>{% trans %}User Tools{% endtrans %}</h3>
|
||||
|
||||
<div class="container">
|
||||
{% if user.has_perm("subscription.view_userban") or user.is_root or user.is_board_member %}
|
||||
{% if user.has_perm("subscription.view_userban") or user.has_perm("club.add_club") or user.is_root or user.is_board_member %}
|
||||
<div>
|
||||
<h4>{% trans %}Sith management{% endtrans %}</h4>
|
||||
<ul>
|
||||
@@ -30,7 +30,7 @@
|
||||
{% if user.has_perm("core.view_userban") %}
|
||||
<li><a href="{{ url("rootplace:ban_list") }}">{% trans %}Bans{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
{% if user.is_board_member or user.is_root %}
|
||||
{% if user.has_perm("club.add_club") %}
|
||||
<li><a href="{{ url('club:club_new') }}">{% trans %}New club{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
@@ -41,8 +41,7 @@
|
||||
{% for b in settings.SITH_COUNTER_BARS if user.is_in_group(name=b[1] + " admin") %}
|
||||
{% set is_admin_on_a_counter = true %}
|
||||
{% endfor %}
|
||||
|
||||
{% if is_admin_on_a_counter or user.is_root or user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID) %}
|
||||
{% if is_admin_on_a_counter or user.has_perm("counter.view_product") or user.has_perm("counter.view_eticket") %}
|
||||
<div>
|
||||
<h4>{% trans %}Counters{% endtrans %}</h4>
|
||||
<ul>
|
||||
@@ -52,31 +51,15 @@
|
||||
{% trans %}General counters management{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if user.has_perm("counter.view_product") %}
|
||||
<li>
|
||||
<a href="{{ url('counter:product_list') }}">
|
||||
{% trans %}Products management{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url('counter:product_type_list') }}">
|
||||
{% trans %}Product types management{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url("counter:returnable_list") }}">
|
||||
{% trans %}Returnable products management{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url('counter:cash_summary_list') }}">
|
||||
{% trans %}Cash register summaries{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url('counter:invoices_call') }}">
|
||||
{% trans %}Invoices call{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if user.has_perm("counter.view_eticket") %}
|
||||
<li>
|
||||
<a href="{{ url('counter:eticket_list') }}">
|
||||
{% trans %}Etickets{% endtrans %}
|
||||
@@ -109,10 +92,17 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_root or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
|
||||
{% if user.has_perms(["counter.view_invoicecall", "counter.change_invoicecall"]) or user.is_root or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
|
||||
<div>
|
||||
<h4>{% trans %}Accounting{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.has_perms(["counter.view_invoicecall", "counter.change_invoicecall"]) %}
|
||||
<li>
|
||||
<a href="{{ url('counter:invoices_call') }}">
|
||||
{% trans %}Invoices call{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if user.is_root or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %}
|
||||
<li><a href="{{ url("counter:account_refound") }}">{% trans %}Refound Account{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
@@ -120,24 +110,19 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_root or user.is_com_admin or user.is_in_group(pk=settings.SITH_GROUP_SAS_ADMIN_ID) %}
|
||||
{% if user.is_root or user.is_com_admin or user.has_perm("sas.moderate_sasfile") %}
|
||||
<div>
|
||||
<h4>{% trans %}Communication{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.is_com_admin or user.is_root %}
|
||||
<li><a href="{{ url('com:weekmail_article') }}">{% trans %}Create weekmail article{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:weekmail') }}">{% trans %}Weekmail{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:weekmail_destinations') }}">{% trans %}Weekmail destinations{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:news_new') }}">{% trans %}Create news{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:news_admin_list') }}">{% trans %}Moderate news{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:alert_edit') }}">{% trans %}Edit alert message{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:info_edit') }}">{% trans %}Edit information message{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('core:file_moderation') }}">{% trans %}Moderate files{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:mailing_admin') }}">{% trans %}Mailing lists administration{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:banner_edit') }}">{% trans %}Edit banner messages{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:poster_list') }}">{% trans %}Posters{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:screen_list') }}">{% trans %}Screens{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_SAS_ADMIN_ID) %}
|
||||
{% if user.has_perm("sas.moderate_sasfile") %}
|
||||
<li><a href="{{ url('sas:moderation') }}">{% trans %}Moderate pictures{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
@@ -173,12 +158,17 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if user.memberships.filter(end_date=None).all().count() > 0 %}
|
||||
{% set memberships = user.memberships.ongoing().select_related("club")|list %}
|
||||
{% if memberships|length > 0 %}
|
||||
<div>
|
||||
<h4>{% trans %}Club tools{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% for m in user.memberships.filter(end_date=None).all() %}
|
||||
<li><a href="{{ url('club:tools', club_id=m.club.id) }}">{{ m.club }}</a></li>
|
||||
{% for m in memberships %}
|
||||
{% if m.is_board %}
|
||||
<li><a href="{{ url('club:tools', club_id=m.club_id) }}">{{ m.club }}</a></li>
|
||||
{% else %}
|
||||
<li><a href="{{ url('club:club_view', club_id=m.club_id) }}">{{ m.club }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
@@ -211,7 +201,7 @@
|
||||
<ul>
|
||||
<li><a href="{{ url('election:list') }}">{% trans %}See available elections{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('election:list_archived') }}">{% trans %}See archived elections{% endtrans %}</a></li>
|
||||
{%- if user.is_subscribed -%}
|
||||
{%- if user.has_perm("election.add_election") -%}
|
||||
<li><a href="{{ url('election:create') }}">{% trans %}Create a new election{% endtrans %}</a></li>
|
||||
{%- endif -%}
|
||||
</ul>
|
||||
|
||||
+18
-5
@@ -35,7 +35,7 @@ from pytest_django.asserts import assertInHTML, assertRedirects
|
||||
|
||||
from antispam.models import ToxicDomain
|
||||
from club.models import Club
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.baker_recipes import board_user, subscriber_user
|
||||
from core.models import AnonymousUser, Group, Page, User, validate_promo
|
||||
from core.utils import get_last_promo, get_semester_code, get_start_of_semester
|
||||
from core.views import AllowFragment
|
||||
@@ -398,11 +398,24 @@ class TestUserTools:
|
||||
response, expected_url=reverse("core:login", query={"next": url})
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("username", ["guy", "root", "skia", "comunity"])
|
||||
def test_page_is_working(self, client, username):
|
||||
@pytest.mark.parametrize(
|
||||
"user_factory",
|
||||
[
|
||||
lambda: baker.make(User),
|
||||
lambda: baker.make(User, is_superuser=True),
|
||||
board_user.make,
|
||||
lambda: baker.make(
|
||||
User, groups=[Group.objects.get(id=settings.SITH_GROUP_COM_ADMIN_ID)]
|
||||
),
|
||||
lambda: baker.make(
|
||||
User,
|
||||
groups=[Group.objects.get(id=settings.SITH_GROUP_COUNTER_ADMIN_ID)],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_page_is_working(self, client, user_factory):
|
||||
"""All existing users should be able to see the test page."""
|
||||
# Test for simple user
|
||||
client.force_login(User.objects.get(username=username))
|
||||
client.force_login(user_factory())
|
||||
response = client.get(reverse("core:user_tools"))
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@@ -321,6 +321,7 @@ class UserTabTestView(UserTabsMixin, DetailView): ...
|
||||
"edit",
|
||||
"prefs",
|
||||
"clubs",
|
||||
"timetable",
|
||||
"stats",
|
||||
"account",
|
||||
],
|
||||
@@ -337,6 +338,7 @@ class UserTabTestView(UserTabsMixin, DetailView): ...
|
||||
"edit",
|
||||
"prefs",
|
||||
"clubs",
|
||||
"timetable",
|
||||
"groups",
|
||||
],
|
||||
),
|
||||
@@ -370,6 +372,7 @@ def test_displayed_user_self_tabs(user_factory, expected_tabs: list[str]):
|
||||
"edit",
|
||||
"prefs",
|
||||
"clubs",
|
||||
"timetable",
|
||||
"groups",
|
||||
"stats",
|
||||
"account",
|
||||
@@ -472,6 +475,36 @@ def test_user_preferences(client: Client):
|
||||
assert user.preferences.notify_on_click is True
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("can_edit", [True, False])
|
||||
def test_user_visibility(client: Client, monkeypatch, can_edit):
|
||||
# The view is a CanView, so just patch User.can_be_edited_by for the test
|
||||
monkeypatch.setattr("core.models.User.can_be_edited_by", lambda *args: can_edit)
|
||||
client.force_login(subscriber_user.make())
|
||||
|
||||
user, other_user = subscriber_user.make(_quantity=2)
|
||||
url = reverse("core:user_visibility_fragment", kwargs={"user_id": user.id})
|
||||
response = client.get(url)
|
||||
assert response.status_code == 200 if can_edit else 403
|
||||
response = client.post(
|
||||
url,
|
||||
{
|
||||
"show_my_stats": False,
|
||||
"is_viewable": False,
|
||||
"whitelisted_users": [other_user.id],
|
||||
},
|
||||
)
|
||||
if not can_edit:
|
||||
assert response.status_code == 403
|
||||
return
|
||||
assertRedirects(response, url)
|
||||
user.refresh_from_db()
|
||||
user.preferences.refresh_from_db()
|
||||
assert user.is_viewable is False
|
||||
assert list(user.whitelisted_users.all()) == [other_user]
|
||||
assert user.preferences.show_my_stats is False
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_user_stats(client: Client):
|
||||
user = subscriber_user.make()
|
||||
|
||||
+1
-5
@@ -48,7 +48,6 @@ from django.utils.translation import gettext_lazy as _
|
||||
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||
from PIL import Image
|
||||
|
||||
from antispam.forms import AntiSpamEmailField
|
||||
from core.models import Gift, Group, Page, PageRev, Preferences, SithFile, User
|
||||
from core.utils import resize_image
|
||||
from core.views.widgets.ajax_select import (
|
||||
@@ -185,10 +184,7 @@ class RegisteringForm(UserCreationForm):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ("first_name", "last_name", "email", "cgu_approved_at")
|
||||
field_classes = {
|
||||
"email": AntiSpamEmailField,
|
||||
"cgu_approved_at": CGUApprovalField,
|
||||
}
|
||||
field_classes = {"cgu_approved_at": CGUApprovalField}
|
||||
|
||||
|
||||
class CGUApprovalForm(forms.ModelForm):
|
||||
|
||||
@@ -94,8 +94,8 @@ class FragmentMixin(TemplateResponseMixin, AllowFragment, ContextMixin):
|
||||
return render(
|
||||
request,
|
||||
"app/template.jinja",
|
||||
context={"fragment": fragment(request)
|
||||
}
|
||||
context={"fragment": fragment(request)}
|
||||
)
|
||||
|
||||
# in urls.py
|
||||
urlpatterns = [
|
||||
|
||||
+24
-1
@@ -275,6 +275,27 @@ class UserTabsMixin(TabedViewMixin):
|
||||
"name": _("Clubs"),
|
||||
}
|
||||
)
|
||||
if user == self.request.user and not user.timetables.exists():
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse("timetable:generator"),
|
||||
"slug": "timetable",
|
||||
"name": _("Timetable"),
|
||||
}
|
||||
)
|
||||
elif user == self.request.user or (
|
||||
self.request.user.has_perm("timetable.view_timetable")
|
||||
and user.preferences.show_my_timetable
|
||||
):
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse(
|
||||
"core:user_timetable", kwargs={"user_id": user.id}
|
||||
),
|
||||
"slug": "timetable",
|
||||
"name": _("Timetable"),
|
||||
}
|
||||
)
|
||||
if self.request.user.is_owner(user):
|
||||
tab_list.append(
|
||||
{
|
||||
@@ -502,7 +523,9 @@ class UserClubView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
current_tab = "clubs"
|
||||
|
||||
|
||||
class UserVisibilityFormFragment(FragmentMixin, SuccessMessageMixin, UpdateView):
|
||||
class UserVisibilityFormFragment(
|
||||
FragmentMixin, SuccessMessageMixin, CanEditMixin, UpdateView
|
||||
):
|
||||
model = User
|
||||
form_class = UserVisibilityForm
|
||||
template_name = "core/fragment/user_visibility.jinja"
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ from ninja_extra.pagination import PageNumberPaginationExtra
|
||||
from ninja_extra.schemas import PaginatedResponseSchema
|
||||
|
||||
from api.auth import ApiKeyAuth
|
||||
from api.permissions import CanAccessLookup, CanView, IsInGroup, IsRoot
|
||||
from api.permissions import CanAccessLookup, CanView, HasPerm, IsInGroup, IsRoot
|
||||
from counter.models import Counter, Product, ProductType
|
||||
from counter.schemas import (
|
||||
CounterFilterSchema,
|
||||
@@ -93,7 +93,7 @@ class ProductController(ControllerBase):
|
||||
@route.get(
|
||||
"/search/detailed",
|
||||
response=PaginatedResponseSchema[ProductSchema],
|
||||
permissions=[IsCounterAdmin],
|
||||
permissions=[HasPerm("counter.view_product")],
|
||||
url_name="search_products_detailed",
|
||||
)
|
||||
@paginate(PageNumberPaginationExtra, page_size=50)
|
||||
|
||||
+44
-5
@@ -3,7 +3,7 @@ import math
|
||||
import uuid
|
||||
from collections import defaultdict
|
||||
from datetime import date, datetime, timezone
|
||||
from typing import TYPE_CHECKING, ClassVar
|
||||
from typing import TYPE_CHECKING, ClassVar, LiteralString
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from django import forms
|
||||
@@ -19,7 +19,7 @@ from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||
|
||||
from club.models import Club
|
||||
from club.widgets.ajax_select import AutoCompleteSelectClub
|
||||
from core.models import User, UserQuerySet
|
||||
from core.models import User, UserBan, UserQuerySet
|
||||
from core.views import LoginForm
|
||||
from core.views.forms import (
|
||||
FutureDateTimeField,
|
||||
@@ -130,8 +130,14 @@ class GetUserForm(forms.Form):
|
||||
elif cleaned_data["id"]:
|
||||
customer = Customer.objects.filter(user=cleaned_data["id"]).first()
|
||||
|
||||
if customer is None or not customer.can_buy:
|
||||
if customer is None:
|
||||
raise forms.ValidationError(_("User not found"))
|
||||
if not customer.can_buy:
|
||||
raise forms.ValidationError(_("This user cannot buy items on counters."))
|
||||
if customer.user.is_banned_counter:
|
||||
raise forms.ValidationError(
|
||||
_("This user is banned from AE places. Take him/her out if you can.")
|
||||
)
|
||||
cleaned_data["user_id"] = customer.user_id
|
||||
cleaned_data["user"] = customer.user
|
||||
return cleaned_data
|
||||
@@ -251,6 +257,41 @@ class CounterEditForm(forms.ModelForm):
|
||||
countersellers__is_regular=False
|
||||
).all()
|
||||
|
||||
def clean_sellers(self, field: LiteralString):
|
||||
sellers = self.cleaned_data[field]
|
||||
bans = [
|
||||
settings.SITH_GROUP_BANNED_COUNTER_ID,
|
||||
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
]
|
||||
invalid_sellers = sellers.annotate(
|
||||
is_banned=Exists(
|
||||
UserBan.objects.filter(user=OuterRef("pk"), ban_group__in=bans)
|
||||
)
|
||||
).filter(Q(is_banned=True) | Q(date_of_birth=None))
|
||||
for seller in invalid_sellers:
|
||||
if seller.is_banned:
|
||||
self.add_error(
|
||||
field,
|
||||
ValidationError(
|
||||
_("%(user)s is banned.") % {"user": seller.get_full_name()}
|
||||
),
|
||||
)
|
||||
if not seller.date_of_birth:
|
||||
self.add_error(
|
||||
field,
|
||||
ValidationError(
|
||||
_("%(user)s has not filled its birthdate.")
|
||||
% {"user": seller.get_full_name()}
|
||||
),
|
||||
)
|
||||
return sellers
|
||||
|
||||
def clean_sellers_regular(self):
|
||||
return self.clean_sellers("sellers_regular")
|
||||
|
||||
def clean_sellers_temporary(self):
|
||||
return self.clean_sellers("sellers_temporary")
|
||||
|
||||
def clean(self):
|
||||
regular: UserQuerySet = self.cleaned_data["sellers_regular"]
|
||||
temporary: UserQuerySet = self.cleaned_data["sellers_temporary"]
|
||||
@@ -466,8 +507,6 @@ class ProductForm(forms.ModelForm):
|
||||
self.fields["name"].widget.attrs["autofocus"] = "autofocus"
|
||||
if self.instance.id:
|
||||
self.fields["counters"].initial = self.instance.counters.all()
|
||||
if hasattr(self.instance, "formula"):
|
||||
self.formula_init(self.instance.formula)
|
||||
self.price_formset = ProductPriceFormSet(
|
||||
*args, instance=self.instance, prefix="price", **kwargs
|
||||
)
|
||||
|
||||
@@ -83,15 +83,17 @@
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
<div class="alert alert-yellow">
|
||||
<div class="alert-main">
|
||||
{%- trans trimmed -%}
|
||||
You can see product details.
|
||||
However, you cannot edit it, thus you won't be able
|
||||
to submit this form.
|
||||
{%- endtrans -%}
|
||||
{% if not user.has_perm("counter.change_product") %}
|
||||
<div class="alert alert-yellow">
|
||||
<div class="alert-main">
|
||||
{%- trans trimmed -%}
|
||||
You can see product details.
|
||||
However, you cannot edit it, thus you won't be able
|
||||
to submit this form.
|
||||
{%- endtrans -%}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if object %}
|
||||
<h2>{{ object }}</h2>
|
||||
<p><i>{% trans %}Creation date{% endtrans %} : {{ object.created_at|date }}</i></p>
|
||||
|
||||
@@ -21,11 +21,12 @@ import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import Permission, make_password
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.messages import DEFAULT_LEVELS, get_messages
|
||||
from django.shortcuts import resolve_url
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
from django.test import Client, RequestFactory, TestCase
|
||||
from django.urls import resolve, reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.timezone import localdate, now
|
||||
from freezegun import freeze_time
|
||||
@@ -47,6 +48,7 @@ from counter.models import (
|
||||
ReturnableProduct,
|
||||
Selling,
|
||||
)
|
||||
from counter.utils import is_logged_in_counter
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.http import HttpResponse
|
||||
@@ -65,8 +67,9 @@ class TestFullClickBase(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.customer = subscriber_user.make()
|
||||
cls.barmen = subscriber_user.make(password=make_password("plop"))
|
||||
cls.board_admin = board_user.make(password=make_password("plop"))
|
||||
password = make_password("plop")
|
||||
cls.barmen = subscriber_user.make(password=password)
|
||||
cls.board_admin = board_user.make(password=password)
|
||||
cls.club_admin = subscriber_user.make()
|
||||
cls.root = baker.make(User, is_superuser=True)
|
||||
cls.subscriber = subscriber_user.make()
|
||||
@@ -402,7 +405,7 @@ class TestCounterClick(TestFullClickBase):
|
||||
self.assertRedirects(res, self.counter.get_absolute_url())
|
||||
assert self.updated_amount(self.customer) == Decimal(8)
|
||||
|
||||
def test_click_alcool_unauthorized(self):
|
||||
def test_click_alcohol_unauthorized(self):
|
||||
self.login_in_bar()
|
||||
|
||||
for user in [self.underage_customer, self.banned_alcohol_customer]:
|
||||
@@ -420,6 +423,31 @@ class TestCounterClick(TestFullClickBase):
|
||||
|
||||
assert self.updated_amount(user) == Decimal(7)
|
||||
|
||||
def test_click_no_alcohol_if_minor_barman(self):
|
||||
"""Test that no age restricted product can be sold if the barman is minor."""
|
||||
set_age(self.barmen, 17)
|
||||
self.login_in_bar(self.barmen)
|
||||
res = self.client.get(
|
||||
reverse(
|
||||
"counter:click",
|
||||
kwargs={"counter_id": self.counter.id, "user_id": self.customer.id},
|
||||
)
|
||||
)
|
||||
assert res.status_code == 200
|
||||
messages = list(get_messages(res.wsgi_request))
|
||||
assert len(messages) == 1
|
||||
assert messages[0].level == DEFAULT_LEVELS["WARNING"]
|
||||
assert messages[0].message == (
|
||||
"Un mineur est barman sur cet appareil, "
|
||||
"vous ne pouvez donc pas vendre d'alcool actuellement."
|
||||
)
|
||||
assert res.context_data["prices"] == [
|
||||
self.gift,
|
||||
self.snack,
|
||||
self.cons,
|
||||
self.dcons,
|
||||
]
|
||||
|
||||
def test_click_unauthorized_customer(self):
|
||||
self.login_in_bar()
|
||||
|
||||
@@ -919,6 +947,48 @@ class TestBarmanConnection(TestCase):
|
||||
assert self.barman in response.wsgi_request.barmen
|
||||
|
||||
|
||||
class TestIsLoggedInCounter(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.counter = baker.make(Counter, type="BAR")
|
||||
cls.other_counter = baker.make(Counter, type="BAR")
|
||||
cls.barman = subscriber_user.make()
|
||||
cls.other_barman = subscriber_user.make()
|
||||
cls.url = reverse("counter:details", kwargs={"counter_id": cls.counter.id})
|
||||
|
||||
def make_request(self, barmen):
|
||||
"""Requête émise depuis une vue du namespace `counter`."""
|
||||
request = RequestFactory().get(self.url)
|
||||
request.resolver_match = resolve(self.url)
|
||||
request.barmen = set(barmen)
|
||||
return request
|
||||
|
||||
def test_denied(self):
|
||||
# nobody is logged
|
||||
request = self.make_request([])
|
||||
assert not is_logged_in_counter(request)
|
||||
|
||||
# somebody is logged, but on another counter
|
||||
self.other_counter.permanencies.create(user=self.barman, start=now())
|
||||
assert not is_logged_in_counter(request, counter=self.counter)
|
||||
|
||||
def test_ok(self):
|
||||
request = self.make_request([self.barman])
|
||||
assert is_logged_in_counter(request)
|
||||
|
||||
self.counter.permanencies.create(user=self.barman, start=now())
|
||||
assert is_logged_in_counter(request, counter=self.counter)
|
||||
|
||||
def test_request_outside_counter_app(self):
|
||||
"""A request coming from outside the counter app is denied."""
|
||||
request = self.make_request([self.barman])
|
||||
request.resolver_match = resolve(reverse("core:index"))
|
||||
assert not is_logged_in_counter(request)
|
||||
|
||||
self.counter.permanencies.create(user=self.barman, start=now())
|
||||
assert not is_logged_in_counter(request, counter=self.counter)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_barman_timeout(client: Client):
|
||||
"""Test that barmen timeout is well managed."""
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from dateutil.utils import today
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.test import TestCase
|
||||
@@ -6,7 +9,7 @@ from model_bakery import baker
|
||||
|
||||
from club.models import Membership
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.models import Group, User
|
||||
from core.models import Group, User, UserBan
|
||||
from counter.baker_recipes import product_recipe
|
||||
from counter.forms import CounterEditForm
|
||||
from counter.models import Counter, CounterSellers
|
||||
@@ -18,7 +21,11 @@ class TestEditCounterSellers(TestCase):
|
||||
cls.counter = baker.make(Counter, type="BAR")
|
||||
cls.products = product_recipe.make(_quantity=2, _bulk_create=True)
|
||||
cls.counter.products.add(*cls.products)
|
||||
users = subscriber_user.make(_quantity=6, _bulk_create=True)
|
||||
users = subscriber_user.make(
|
||||
date_of_birth=today() - timedelta(days=365 * 20),
|
||||
_quantity=6,
|
||||
_bulk_create=True,
|
||||
)
|
||||
cls.regular_barmen = users[:2]
|
||||
cls.tmp_barmen = users[2:4]
|
||||
cls.not_barmen = users[4:]
|
||||
@@ -128,6 +135,54 @@ class TestEditCounterSellers(TestCase):
|
||||
self.counter.sellers.filter(countersellers__is_regular=False)
|
||||
) == set(self.tmp_barmen)
|
||||
|
||||
def test_barman_without_birthdate(self):
|
||||
"""Test that users without a birthdate cannot be sellers."""
|
||||
user = subscriber_user.make()
|
||||
form = CounterEditForm(
|
||||
data={
|
||||
"sellers_regular": [*self.regular_barmen, user],
|
||||
"sellers_temporary": self.tmp_barmen,
|
||||
"products": self.products,
|
||||
},
|
||||
instance=self.counter,
|
||||
user=self.operator,
|
||||
)
|
||||
assert not form.is_valid()
|
||||
assert form.errors == {
|
||||
"sellers_regular": [
|
||||
f"{user.get_full_name()} n'a pas renseigné sa date de naissance."
|
||||
]
|
||||
}
|
||||
|
||||
def test_banned_barman_forbidden(self):
|
||||
"""Test that users with a counter ban cannot be sellers."""
|
||||
UserBan.objects.create(
|
||||
user=self.not_barmen[0],
|
||||
ban_group_id=settings.SITH_GROUP_BANNED_COUNTER_ID,
|
||||
reason="ban comptoir",
|
||||
)
|
||||
UserBan.objects.create(
|
||||
user=self.not_barmen[1],
|
||||
ban_group_id=settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
reason="ban comptoir",
|
||||
)
|
||||
form = CounterEditForm(
|
||||
data={
|
||||
"sellers_regular": [*self.regular_barmen, *self.not_barmen[0:2]],
|
||||
"sellers_temporary": self.tmp_barmen,
|
||||
"products": self.products,
|
||||
},
|
||||
instance=self.counter,
|
||||
user=self.operator,
|
||||
)
|
||||
assert not form.is_valid()
|
||||
assert form.errors == {
|
||||
"sellers_regular": [
|
||||
f"{self.not_barmen[0].get_full_name()} est banni.",
|
||||
f"{self.not_barmen[1].get_full_name()} est banni.",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
class TestEditCounterProducts(TestCase):
|
||||
@classmethod
|
||||
|
||||
@@ -145,7 +145,7 @@ class TestStudentCard(TestCase):
|
||||
|
||||
self.login_in_counter()
|
||||
barman = subscriber_user.make()
|
||||
self.counter.sellers.add(barman)
|
||||
self.counter.sellers.add(barman, through_defaults={"is_regular": True})
|
||||
# We want to test sending requests from another counter while
|
||||
# we are currently registered to another counter
|
||||
# so we connect to a counter and
|
||||
|
||||
+6
-2
@@ -6,8 +6,10 @@ from django.urls import resolve
|
||||
if TYPE_CHECKING:
|
||||
from django.http import HttpRequest
|
||||
|
||||
from counter.models import Counter
|
||||
|
||||
def is_logged_in_counter(request: HttpRequest) -> bool:
|
||||
|
||||
def is_logged_in_counter(request: HttpRequest, counter: Counter | None = None) -> bool:
|
||||
"""Check if the request is sent from a device logged to a counter.
|
||||
|
||||
The request must also be sent within the frame of a counter's activity.
|
||||
@@ -30,4 +32,6 @@ def is_logged_in_counter(request: HttpRequest) -> bool:
|
||||
if not referer_ok and request.resolver_match.app_name != "counter":
|
||||
return False
|
||||
|
||||
return bool(request.barmen)
|
||||
if counter is None:
|
||||
return bool(request.barmen)
|
||||
return bool(request.barmen) and request.barmen.issubset(set(counter.barmen_list))
|
||||
+28
-36
@@ -181,6 +181,9 @@ class ProductEditView(CounterAdminTabsMixin, PermissionRequiredMixin, UpdateView
|
||||
permission_required = "counter.change_product"
|
||||
|
||||
def has_permission(self):
|
||||
# If users can see products but not edit them,
|
||||
# still show them this form, as it is the place where all infos are,
|
||||
# but forbid to save it.
|
||||
return self.request.user.has_perm("counter.change_product") or (
|
||||
self.request.method == "GET"
|
||||
and self.request.user.has_perm("counter.view_product")
|
||||
@@ -306,52 +309,41 @@ class ReturnableProductDeleteView(
|
||||
}
|
||||
|
||||
|
||||
class RefillingDeleteView(DeleteView):
|
||||
class CounterTransactionDeletionView(DeleteView):
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().select_related("counter", "customer")
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.object: Selling | Refilling = self.get_object()
|
||||
if timezone.now() - self.object.date <= timedelta(
|
||||
minutes=settings.SITH_LAST_OPERATIONS_LIMIT
|
||||
) and is_logged_in_counter(request, counter=self.object.counter):
|
||||
self.success_url = reverse(
|
||||
"counter:details", kwargs={"counter_id": self.object.counter_id}
|
||||
)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
elif self.object.is_owned_by(request.user):
|
||||
self.success_url = reverse(
|
||||
"core:user_account", kwargs={"user_id": self.object.customer.user_id}
|
||||
)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
class RefillingDeleteView(CounterTransactionDeletionView):
|
||||
"""Delete a refilling (for the admins)."""
|
||||
|
||||
model = Refilling
|
||||
pk_url_kwarg = "refilling_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if timezone.now() - self.object.date <= timedelta(
|
||||
minutes=settings.SITH_LAST_OPERATIONS_LIMIT
|
||||
) and is_logged_in_counter(request):
|
||||
self.success_url = reverse(
|
||||
"counter:details", kwargs={"counter_id": self.object.counter.id}
|
||||
)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
elif self.object.is_owned_by(request.user):
|
||||
self.success_url = reverse(
|
||||
"core:user_account", kwargs={"user_id": self.object.customer.user.id}
|
||||
)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
class SellingDeleteView(DeleteView):
|
||||
class SellingDeleteView(CounterTransactionDeletionView):
|
||||
"""Delete a selling (for the admins)."""
|
||||
|
||||
model = Selling
|
||||
pk_url_kwarg = "selling_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if timezone.now() - self.object.date <= timedelta(
|
||||
minutes=settings.SITH_LAST_OPERATIONS_LIMIT
|
||||
) and is_logged_in_counter(request):
|
||||
self.success_url = reverse(
|
||||
"counter:details", kwargs={"counter_id": self.object.counter.id}
|
||||
)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
elif self.object.is_owned_by(request.user):
|
||||
self.success_url = reverse(
|
||||
"core:user_account", kwargs={"user_id": self.object.customer.user.id}
|
||||
)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
class CounterStatView(PermissionRequiredMixin, DetailView):
|
||||
|
||||
+81
-11
@@ -43,8 +43,8 @@ from counter.views.mixins import CounterTabsMixin
|
||||
from counter.views.student_card import StudentCardFormFragment
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.http import HttpRequest
|
||||
from django.utils.safestring import SafeString
|
||||
from ninja.main import HttpRequest
|
||||
|
||||
from core.models import User
|
||||
|
||||
@@ -60,9 +60,70 @@ def get_operator(request: HttpRequest, counter: Counter, customer: Customer) ->
|
||||
class CounterClick(
|
||||
CounterTabsMixin, UseFragmentsMixin, CanViewMixin, SingleObjectMixin, FormView
|
||||
):
|
||||
"""The click view
|
||||
This is a detail view not to have to worry about loading the counter
|
||||
Everything is made by hand in the post method.
|
||||
"""The click view.
|
||||
|
||||
This page is reached from the counter main page, after selecting
|
||||
the user who is purchasing stuff.
|
||||
|
||||
# Counter access
|
||||
|
||||
Who can perform barman actions depends on the type of the counter :
|
||||
|
||||
- for eboutic counters, no barman access at all is granted ;
|
||||
it's just a 404, as there should be only one eboutic,
|
||||
accessible only at `/eboutic/`
|
||||
- office counters are accessible to the board members of the
|
||||
club owning the counter and to users that have been
|
||||
explicitly added to the sellers of this counter.
|
||||
- bar counters are accessible to users that have been added to
|
||||
the counter sellers and that are currently logged as barmen
|
||||
on the current device.
|
||||
|
||||
The bar case is really tricky,
|
||||
as it doesn't use the usual django auth backend.
|
||||
Barmen must not be logged in as regular users,
|
||||
but as barmen, granting the session some special privileges,
|
||||
even in the case where no regular user is logged in.
|
||||
|
||||
This is because of two reasons :
|
||||
|
||||
- we track the barmen connection, for logging,
|
||||
statistics and dick contest purposes.
|
||||
We want to know who was barman, where and when,
|
||||
as barmen are accountable of what happens during their duty.
|
||||
- multiple users must be able to log on the same device,
|
||||
while keeping the session anonymous.
|
||||
The bar PC must be a reliable way for any barman to click users,
|
||||
but without requiring a user session.
|
||||
Just imagine if someone who is superuser had to log in with
|
||||
all its privileges on a device everyone can access.
|
||||
|
||||
# Available items
|
||||
|
||||
A counter can have multiple products.
|
||||
A product can have multiple prices.
|
||||
To select what the user can buy, we select
|
||||
all the prices that can be applied to the current
|
||||
customer, among the products of the counter.
|
||||
The price selection logic is described in
|
||||
[PriceQuerySet][counter.models.PriceQuerySet].
|
||||
|
||||
On top of that, some additional rules are applied,
|
||||
because alcohol can be sold on counters :
|
||||
|
||||
- if the customer is minor (or has not filled its birthdate)
|
||||
age restricted products are removed
|
||||
([L.3342-1, Code de la santé publique](https://www.legifrance.gouv.fr/codes/article_lc/LEGIARTI000031927682))
|
||||
- if any barman on the current device is minor,
|
||||
age restricted products are also removed
|
||||
([L.3336-4, Code de la santé publique](https://www.legifrance.gouv.fr/codes/article_lc/LEGIARTI000048654800))
|
||||
|
||||
The minor barman case is a little bit unclear, legally speaking,
|
||||
as barmen are volunteers, but the law speaks only of employees and interns.
|
||||
As such, we don't apply the law to its full extent.
|
||||
It would be harsh for young students not to be able to
|
||||
be barmen at the MDE, where no alcohol at all is sold during daytime.
|
||||
However, we restrict items that can be sold as a token of good will.
|
||||
"""
|
||||
|
||||
model = Counter
|
||||
@@ -111,6 +172,19 @@ class CounterClick(
|
||||
return redirect(obj) # Redirect to counter
|
||||
|
||||
self.prices = list(obj.get_prices_for(self.customer))
|
||||
if any(user.age < 18 for user in request.barmen):
|
||||
# users without a birthdate cannot be sellers on counters,
|
||||
# so the `user.age == 0` case shouldn't happen
|
||||
filtered = [p for p in self.prices if p.product.limit_age < 18]
|
||||
if len(filtered) != len(self.prices):
|
||||
self.prices = filtered
|
||||
messages.warning(
|
||||
request,
|
||||
_(
|
||||
"A minor is barman on this on this device, "
|
||||
"so you cannot currently sell alcohol."
|
||||
),
|
||||
)
|
||||
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
@@ -242,15 +316,11 @@ class RefillingCreateView(FragmentMixin, CreateView):
|
||||
if not self.customer.can_buy:
|
||||
raise Http404
|
||||
|
||||
if not is_logged_in_counter(request):
|
||||
raise PermissionDenied
|
||||
|
||||
self.counter: Counter = get_object_or_404(Counter, id=self.kwargs["counter_id"])
|
||||
|
||||
if not (
|
||||
request.barmen
|
||||
and request.barmen.issubset(self.counter.barmen_list)
|
||||
and self.counter.can_refill
|
||||
if (
|
||||
not is_logged_in_counter(request, counter=self.counter)
|
||||
or not self.counter.can_refill
|
||||
):
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ from datetime import timedelta
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db.models import F
|
||||
from django.http import HttpRequest, HttpResponseRedirect
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
@@ -36,6 +36,7 @@ from counter.utils import is_logged_in_counter
|
||||
from counter.views.mixins import CounterTabsMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.http import HttpRequest, HttpResponseRedirect
|
||||
from django.utils.safestring import SafeString
|
||||
|
||||
|
||||
@@ -155,7 +156,7 @@ class CounterMain(
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class CounterLastOperationsView(CounterTabsMixin, CanViewMixin, DetailView):
|
||||
class CounterLastOperationsView(CounterTabsMixin, UserPassesTestMixin, DetailView):
|
||||
"""Provide the last operations to allow barmen to delete them."""
|
||||
|
||||
model = Counter
|
||||
@@ -163,14 +164,12 @@ class CounterLastOperationsView(CounterTabsMixin, CanViewMixin, DetailView):
|
||||
template_name = "counter/last_ops.jinja"
|
||||
current_tab = "last_ops"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
"""We have here again a very particular right handling."""
|
||||
def test_func(self):
|
||||
self.object = self.get_object()
|
||||
if is_logged_in_counter(request) and self.object.barmen_list:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
return HttpResponseRedirect(
|
||||
reverse("counter:details", kwargs={"counter_id": self.object.id})
|
||||
+ "?bad_location"
|
||||
return is_logged_in_counter(
|
||||
self.request, counter=self.object
|
||||
) or self.request.user.has_perms(
|
||||
["counter.view_selling", "counter.view_refilling"]
|
||||
)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
||||
@@ -22,7 +22,7 @@ from counter.utils import is_logged_in_counter
|
||||
|
||||
class CounterTabsMixin(TabedViewMixin):
|
||||
def get_tabs_title(self):
|
||||
return self.object
|
||||
return self.object.name
|
||||
|
||||
def get_list_of_tabs(self):
|
||||
if self.object.type != "BAR":
|
||||
@@ -46,7 +46,11 @@ class CounterTabsMixin(TabedViewMixin):
|
||||
"name": _("Cash summary"),
|
||||
}
|
||||
)
|
||||
if is_logged_in_counter(self.request):
|
||||
if is_logged_in_counter(
|
||||
self.request, counter=self.object
|
||||
) or self.request.user.has_perms(
|
||||
["counter.view_selling", "counter.view_refilling"]
|
||||
):
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse(
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
::: counter.views
|
||||
@@ -0,0 +1,6 @@
|
||||
::: counter.views.click
|
||||
handler: python
|
||||
options:
|
||||
members:
|
||||
- CounterClick
|
||||
- RefillingCreateView
|
||||
@@ -0,0 +1 @@
|
||||
::: counter.views.home
|
||||
@@ -0,0 +1,7 @@
|
||||
::: counter.views.mixins
|
||||
handler: python
|
||||
options:
|
||||
heading_level: 3
|
||||
members:
|
||||
- CounterTabsMixin
|
||||
- CounterAdminTabsMixin
|
||||
@@ -0,0 +1,5 @@
|
||||
::: counter.views.admin
|
||||
::: counter.views.cash
|
||||
::: counter.views.eticket
|
||||
::: counter.views.invoice
|
||||
::: counter.views.student_card
|
||||
@@ -5,24 +5,13 @@
|
||||
{%- trans %}Election list{% endtrans %}
|
||||
{%- endblock %}
|
||||
|
||||
{% block head %}
|
||||
{{ super() -}}
|
||||
<style>
|
||||
small {
|
||||
font-size: smaller;
|
||||
}
|
||||
|
||||
time {
|
||||
font-weight: bolder;
|
||||
}
|
||||
</style>
|
||||
{%- endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans %}Current elections{% endtrans %}</h3>
|
||||
<a class="btn btn-blue" href="{{ url("election:create") }}">
|
||||
<i class="fa fa-plus"></i>{% trans %}New election{% endtrans %}
|
||||
</a>
|
||||
{% if user.has_perm("election.add_election") %}
|
||||
<a class="btn btn-blue" href="{{ url("election:create") }}">
|
||||
<i class="fa fa-plus"></i>{% trans %}New election{% endtrans %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{%- for election in object_list %}
|
||||
<hr>
|
||||
<section>
|
||||
|
||||
+111
-254
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-10-25 12:04+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"
|
||||
@@ -20,15 +20,15 @@ msgstr ""
|
||||
msgid "Email domain is not allowed."
|
||||
msgstr "Le domaine de l'addresse e-mail n'est pas autorisé."
|
||||
|
||||
#: antispam/models.py
|
||||
#: antispam/models/models.py
|
||||
msgid "domain"
|
||||
msgstr "domaine"
|
||||
|
||||
#: antispam/models.py
|
||||
#: antispam/models/models.py
|
||||
msgid "is externally managed"
|
||||
msgstr "est géré de manière externe"
|
||||
|
||||
#: antispam/models.py
|
||||
#: antispam/models/models.py
|
||||
msgid ""
|
||||
"True if kept up-to-date using external toxic domain providers, else False"
|
||||
msgstr ""
|
||||
@@ -192,46 +192,6 @@ msgstr ""
|
||||
"arrivée durant l'interaction avec l'application tierce. Veuillez contacter "
|
||||
"les responsables de cette dernière."
|
||||
|
||||
#: club/forms.py
|
||||
msgid "Users to add"
|
||||
msgstr "Utilisateurs à ajouter"
|
||||
|
||||
#: club/forms.py core/views/group.py
|
||||
msgid "Search users to add (one or more)."
|
||||
msgstr "Recherche les utilisateurs à ajouter (un ou plus)."
|
||||
|
||||
#: club/forms.py
|
||||
msgid "New Mailing"
|
||||
msgstr "Nouvelle mailing liste"
|
||||
|
||||
#: club/forms.py
|
||||
msgid "Subscribe"
|
||||
msgstr "S'abonner"
|
||||
|
||||
#: club/forms.py
|
||||
msgid "Remove"
|
||||
msgstr "Retirer"
|
||||
|
||||
#: club/forms.py counter/forms.py pedagogy/templates/pedagogy/moderation.jinja
|
||||
msgid "Action"
|
||||
msgstr "Action"
|
||||
|
||||
#: club/forms.py club/tests/test_mailing.py
|
||||
msgid "This field is required"
|
||||
msgstr "Ce champ est obligatoire"
|
||||
|
||||
#: club/forms.py club/tests/test_mailing.py
|
||||
msgid "One of the selected users doesn't have an email address"
|
||||
msgstr "Un des utilisateurs sélectionnés n'a pas d'adresse email"
|
||||
|
||||
#: club/forms.py
|
||||
msgid "An action is required"
|
||||
msgstr "Une action est requise"
|
||||
|
||||
#: club/forms.py club/tests/test_mailing.py
|
||||
msgid "You must specify at least an user or an email address"
|
||||
msgstr "vous devez spécifier au moins un utilisateur ou une adresse email"
|
||||
|
||||
#: club/forms.py counter/forms.py
|
||||
msgid "Begin date"
|
||||
msgstr "Date de début"
|
||||
@@ -291,6 +251,10 @@ msgstr "Inactif"
|
||||
msgid "All clubs"
|
||||
msgstr "Tous les clubs"
|
||||
|
||||
#: club/forms.py
|
||||
msgid "Provide an english name for non-french speaking users."
|
||||
msgstr "Fournissez un nom anglais pour les utilisateurs non-francophones."
|
||||
|
||||
#: club/models.py
|
||||
msgid "slug name"
|
||||
msgstr "nom slug"
|
||||
@@ -380,6 +344,10 @@ msgid "A role cannot be in the presidency while not being in the board"
|
||||
msgstr ""
|
||||
"Un rôle ne peut pas appartenir à la présidence sans être dans le bureau"
|
||||
|
||||
#: club/models.py
|
||||
msgid "There is already a role with that name"
|
||||
msgstr "Il existe déjà un rôle avec ce nom"
|
||||
|
||||
#: club/models.py
|
||||
#, python-format
|
||||
msgid "Role %(role)s cannot be placed below a member role"
|
||||
@@ -415,60 +383,6 @@ msgstr "rôle"
|
||||
msgid "past member"
|
||||
msgstr "ancien membre"
|
||||
|
||||
#: club/models.py com/templates/com/mailing_admin.jinja
|
||||
#: com/templates/com/news_admin_list.jinja com/templates/com/weekmail.jinja
|
||||
#: core/templates/core/user_clubs.jinja
|
||||
#: counter/templates/counter/invoices_call.jinja
|
||||
#: trombi/templates/trombi/edit_profile.jinja
|
||||
#: trombi/templates/trombi/export.jinja
|
||||
#: trombi/templates/trombi/user_profile.jinja
|
||||
msgid "Club"
|
||||
msgstr "Club"
|
||||
|
||||
#: club/models.py
|
||||
msgid "Email address"
|
||||
msgstr "Adresse email"
|
||||
|
||||
#: club/models.py
|
||||
msgid "Enter a valid address. Only the root of the address is needed."
|
||||
msgstr ""
|
||||
"Entrez une adresse valide. Seule la racine de l'adresse est nécessaire."
|
||||
|
||||
#: club/models.py com/models.py core/models.py
|
||||
msgid "is moderated"
|
||||
msgstr "est modéré"
|
||||
|
||||
#: club/models.py com/models.py
|
||||
msgid "moderator"
|
||||
msgstr "modérateur"
|
||||
|
||||
#: club/models.py
|
||||
msgid "This mailing list already exists."
|
||||
msgstr "Cette liste de diffusion existe déjà."
|
||||
|
||||
#: club/models.py club/templates/club/mailing.jinja
|
||||
msgid "Mailing"
|
||||
msgstr "Liste de diffusion"
|
||||
|
||||
#: club/models.py club/templates/club/club_members.jinja
|
||||
#: club/templates/club/club_old_members.jinja club/templates/club/mailing.jinja
|
||||
#: counter/templates/counter/cash_summary_list.jinja
|
||||
#: counter/templates/counter/stats.jinja
|
||||
msgid "User"
|
||||
msgstr "Utilisateur"
|
||||
|
||||
#: club/models.py
|
||||
msgid "At least user or email is required"
|
||||
msgstr "Au moins un utilisateur ou un email est nécessaire"
|
||||
|
||||
#: club/models.py club/tests/test_mailing.py
|
||||
msgid "This email is already suscribed in this mailing"
|
||||
msgstr "Cet email est déjà abonné à cette mailing"
|
||||
|
||||
#: club/models.py
|
||||
msgid "Unregistered user"
|
||||
msgstr "Utilisateur non enregistré"
|
||||
|
||||
#: club/models.py
|
||||
msgid "The base url that links with this type must respect"
|
||||
msgstr "L'url de base que tous les liens de ce type doivent respecter"
|
||||
@@ -571,6 +485,13 @@ msgstr "Membres du club"
|
||||
msgid "Manage roles"
|
||||
msgstr "Gérer les rôles"
|
||||
|
||||
#: club/templates/club/club_members.jinja
|
||||
#: club/templates/club/club_old_members.jinja
|
||||
#: counter/templates/counter/cash_summary_list.jinja
|
||||
#: counter/templates/counter/stats.jinja
|
||||
msgid "User"
|
||||
msgstr "Utilisateur"
|
||||
|
||||
#: club/templates/club/club_members.jinja
|
||||
#: club/templates/club/club_old_members.jinja
|
||||
#: core/templates/core/user_clubs.jinja
|
||||
@@ -863,8 +784,7 @@ msgstr "Total"
|
||||
msgid "Payment method"
|
||||
msgstr "Méthode de paiement"
|
||||
|
||||
#: club/templates/club/club_sellings.jinja club/templates/club/mailing.jinja
|
||||
#: com/templates/com/macros.jinja com/templates/com/mailing_admin.jinja
|
||||
#: club/templates/club/club_sellings.jinja com/templates/com/macros.jinja
|
||||
#: com/templates/com/news_admin_list.jinja com/templates/com/poster_edit.jinja
|
||||
#: com/templates/com/screen_edit.jinja com/templates/com/weekmail.jinja
|
||||
#: core/templates/core/file_detail.jinja
|
||||
@@ -990,60 +910,6 @@ msgstr "Ajouter"
|
||||
msgid "Join"
|
||||
msgstr "Rejoindre"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "Mailing lists"
|
||||
msgstr "Mailing listes"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid ""
|
||||
"Remember : mailing lists need to be moderated, if your new created list is "
|
||||
"not shown wait until moderation takes action"
|
||||
msgstr ""
|
||||
"Rappelez vous : les mailing listes doivent être modérées, si votre liste "
|
||||
"nouvellement créée n'est pas affichée, attendez jusqu'à ce qu'un modérateur "
|
||||
"prenne une décision"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "Mailing lists waiting for moderation"
|
||||
msgstr "Listes de diffusions en attente de modération"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "Generate mailing list"
|
||||
msgstr "Générer la liste de diffusion"
|
||||
|
||||
#: club/templates/club/mailing.jinja com/templates/com/mailing_admin.jinja
|
||||
msgid "Email"
|
||||
msgstr "Email"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "Remove from mailing list"
|
||||
msgstr "Supprimer de la liste de diffusion"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "There is no subscriber for this mailing list"
|
||||
msgstr "Il n'y a pas d'abonnés dans cette liste de diffusion"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "No mailing list existing for this club"
|
||||
msgstr "Aucune mailing liste n'existe pour ce club"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
#: subscription/templates/subscription/subscription.jinja
|
||||
msgid "New member"
|
||||
msgstr "Nouveau membre"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "Add to mailing list"
|
||||
msgstr "Ajouter à la mailing liste"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "New mailing"
|
||||
msgstr "Nouvelle liste de diffusion"
|
||||
|
||||
#: club/templates/club/mailing.jinja
|
||||
msgid "Create mailing list"
|
||||
msgstr "Créer une liste de diffusion"
|
||||
|
||||
#: club/templates/club/pagerev_edit.jinja core/templates/core/page/edit.jinja
|
||||
msgid "Edit page"
|
||||
msgstr "Éditer la page"
|
||||
@@ -1074,10 +940,6 @@ msgstr "Outils"
|
||||
msgid "Sellings"
|
||||
msgstr "Vente"
|
||||
|
||||
#: club/views.py
|
||||
msgid "Mailing list"
|
||||
msgstr "Listes de diffusion"
|
||||
|
||||
#: club/views.py
|
||||
msgid "You are now a member of this club."
|
||||
msgstr "Vous êtes maintenant membre de ce club."
|
||||
@@ -1208,6 +1070,10 @@ msgstr "auteur"
|
||||
msgid "is published"
|
||||
msgstr "est publié"
|
||||
|
||||
#: com/models.py
|
||||
msgid "moderator"
|
||||
msgstr "modérateur"
|
||||
|
||||
#: com/models.py
|
||||
msgid "news"
|
||||
msgstr "nouvelle"
|
||||
@@ -1268,6 +1134,10 @@ msgstr "fichier"
|
||||
msgid "display time"
|
||||
msgstr "temps d'affichage"
|
||||
|
||||
#: com/models.py core/models.py
|
||||
msgid "is moderated"
|
||||
msgstr "est modéré"
|
||||
|
||||
#: com/models.py
|
||||
msgid "Begin date should be before end date"
|
||||
msgstr "La date de début doit être avant celle de fin"
|
||||
@@ -1303,46 +1173,6 @@ msgstr "Nouvelle publiée"
|
||||
msgid "News deleted"
|
||||
msgstr "Nouvelle supprimée"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja com/views.py
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Mailing lists administration"
|
||||
msgstr "Administration des mailing listes"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja
|
||||
#: com/templates/com/news_admin_list.jinja com/templates/com/weekmail.jinja
|
||||
#: counter/templates/counter/refilling_list.jinja
|
||||
msgid "Actions"
|
||||
msgstr "Actions"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja com/templates/com/poster_list.jinja
|
||||
#: core/templates/core/file_detail.jinja
|
||||
#: core/templates/core/file_moderation.jinja
|
||||
#: pedagogy/templates/pedagogy/fragments/ue_detail/comments.jinja
|
||||
#: sas/templates/sas/moderation.jinja sas/templates/sas/picture.jinja
|
||||
msgid "Moderate"
|
||||
msgstr "Modérer"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja
|
||||
#, python-format
|
||||
msgid "Moderated by %(user)s"
|
||||
msgstr "Modéré par %(user)s"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja
|
||||
msgid "This page lists all mailing lists"
|
||||
msgstr "Cette page liste toutes les listes de diffusion"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja
|
||||
msgid "Not moderated mailing lists"
|
||||
msgstr "Listes de diffusion non modérées"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja
|
||||
msgid "Moderated mailing lists"
|
||||
msgstr "Modérer les listes de diffusion"
|
||||
|
||||
#: com/templates/com/mailing_admin.jinja
|
||||
msgid "No mailing list existing"
|
||||
msgstr "Aucune liste de diffusion existante"
|
||||
|
||||
#: com/templates/com/news_admin_list.jinja
|
||||
msgid "News admin"
|
||||
msgstr "Administration des nouvelles"
|
||||
@@ -1366,6 +1196,15 @@ msgstr "Événements hebdomadaires affichées"
|
||||
msgid "Title"
|
||||
msgstr "Titre"
|
||||
|
||||
#: com/templates/com/news_admin_list.jinja com/templates/com/weekmail.jinja
|
||||
#: core/templates/core/user_clubs.jinja
|
||||
#: counter/templates/counter/invoices_call.jinja
|
||||
#: trombi/templates/trombi/edit_profile.jinja
|
||||
#: trombi/templates/trombi/export.jinja
|
||||
#: trombi/templates/trombi/user_profile.jinja
|
||||
msgid "Club"
|
||||
msgstr "Club"
|
||||
|
||||
#: com/templates/com/news_admin_list.jinja com/templates/com/weekmail.jinja
|
||||
#: forum/templates/forum/forum.jinja sas/models.py
|
||||
msgid "Author"
|
||||
@@ -1380,6 +1219,11 @@ msgstr "Modérateur"
|
||||
msgid "Dates"
|
||||
msgstr "Dates"
|
||||
|
||||
#: com/templates/com/news_admin_list.jinja com/templates/com/weekmail.jinja
|
||||
#: counter/templates/counter/refilling_list.jinja
|
||||
msgid "Actions"
|
||||
msgstr "Actions"
|
||||
|
||||
#: com/templates/com/news_admin_list.jinja core/templates/core/file.jinja
|
||||
#: core/templates/core/page/base.jinja
|
||||
msgid "View"
|
||||
@@ -1535,6 +1379,13 @@ msgstr "Créer"
|
||||
msgid "Click to expand"
|
||||
msgstr "Cliquez pour agrandir"
|
||||
|
||||
#: com/templates/com/poster_list.jinja core/templates/core/file_detail.jinja
|
||||
#: core/templates/core/file_moderation.jinja
|
||||
#: pedagogy/templates/pedagogy/fragments/ue_detail/comments.jinja
|
||||
#: sas/templates/sas/moderation.jinja sas/templates/sas/picture.jinja
|
||||
msgid "Moderate"
|
||||
msgstr "Modérer"
|
||||
|
||||
#: com/templates/com/poster_list.jinja
|
||||
msgid "No posters"
|
||||
msgstr "Aucune affiche"
|
||||
@@ -1660,17 +1511,13 @@ msgstr "Le mot de la fin"
|
||||
msgid "Communication administration"
|
||||
msgstr "Administration de la communication"
|
||||
|
||||
#: com/views.py core/templates/core/user_tools.jinja
|
||||
#: com/views.py
|
||||
msgid "Weekmail destinations"
|
||||
msgstr "Destinataires du Weekmail"
|
||||
|
||||
#: com/views.py
|
||||
msgid "Info message"
|
||||
msgstr "Message d'info"
|
||||
|
||||
#: com/views.py
|
||||
msgid "Alert message"
|
||||
msgstr "Message d'alerte"
|
||||
msgid "Banner messages"
|
||||
msgstr "Messages de bannière"
|
||||
|
||||
#: com/views.py
|
||||
msgid "Posters list"
|
||||
@@ -2857,14 +2704,6 @@ msgstr "Clubs actuels : "
|
||||
msgid "Old club(s) :"
|
||||
msgstr "Anciens clubs :"
|
||||
|
||||
#: core/templates/core/user_clubs.jinja
|
||||
msgid "Subscribed mailing lists"
|
||||
msgstr "Mailing listes abonnées"
|
||||
|
||||
#: core/templates/core/user_clubs.jinja
|
||||
msgid "Unsubscribe"
|
||||
msgstr "Se désabonner"
|
||||
|
||||
#: core/templates/core/user_detail.jinja
|
||||
#, python-format
|
||||
msgid "%(user_name)s's profile"
|
||||
@@ -3149,24 +2988,6 @@ msgstr "Gestion générale des comptoirs"
|
||||
msgid "Products management"
|
||||
msgstr "Gestion des produits"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Product types management"
|
||||
msgstr "Gestion des types de produit"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Returnable products management"
|
||||
msgstr "Gestion des consignes"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
#: counter/templates/counter/cash_summary_list.jinja counter/views/mixins.py
|
||||
msgid "Cash register summaries"
|
||||
msgstr "Relevés de caisse"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
#: counter/templates/counter/invoices_call.jinja counter/views/mixins.py
|
||||
msgid "Invoices call"
|
||||
msgstr "Appels à facture"
|
||||
|
||||
#: core/templates/core/user_tools.jinja core/views/user.py
|
||||
#: counter/templates/counter/counter_list.jinja
|
||||
msgid "Stats"
|
||||
@@ -3176,6 +2997,11 @@ msgstr "Stats"
|
||||
msgid "Accounting"
|
||||
msgstr "Comptabilité"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
#: counter/templates/counter/invoices_call.jinja counter/views/mixins.py
|
||||
msgid "Invoices call"
|
||||
msgstr "Appels à facture"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Refound Account"
|
||||
msgstr "Rembourser un compte"
|
||||
@@ -3184,25 +3010,13 @@ msgstr "Rembourser un compte"
|
||||
msgid "Communication"
|
||||
msgstr "Communication"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Create weekmail article"
|
||||
msgstr "Rédiger un nouvel article dans le Weekmail"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Moderate news"
|
||||
msgstr "Modérer les nouvelles"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Edit alert message"
|
||||
msgstr "Éditer le message d'alerte"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Edit information message"
|
||||
msgstr "Éditer le message d'informations"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Moderate files"
|
||||
msgstr "Modérer les fichiers"
|
||||
msgid "Edit banner messages"
|
||||
msgstr "Éditer les messages de bannière"
|
||||
|
||||
#: core/templates/core/user_tools.jinja
|
||||
msgid "Moderate pictures"
|
||||
@@ -3275,6 +3089,10 @@ msgstr "Erreur d'envoi du fichier %(file_name)s : %(msg)s"
|
||||
msgid "Apply rights recursively"
|
||||
msgstr "Appliquer les droits récursivement"
|
||||
|
||||
#: core/views/files.py
|
||||
msgid "You cannot move this file there"
|
||||
msgstr "Vous ne pouvez pas déplacer ce fichier là"
|
||||
|
||||
#: core/views/forms.py
|
||||
msgid "Ensure this timestamp is set in the future"
|
||||
msgstr "Assurez-vous que cet horodatage est dans le futur"
|
||||
@@ -3346,6 +3164,10 @@ msgstr "%s est déjà votre fillot/fillote"
|
||||
msgid "Users to add to group"
|
||||
msgstr "Utilisateurs à ajouter au groupe"
|
||||
|
||||
#: core/views/group.py
|
||||
msgid "Search users to add (one or more)."
|
||||
msgstr "Recherche les utilisateurs à ajouter (un ou plus)."
|
||||
|
||||
#: core/views/group.py
|
||||
msgid "Users to remove from group"
|
||||
msgstr "Utilisateurs à retirer du groupe"
|
||||
@@ -3388,6 +3210,14 @@ msgstr "Cet UID est invalide"
|
||||
msgid "User not found"
|
||||
msgstr "Utilisateur non trouvé"
|
||||
|
||||
#: counter/forms.py
|
||||
msgid "This user cannot buy items on counters."
|
||||
msgstr "Cet utilisateur ne peut pas faire d'achats sur les comptoirs."
|
||||
|
||||
#: counter/forms.py
|
||||
msgid "This user is banned from AE places. Take him/her out if you can."
|
||||
msgstr "Cette personne est ban comptoir. Faites-la sortir si vous le pouvez."
|
||||
|
||||
#: counter/forms.py
|
||||
msgid "You are not a barman of this counter."
|
||||
msgstr "Vous n'êtes pas barman sur ce comptoir."
|
||||
@@ -3435,6 +3265,16 @@ msgstr ""
|
||||
"Si vous souhaitez ajouter sur ce comptoir un produit qui n'appartient pas à "
|
||||
"votre club, vous devriez demander à un admin."
|
||||
|
||||
#: counter/forms.py
|
||||
#, python-format
|
||||
msgid "%(user)s is banned."
|
||||
msgstr "%(user)s est banni."
|
||||
|
||||
#: counter/forms.py
|
||||
#, python-format
|
||||
msgid "%(user)s has not filled its birthdate."
|
||||
msgstr "%(user)s n'a pas renseigné sa date de naissance."
|
||||
|
||||
#: counter/forms.py
|
||||
#, python-format
|
||||
msgid ""
|
||||
@@ -3445,6 +3285,10 @@ msgstr ""
|
||||
"temps, mais les utilisateurs suivants ont été définis comme les deux : "
|
||||
"%(users)s"
|
||||
|
||||
#: counter/forms.py pedagogy/templates/pedagogy/moderation.jinja
|
||||
msgid "Action"
|
||||
msgstr "Action"
|
||||
|
||||
#: counter/forms.py
|
||||
msgid "Date and time of action"
|
||||
msgstr "Date et heure de l'action"
|
||||
@@ -3932,6 +3776,10 @@ msgstr "Liste des relevés de caisse"
|
||||
msgid "Theoric sums"
|
||||
msgstr "Sommes théoriques"
|
||||
|
||||
#: counter/templates/counter/cash_summary_list.jinja counter/views/mixins.py
|
||||
msgid "Cash register summaries"
|
||||
msgstr "Relevés de caisse"
|
||||
|
||||
#: counter/templates/counter/cash_summary_list.jinja counter/views/cash.py
|
||||
msgid "Emptied"
|
||||
msgstr "Coffre vidé"
|
||||
@@ -4499,6 +4347,14 @@ msgstr "Nombre de chèque"
|
||||
msgid "You cannot click users on this counter"
|
||||
msgstr "Vous ne pouvez pas cliquer des gens sur ce comptoir"
|
||||
|
||||
#: counter/views/click.py
|
||||
msgid ""
|
||||
"A minor is barman on this on this device, so you cannot currently sell "
|
||||
"alcohol."
|
||||
msgstr ""
|
||||
"Un mineur est barman sur cet appareil, vous ne pouvez donc pas vendre "
|
||||
"d'alcool actuellement."
|
||||
|
||||
#: counter/views/eticket.py
|
||||
msgid "people(s)"
|
||||
msgstr "personne(s)"
|
||||
@@ -5652,14 +5508,14 @@ msgstr "Photos de %(user_name)s"
|
||||
msgid "Download all my pictures"
|
||||
msgstr "Télécharger toutes mes photos"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "English"
|
||||
msgstr "Anglais"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "French"
|
||||
msgstr "Français"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "English"
|
||||
msgstr "Anglais"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "TC"
|
||||
msgstr "TC"
|
||||
@@ -5896,10 +5752,6 @@ msgstr "Cursus alternant (-20%)"
|
||||
msgid "A new poster needs to be moderated"
|
||||
msgstr "Une nouvelle affiche a besoin d'être modérée"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "A new mailing list needs to be moderated"
|
||||
msgstr "Une nouvelle mailing list a besoin d'être modérée"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "A new pedagogy comment has been signaled for moderation"
|
||||
msgstr ""
|
||||
@@ -6028,6 +5880,10 @@ msgstr "Toutes les cotisations"
|
||||
msgid "Existing member"
|
||||
msgstr "Membre existant"
|
||||
|
||||
#: subscription/templates/subscription/subscription.jinja
|
||||
msgid "New member"
|
||||
msgstr "Nouveau membre"
|
||||
|
||||
#: subscription/views.py
|
||||
msgid "the groups that can create subscriptions"
|
||||
msgstr "les groupes pouvant créer des cotisations"
|
||||
@@ -6114,7 +5970,8 @@ msgstr "Rendre cet emploi du temps publique"
|
||||
msgid ""
|
||||
"You can change this at any time in <a href=\"%(url)s\">your preferences</a>"
|
||||
msgstr ""
|
||||
"Vous pouvez changer ceci n'importe quand dans <a href=\"%(url)s\">vos préférences</a>"
|
||||
"Vous pouvez changer ceci n'importe quand dans <a href=\"%(url)s\">vos "
|
||||
"préférences</a>"
|
||||
|
||||
#: timetable/templates/timetable/generator.jinja
|
||||
msgid "Save timetable"
|
||||
|
||||
+5
-1
@@ -113,7 +113,11 @@ nav:
|
||||
- reference/core/auth.md
|
||||
- counter:
|
||||
- reference/counter/models.md
|
||||
- reference/counter/views.md
|
||||
- Views:
|
||||
- reference/counter/views/home.md
|
||||
- reference/counter/views/click.md
|
||||
- reference/counter/views/mixins.md
|
||||
- reference/counter/views/others.md
|
||||
- reference/counter/schemas.md
|
||||
- eboutic:
|
||||
- reference/eboutic/models.md
|
||||
|
||||
Generated
+565
-438
File diff suppressed because it is too large.
Load diff
+18
-18
@@ -24,20 +24,20 @@
|
||||
"#com:*": "./com/static/bundled/*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^8.0.9",
|
||||
"@babel/core": "^8.1.2",
|
||||
"@babel/preset-env": "^8.0.7",
|
||||
"@biomejs/biome": "^2.6.3",
|
||||
"@biomejs/biome": "^2.6.8",
|
||||
"@hey-api/openapi-ts": "^0.99.0",
|
||||
"@types/alpinejs": "^3.17.0",
|
||||
"@types/alpinejs__sort": "^3.13.0",
|
||||
"@types/cytoscape-cxtmenu": "^3.4.5",
|
||||
"@types/cytoscape-klay": "^3.1.5",
|
||||
"@types/js-cookie": "^3.0.6",
|
||||
"@types/node": "^26.6.5",
|
||||
"@types/node": "^26.6.6",
|
||||
"@typescript/native": "npm:typescript@^7.0.2",
|
||||
"rollup-plugin-visualizer": "^7.1.1",
|
||||
"rollup-plugin-visualizer": "^7.1.3",
|
||||
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
||||
"vite": "^8.3.5"
|
||||
"vite": "^8.3.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ae_utbm/aemark": "^0.1.4",
|
||||
@@ -45,30 +45,30 @@
|
||||
"@arendjr/text-clipper": "npm:@jsr/arendjr__text-clipper@^3.0.0",
|
||||
"@floating-ui/dom": "^1.8.0",
|
||||
"@fortawesome/fontawesome-free": "^7.3.1",
|
||||
"@fullcalendar/core": "^6.1.21",
|
||||
"@fullcalendar/daygrid": "^6.1.21",
|
||||
"@fullcalendar/icalendar": "^6.1.21",
|
||||
"@fullcalendar/list": "^6.1.21",
|
||||
"@sentry/browser": "^11.9.0",
|
||||
"@zip.js/zip.js": "^2.24.0",
|
||||
"3d-force-graph": "^1.80.1",
|
||||
"@fullcalendar/core": "^6.1.22",
|
||||
"@fullcalendar/daygrid": "^6.1.22",
|
||||
"@fullcalendar/icalendar": "^6.1.22",
|
||||
"@fullcalendar/list": "^6.1.22",
|
||||
"@sentry/browser": "^11.15.0",
|
||||
"@zip.js/zip.js": "^2.25.0",
|
||||
"3d-force-graph": "^1.80.2",
|
||||
"alpinejs": "^3.17.5",
|
||||
"chart.js": "^4.6.1",
|
||||
"country-flag-emoji-polyfill": "^0.1.10",
|
||||
"cytoscape": "^3.34.4",
|
||||
"cytoscape": "^3.35.0",
|
||||
"cytoscape-cxtmenu": "^3.5.0",
|
||||
"cytoscape-klay": "^3.1.4",
|
||||
"d3-force-3d": "^3.0.6",
|
||||
"easymde": "^2.21.0",
|
||||
"glob": "^13.0.6",
|
||||
"glob": "^14.0.6",
|
||||
"html2canvas": "^1.4.1",
|
||||
"htmx.org": "^4.0.0",
|
||||
"htmx.org": "^4.0.2",
|
||||
"js-cookie": "^3.0.8",
|
||||
"lit-html": "^3.3.3",
|
||||
"native-file-system-adapter": "^3.0.1",
|
||||
"temporal-polyfill": "^1.0.6",
|
||||
"three": "^0.186.1",
|
||||
"temporal-polyfill": "^1.0.8",
|
||||
"three": "^0.187.0",
|
||||
"three-spritetext": "^1.10.0",
|
||||
"tom-select": "^2.6.2"
|
||||
"tom-select": "^2.7.0"
|
||||
}
|
||||
}
|
||||
+16
-14
@@ -19,23 +19,23 @@ authors = [
|
||||
license = { text = "GPL-3.0-only" }
|
||||
requires-python = "<4.0,>=3.14"
|
||||
dependencies = [
|
||||
"django>=5.2.18,<6.0.0",
|
||||
"django-ninja>=1.7.1,<2.0.0",
|
||||
"django>=5.2.19,<6.0.0",
|
||||
"django-ninja>=1.7.3,<2.0.0",
|
||||
"django-ninja-extra>=0.31.7",
|
||||
"Pillow>=13.0.0,<14",
|
||||
"aemark>=0.1.4",
|
||||
"django-jinja<3.0.0,>=2.11.0",
|
||||
"cryptography>=50.0.2,<51.0.0",
|
||||
"django-phonenumber-field>=9.0.0,<10",
|
||||
"phonenumbers>=9.0.41,<10.0.0",
|
||||
"phonenumbers>=9.0.43,<10.0.0",
|
||||
"reportlab>=5.1.0,<6.0.0",
|
||||
"django-haystack>=3.4.0,<4.0.0",
|
||||
"xapian-haystack>=4.0.0,<5.0.0",
|
||||
"libsass>=0.23.0,<1.0.0",
|
||||
"django-ordered-model>=3.7.4,<4.0.0",
|
||||
"django-simple-captcha>=0.7.0,<1.0.0",
|
||||
"python-dateutil>=3.0.0,<4",
|
||||
"sentry-sdk>=2.73.0,<3.0.0",
|
||||
"django-simple-captcha>=0.8.0,<1.0.0",
|
||||
"python-dateutil>=4.0.0,<5",
|
||||
"sentry-sdk>=2.75.0,<3.0.0",
|
||||
"jinja2>=3.1.6,<4.0.0",
|
||||
"django-countries>=9.1.0,<10.0.0",
|
||||
"dict2xml>=1.7.8,<2.0.0",
|
||||
@@ -52,6 +52,7 @@ dependencies = [
|
||||
"celery[redis]>=5.6.3,<7",
|
||||
"django-celery-results>=2.6.0,<3",
|
||||
"django-celery-beat>=2.9.0,<3",
|
||||
"django-modeltranslation>=0.20.6",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
@@ -60,31 +61,32 @@ documentation = "https://sith-ae.readthedocs.io/"
|
||||
|
||||
[dependency-groups]
|
||||
prod = [
|
||||
"psycopg[c]>=3.3.6,<4.0.0",
|
||||
"psycopg[c]>=3.3.9,<4.0.0",
|
||||
"uwsgi>=2.0.31,<3",
|
||||
]
|
||||
dev = [
|
||||
"django-debug-toolbar>=8.0.0,<9",
|
||||
"ipython>=9.17.1,<10.0.0",
|
||||
"ipython>=9.18.1,<10.0.0",
|
||||
"pre-commit>=4.7.0,<5.0.0",
|
||||
"ruff>=0.17.2,<1.0.0",
|
||||
"ruff>=0.17.6,<1.0.0",
|
||||
"djhtml>=3.0.11,<4.0.0",
|
||||
"faker>=40.43.0,<41.0.0",
|
||||
"faker>=40.54.0,<41.0.0",
|
||||
"rjsmin>=1.3.0,<2.0.0",
|
||||
]
|
||||
tests = [
|
||||
"freezegun>=1.5.5,<2.0.0",
|
||||
"pytest>=9.1.1,<10.0.0",
|
||||
"pytest>=9.2.0,<10.0.0",
|
||||
"pytest-cov>=7.1.0,<8.0.0",
|
||||
"pytest-django>=4.14.0,<5.0.0",
|
||||
"model-bakery>=1.24.2,<2.0.0",
|
||||
"model-bakery>=1.25.0,<2.0.0",
|
||||
"beautifulsoup4>=4.15.0,<5",
|
||||
"lxml>=6.1.3,<7",
|
||||
]
|
||||
docs = [
|
||||
"mkdocs>=1.6.1,<2.0.0",
|
||||
"mkdocs-material>=9.7.7,<10.0.0",
|
||||
"mkdocs-material>=9.8.2,<10.0.0",
|
||||
"mkdocstrings>=1.0.6,<2.0.0",
|
||||
"mkdocstrings-python>=2.0.9,<3.0.0",
|
||||
"mkdocstrings-python>=2.0.11,<3.0.0",
|
||||
"mkdocs-include-markdown-plugin>=7.3.0,<8.0.0",
|
||||
]
|
||||
|
||||
|
||||
@@ -8,7 +8,10 @@ from django.utils.timezone import localtime
|
||||
from model_bakery import baker
|
||||
from pytest_django.asserts import assertRedirects
|
||||
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.models import BanGroup, User, UserBan
|
||||
from counter.models import Counter
|
||||
from sith import settings
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.test import Client
|
||||
@@ -33,11 +36,7 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
|
||||
client.force_login(operator)
|
||||
user = baker.make(User)
|
||||
ban_group = BanGroup.objects.first()
|
||||
data = {
|
||||
"user": user.id,
|
||||
"ban_group": ban_group.id,
|
||||
"reason": "Being naughty",
|
||||
}
|
||||
data = {"user": user.id, "ban_group": ban_group.id, "reason": "Being naughty"}
|
||||
if expires_at is not None:
|
||||
data["expires_at"] = expires_at.strftime("%Y-%m-%d %H:%M")
|
||||
response = client.post(reverse("rootplace:ban_create"), data)
|
||||
@@ -49,6 +48,24 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
|
||||
assert bans[0].ban_group == ban_group
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ban_counter_ends_barmanship():
|
||||
user = subscriber_user.make()
|
||||
counter = baker.make(Counter)
|
||||
counter.sellers.add(user, through_defaults={"is_regular": True})
|
||||
|
||||
UserBan.objects.create(
|
||||
user=user,
|
||||
ban_group_id=settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
|
||||
reason="ban comptoir",
|
||||
)
|
||||
|
||||
# check that we did effectively delete the barmanship
|
||||
# and not the bar itself (better safe than sorry)
|
||||
assert Counter.objects.filter(id=counter.id).exists()
|
||||
assert not user.counters.exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_remove_ban(client: Client, operator: User):
|
||||
client.force_login(operator)
|
||||
|
||||
+2
-2
@@ -103,6 +103,7 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
SITE_ID = 4000
|
||||
|
||||
INSTALLED_APPS = (
|
||||
"modeltranslation",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
@@ -285,7 +286,7 @@ LOGGING = {
|
||||
|
||||
LANGUAGE_CODE = "fr-FR"
|
||||
|
||||
LANGUAGES = [("en", _("English")), ("fr", _("French"))]
|
||||
LANGUAGES = [("fr", _("French")), ("en", _("English"))]
|
||||
|
||||
TIME_ZONE = "Europe/Paris"
|
||||
|
||||
@@ -621,7 +622,6 @@ with open(
|
||||
|
||||
SITH_NOTIFICATIONS = [
|
||||
("POSTER_MODERATION", _("A new poster needs to be moderated")),
|
||||
("MAILING_MODERATION", _("A new mailing list needs to be moderated")),
|
||||
(
|
||||
"PEDAGOGY_MODERATION",
|
||||
_("A new pedagogy comment has been signaled for moderation"),
|
||||
|
||||
@@ -104,7 +104,7 @@ class Migration(migrations.Migration):
|
||||
"week_group",
|
||||
models.CharField(
|
||||
blank=True,
|
||||
choices=[("A", "A"), ("B", "B")],
|
||||
choices=[("A", "A"), ("B", "B"), ("", "Both")],
|
||||
default="",
|
||||
max_length=1,
|
||||
verbose_name="week group",
|
||||
|
||||
Reference in new issue
Block a user