Switch back from config to settings

This commit is contained in:
Dorian Lesbre 2021-02-20 20:59:54 +01:00
parent cc7c4306f4
commit 23f7865140
5 changed files with 22 additions and 18 deletions

View file

@ -25,7 +25,7 @@ adhérents ni des cotisations.
### K-Fêt ### K-Fêt
- L'accès à l'historique est maintenant limité à 7 jours pour raison de confidentialité. Les chefs/trez peuvent disposer d'une permission supplémentaire pour accèder à jusqu'à 30 jours en cas de problème de compta. L'accès à son historique personnel n'est pas limité. Les durées limites sont configurables depuis les paramètres K-Fêt. - L'accès à l'historique est maintenant limité à 7 jours pour raison de confidentialité. Les chefs/trez peuvent disposer d'une permission supplémentaire pour accèder à jusqu'à 30 jours en cas de problème de compta. L'accès à son historique personnel n'est pas limité. Les durées sont configurables dans `settings/cof_prod.py`.
## Version 0.9 - 06/02/2020 ## Version 0.9 - 06/02/2020

View file

@ -5,6 +5,7 @@ Surcharge les settings définis dans common.py
""" """
import os import os
from datetime import timedelta
from .common import * # NOQA from .common import * # NOQA
from .common import ( from .common import (
@ -202,3 +203,15 @@ MAIL_DATA = {
"REPLYTO": "BdA-Revente <bda-revente@ens.fr>", "REPLYTO": "BdA-Revente <bda-revente@ens.fr>",
}, },
} }
# ---
# kfet history limits
# ---
# L'historique n'est accesible que d'aujourd'hui
# à aujourd'hui - KFET_HISTORY_DATE_LIMIT
KFET_HISTORY_DATE_LIMIT = timedelta(days=7)
# Limite plus longue pour les chefs/trez
# (qui ont la permission kfet.access_old_history)
KFET_HISTORY_LONG_DATE_LIMIT = timedelta(days=30)

View file

@ -2,6 +2,7 @@ from datetime import timedelta
from decimal import Decimal from decimal import Decimal
from django import forms from django import forms
from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core import validators from django.core import validators
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -481,16 +482,6 @@ class KFetConfigForm(ConfigForm):
label="Durée pour annuler une commande sans mot de passe", label="Durée pour annuler une commande sans mot de passe",
initial=timedelta(minutes=5), initial=timedelta(minutes=5),
) )
kfet_history_limit = forms.DurationField(
label="Limite de confidentialité de l'historique",
initial=timedelta(days=7),
help_text="Les éléments plus vieux que cette durée seront masqués",
)
kfet_history_long_limit = forms.DurationField(
label="Limite de confidentialité de l'historique pour chef/trez",
initial=timedelta(days=30),
help_text="Limite plus longue en cas de problème de compta",
)
class FilterHistoryForm(forms.Form): class FilterHistoryForm(forms.Form):
@ -498,7 +489,10 @@ class FilterHistoryForm(forms.Form):
label=_("De"), label=_("De"),
widget=DateTimeWidget, widget=DateTimeWidget,
required=False, required=False,
help_text="Limité pour raisons de confidentialité", help_text="Limité à {} jours ({} pour les chefs/trez)".format(
settings.KFET_HISTORY_DATE_LIMIT.days,
settings.KFET_HISTORY_LONG_DATE_LIMIT.days,
),
) )
end = forms.DateTimeField(label=_("À"), widget=DateTimeWidget, required=False) end = forms.DateTimeField(label=_("À"), widget=DateTimeWidget, required=False)
checkout = forms.ModelChoiceField( checkout = forms.ModelChoiceField(

View file

@ -4310,8 +4310,6 @@ class SettingsUpdateViewTests(ViewTestCaseMixin, TestCase):
"kfet_overdraft_duration": "2 00:00:00", "kfet_overdraft_duration": "2 00:00:00",
"kfet_overdraft_amount": "25", "kfet_overdraft_amount": "25",
"kfet_cancel_duration": "00:20:00", "kfet_cancel_duration": "00:20:00",
"kfet_history_limit": "5 00:00:00",
"kfet_history_long_limit": "60 00:00:00",
} }
def get_users_extra(self): def get_users_extra(self):
@ -4333,8 +4331,6 @@ class SettingsUpdateViewTests(ViewTestCaseMixin, TestCase):
"overdraft_duration": timedelta(days=2), "overdraft_duration": timedelta(days=2),
"overdraft_amount": Decimal("25"), "overdraft_amount": Decimal("25"),
"cancel_duration": timedelta(minutes=20), "cancel_duration": timedelta(minutes=20),
"history_limit": timedelta(days=5),
"history_long_limit": timedelta(days=60),
} }
for key, expected in expected_config.items(): for key, expected in expected_config.items():

View file

@ -6,6 +6,7 @@ from decimal import Decimal
from typing import List from typing import List
from urllib.parse import urlencode from urllib.parse import urlencode
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
@ -1415,9 +1416,9 @@ def get_history_limit(user) -> datetime:
according to his/her permissions""" according to his/her permissions"""
now = timezone.now() now = timezone.now()
if user.has_perm("kfet.access_old_history"): if user.has_perm("kfet.access_old_history"):
return now - kfet_config.history_long_limit return now - settings.KFET_HISTORY_LONG_DATE_LIMIT
if user.has_perm("kfet.is_team"): if user.has_perm("kfet.is_team"):
return now - kfet_config.history_limit return now - settings.KFET_HISTORY_LONG_DATE_LIMIT
# should not happen - future earliest date # should not happen - future earliest date
return now + timedelta(days=1) return now + timedelta(days=1)