forked from DGNum/gestioCOF
Added separate permission for chef/trez
This commit is contained in:
parent
fa8c57269c
commit
46242ad2c0
4 changed files with 15 additions and 4 deletions
|
@ -206,3 +206,5 @@ MAIL_DATA = {
|
|||
|
||||
# Max lookback date into kfet history
|
||||
KFET_HISTORY_DATE_LIMIT = timedelta(weeks=1)
|
||||
# limite plus longue pour les chef/trez
|
||||
KFET_HISTORY_LONG_DATE_LIMIT = timedelta(days=30)
|
||||
|
|
|
@ -489,8 +489,9 @@ class FilterHistoryForm(forms.Form):
|
|||
label=_("De"),
|
||||
widget=DateTimeWidget,
|
||||
required=False,
|
||||
help_text="L'historique est limité à {} jours".format(
|
||||
settings.KFET_HISTORY_DATE_LIMIT.days
|
||||
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)
|
||||
|
|
|
@ -89,6 +89,7 @@ class Account(models.Model):
|
|||
("can_force_close", "Fermer manuellement la K-Fêt"),
|
||||
("see_config", "Voir la configuration K-Fêt"),
|
||||
("change_config", "Modifier la configuration K-Fêt"),
|
||||
("access_old_history", "Peut accéder à l'historique plus ancien"),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -1411,6 +1411,13 @@ def cancel_operations(request):
|
|||
return JsonResponse(data)
|
||||
|
||||
|
||||
def get_history_limit(user) -> timedelta:
|
||||
"""returns the earliest date the user can view history"""
|
||||
if user.has_perm("access_old_history"):
|
||||
return datetime.today() - settings.KFET_HISTORY_LONG_DATE_LIMIT
|
||||
return datetime.today() - settings.KFET_HISTORY_DATE_LIMIT
|
||||
|
||||
|
||||
@login_required
|
||||
def history_json(request):
|
||||
# Récupération des paramètres
|
||||
|
@ -1497,7 +1504,7 @@ def history_json(request):
|
|||
return JsonResponse({}, status=403)
|
||||
if limit_date:
|
||||
# limiter l'accès à l'historique ancien pour confidentialité
|
||||
earliest_date = datetime.today() - settings.KFET_HISTORY_DATE_LIMIT
|
||||
earliest_date = get_history_limit(request.user)
|
||||
opegroups = opegroups.filter(at__gte=earliest_date)
|
||||
transfergroups = transfergroups.filter(at__gte=earliest_date)
|
||||
|
||||
|
@ -1589,7 +1596,7 @@ def kpsul_articles_data(request):
|
|||
|
||||
@teamkfet_required
|
||||
def history(request):
|
||||
history_limit = timezone.now() - settings.KFET_HISTORY_DATE_LIMIT
|
||||
history_limit = get_history_limit(request.user)
|
||||
data = {
|
||||
"filter_form": FilterHistoryForm(),
|
||||
"history_limit": history_limit.strftime("%Y-%m-%d %H:%M"),
|
||||
|
|
Loading…
Reference in a new issue