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`` **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'] **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 os
import re import re
import warnings import warnings
import sys
DEFAULT_USER_SETTINGS = { DEFAULT_USER_SETTINGS = {
@ -337,6 +338,11 @@ HELPDESK_IMAP_DEBUG_LEVEL = getattr(settings, 'HELPDESK_IMAP_DEBUG_LEVEL', 0)
# Override it in your own Django settings.py # Override it in your own Django settings.py
HELPDESK_ATTACHMENT_DIR_PERMS = int(getattr(settings, 'HELPDESK_ATTACHMENT_DIR_PERMS', "755"), 8) HELPDESK_ATTACHMENT_DIR_PERMS = int(getattr(settings, 'HELPDESK_ATTACHMENT_DIR_PERMS', "755"), 8)
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_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) HELPDESK_VALIDATE_ATTACHMENT_TYPES = getattr(settings, 'HELPDESK_VALIDATE_ATTACHMENT_TYPES', True)

View File

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