Deprecate VALID_EXTENSIONS properly

This commit is contained in:
Timothy Hobbs 2024-04-22 18:33:58 +02:00
parent 128a465d44
commit ebbbcdb2aa
3 changed files with 18 additions and 11 deletions

View File

@ -49,7 +49,7 @@ These settings can be used to change who can access the helpdesk.
**Default:** ``HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = False``
- **HELPDESK_VALID_EXTENSIONS** Valid extensions for file types that can be attached to tickets
- **HELPDESK_VALID_EXTENSIONS** Valid extensions for file types that can be attached to tickets. Note: This used to be calle **VALID_EXTENSIONS** which is now deprecated.
**Default:** ``HELPDESK_VALID_EXTENSIONS = ['.txt', '.asc', '.htm', '.html', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png', '.eml']

View File

@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy as _
import os
import re
import warnings
import sys
DEFAULT_USER_SETTINGS = {
@ -337,7 +338,12 @@ HELPDESK_IMAP_DEBUG_LEVEL = getattr(settings, 'HELPDESK_IMAP_DEBUG_LEVEL', 0)
# Override it in your own Django settings.py
HELPDESK_ATTACHMENT_DIR_PERMS = int(getattr(settings, 'HELPDESK_ATTACHMENT_DIR_PERMS', "755"), 8)
HELPDESK_VALID_EXTENSIONS = getattr(settings, 'HELPDESK_VALID_EXTENSIONS', ['.txt', '.asc', '.htm', '.html', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png', '.eml'])
HELPDESK_VALID_EXTENSIONS = getattr(settings, 'VALID_EXTENSIONS', None)
if HELPDESK_VALID_EXTENSIONS:
# Print to stderr
print("VALID_EXTENSIONS is deprecated, use HELPDESK_VALID_EXTENSIONS instead", file=sys.stderr)
else:
HELPDESK_VALID_EXTENSIONS = getattr(settings, 'HELPDESK_VALID_EXTENSIONS', ['.txt', '.asc', '.htm', '.html', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png', '.eml'])
HELPDESK_VALIDATE_ATTACHMENT_TYPES = getattr(settings, 'HELPDESK_VALIDATE_ATTACHMENT_TYPES', True)

View File

@ -51,15 +51,16 @@ class TicketViewSet(viewsets.ModelViewSet):
# filter by status
status = self.request.query_params.get('status', None)
statuses = status.split(',') if status else []
status_choices = helpdesk_settings.TICKET_STATUS_CHOICES
number_statuses = []
for status in statuses:
for choice in status_choices:
if choice[1] == status:
number_statuses.append(choice[0])
if number_statuses:
tickets = tickets.filter(status__in=number_statuses)
if status:
statuses = status.split(',') if status else []
status_choices = helpdesk_settings.TICKET_STATUS_CHOICES
number_statuses = []
for status in statuses:
for choice in status_choices:
if str(choice[0]) == status:
number_statuses.append(choice[0])
if number_statuses:
tickets = tickets.filter(status__in=number_statuses)
for ticket in tickets:
ticket.set_custom_field_values()