Merge branch 'stable' of

git@github.com:superuser-marty-me-uk/django-helpdesk.git into formatting
This commit is contained in:
Martin Whitehouse 2022-07-13 10:22:11 +02:00
commit b586442508
No known key found for this signature in database
GPG Key ID: 8492A7A45769CD35
12 changed files with 124 additions and 28 deletions

View File

@ -6,7 +6,7 @@ django-helpdesk - A Django powered ticket tracker for small businesses.
.. image:: https://codecov.io/gh/django-helpdesk/django-helpdesk/branch/develop/graph/badge.svg .. image:: https://codecov.io/gh/django-helpdesk/django-helpdesk/branch/develop/graph/badge.svg
:target: https://codecov.io/gh/django-helpdesk/django-helpdesk :target: https://codecov.io/gh/django-helpdesk/django-helpdesk
Copyright 2009-2021 Ross Poulton and django-helpdesk contributors. All Rights Reserved. Copyright 2009-2022 Ross Poulton and django-helpdesk contributors. All Rights Reserved.
See LICENSE for details. See LICENSE for details.
django-helpdesk was formerly known as Jutda Helpdesk, named after the django-helpdesk was formerly known as Jutda Helpdesk, named after the

View File

@ -17,18 +17,24 @@ pool:
vmImage: ubuntu-latest vmImage: ubuntu-latest
strategy: strategy:
matrix: matrix:
Python38Django22:
PYTHON_VERSION: '3.8'
DJANGO_VERSION: '22'
Python39Django22:
PYTHON_VERSION: '3.9'
DJANGO_VERSION: '22'
Python38Django32: Python38Django32:
PYTHON_VERSION: '3.8' PYTHON_VERSION: '3.8'
DJANGO_VERSION: '32' DJANGO_VERSION: '32'
Python39Django32: Python39Django32:
PYTHON_VERSION: '3.9' PYTHON_VERSION: '3.9'
DJANGO_VERSION: '32' DJANGO_VERSION: '32'
Python310Django32:
PYTHON_VERSION: '3.10'
DJANGO_VERSION: '32'
Python38Django4:
PYTHON_VERSION: '3.8'
DJANGO_VERSION: '4'
Python39Django4:
PYTHON_VERSION: '3.9'
DJANGO_VERSION: '4'
Python310Django4:
PYTHON_VERSION: '3.10'
DJANGO_VERSION: '4'
maxParallel: 10 maxParallel: 10
steps: steps:
@ -56,6 +62,7 @@ steps:
- script: | - script: |
python -m pip install --upgrade pip setuptools wheel python -m pip install --upgrade pip setuptools wheel
pip install -c constraints-Django$(DJANGO_VERSION).txt -r requirements.txt pip install -c constraints-Django$(DJANGO_VERSION).txt -r requirements.txt
pip install -c constraints-Django$(DJANGO_VERSION).txt -r requirements-testing.txt
pip install unittest-xml-reporting pip install unittest-xml-reporting
displayName: 'Install prerequisites' displayName: 'Install prerequisites'

View File

@ -1,2 +0,0 @@
Django >=2.2,<3

1
constraints-Django4.txt Normal file
View File

@ -0,0 +1 @@
Django >=4,<5

View File

@ -13,7 +13,7 @@ project_root = os.path.dirname(here)
NAME = 'django-helpdesk-demodesk' NAME = 'django-helpdesk-demodesk'
DESCRIPTION = 'A demo Django project using django-helpdesk' DESCRIPTION = 'A demo Django project using django-helpdesk'
README = open(os.path.join(here, 'README.rst')).read() README = open(os.path.join(here, 'README.rst')).read()
VERSION = '0.4.0' VERSION = '0.4.1'
#VERSION = open(os.path.join(project_root, 'VERSION')).read().strip() #VERSION = open(os.path.join(project_root, 'VERSION')).read().strip()
AUTHOR = 'django-helpdesk team' AUTHOR = 'django-helpdesk team'
URL = 'https://github.com/django-helpdesk/django-helpdesk' URL = 'https://github.com/django-helpdesk/django-helpdesk'

View File

@ -1,20 +1,25 @@
API API
=== ===
A REST API (built with ``djangorestframework``) is available in order to list, create, update and delete tickets from other tools thanks to HTTP requests. A REST API (built with ``djangorestframework``) is available in order to list, create, update and delete tickets from
other tools thanks to HTTP requests.
If you wish to use it, you have to add this line in your settings:: If you wish to use it, you have to add this line in your settings::
HELPDESK_ACTIVATE_API_ENDPOINT = True HELPDESK_ACTIVATE_API_ENDPOINT = True
You must be authenticated to access the API, the URL endpoint is ``/api/tickets/``. You can configure how you wish to authenticate to the API by customizing the ``DEFAULT_AUTHENTICATION_CLASSES`` key in the ``REST_FRAMEWORK`` setting (more information on this page : https://www.django-rest-framework.org/api-guide/authentication/) You must be authenticated to access the API, the URL endpoint is ``/api/tickets/``.
You can configure how you wish to authenticate to the API by customizing the ``DEFAULT_AUTHENTICATION_CLASSES`` key
in the ``REST_FRAMEWORK`` setting (more information on this page : https://www.django-rest-framework.org/api-guide/authentication/)
GET GET
--- ---
Accessing the endpoint ``/api/tickets/`` with a **GET** request will return you the complete list of tickets. Accessing the endpoint ``/api/tickets/`` with a **GET** request will return you the complete list of tickets with their
followups and their attachment files.
Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **GET** request will return you the data of the ticket you provided the ID. Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **GET** request will return you the data of the ticket you
provided the ID.
POST POST
---- ----
@ -35,7 +40,8 @@ You need to provide a JSON body with the following data :
- **due_date**: date representation for when the ticket is due - **due_date**: date representation for when the ticket is due
- **merged_to**: ID of the ticket to which it is merged - **merged_to**: ID of the ticket to which it is merged
Note that ``status`` will automatically be set to OPEN. Also, some fields are not configurable during creation: ``resolution``, ``on_hold`` and ``merged_to``. Note that ``status`` will automatically be set to OPEN. Also, some fields are not configurable during creation:
``resolution``, ``on_hold`` and ``merged_to``.
Moreover, if you created custom fields, you can add them into the body with the key ``custom_<custom-field-slug>``. Moreover, if you created custom fields, you can add them into the body with the key ``custom_<custom-field-slug>``.
@ -46,6 +52,34 @@ Here is an example of a cURL request to create a ticket (using Basic authenticat
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--data-raw '{"queue": 1, "title": "Test Ticket API", "description": "Test create ticket from API", "submitter_email": "test@mail.com", "priority": 4}' --data-raw '{"queue": 1, "title": "Test Ticket API", "description": "Test create ticket from API", "submitter_email": "test@mail.com", "priority": 4}'
Note that you can attach one file as attachment but in this case, you cannot use JSON for the request content type.
Here is an example with form-data (curl default) ::
curl --location --request POST 'http://127.0.0.1:8000/api/tickets/' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--form 'queue="1"' \
--form 'title="Test Ticket API with attachment"' \
--form 'description="Test create ticket from API avec attachment"' \
--form 'submitter_email="test@mail.com"' \
--form 'priority="2"' \
--form 'attachment=@"/C:/Users/benbb96/Documents/file.txt"'
----
Accessing the endpoint ``/api/followups/`` with a **POST** request will let you create a new followup on a ticket.
This time, you can attach multiple files thanks to the `attachments` field. Here is an example ::
curl --location --request POST 'http://127.0.0.1:8000/api/followups/' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--form 'ticket="44"' \
--form 'title="Test ticket answer"' \
--form 'comment="This answer contains multiple files as attachment."' \
--form 'attachments=@"/C:/Users/benbb96/Documents/doc.pdf"' \
--form 'attachments=@"/C:/Users/benbb96/Documents/image.png"'
----
Accessing the endpoint ``/api/users/`` with a **POST** request will let you create a new user. Accessing the endpoint ``/api/users/`` with a **POST** request will let you create a new user.
You need to provide a JSON body with the following data : You need to provide a JSON body with the following data :
@ -59,18 +93,21 @@ You need to provide a JSON body with the following data :
PUT PUT
--- ---
Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **PUT** request will let you update the data of the ticket you provided the ID. Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **PUT** request will let you update the data of the ticket
you provided the ID.
You must include all fields in the JSON body. You must include all fields in the JSON body.
PATCH PATCH
----- -----
Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **PATCH** request will let you do a partial update of the data of the ticket you provided the ID. Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **PATCH** request will let you do a partial update of the
data of the ticket you provided the ID.
You can include only the fields you need to update in the JSON body. You can include only the fields you need to update in the JSON body.
DELETE DELETE
------ ------
Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **DELETE** request will let you delete the ticket you provided the ID. Accessing the endpoint ``/api/tickets/<ticket-id>`` with a **DELETE** request will let you delete the ticket you
provided the ID.

View File

@ -74,11 +74,12 @@ errors with trying to create User settings.
SITE_ID = 1 SITE_ID = 1
2. Make sure django-helpdesk is accessible via ``urls.py``. Add the following line to ``urls.py``:: 2. Make sure django-helpdesk is accessible via ``urls.py``. Add the following lines to ``urls.py``::
from django.conf.urls import include
path('helpdesk/', include('helpdesk.urls')), path('helpdesk/', include('helpdesk.urls')),
Note that you can change 'helpdesk/' to anything you like, such as 'support/' or 'help/'. If you want django-helpdesk to be available at the root of your site (for example at http://support.mysite.tld/) then the line will be as follows:: Note that you can change 'helpdesk/' to anything you like, such as 'support/' or 'help/'. If you want django-helpdesk to be available at the root of your site (for example at http://support.mysite.tld/) then the path line will be as follows::
path('', include('helpdesk.urls', namespace='helpdesk')), path('', include('helpdesk.urls', namespace='helpdesk')),

View File

@ -4,8 +4,8 @@ from django.contrib.humanize.templatetags import humanize
from rest_framework.exceptions import ValidationError from rest_framework.exceptions import ValidationError
from .forms import TicketForm from .forms import TicketForm
from .models import Ticket, CustomField from .models import Ticket, CustomField, FollowUp, FollowUpAttachment
from .lib import format_time_spent from .lib import format_time_spent, process_attachments
from .user import HelpdeskUser from .user import HelpdeskUser
@ -71,12 +71,45 @@ class DatatablesTicketSerializer(serializers.ModelSerializer):
return obj.kbitem.title if obj.kbitem else "" return obj.kbitem.title if obj.kbitem else ""
class FollowUpAttachmentSerializer(serializers.ModelSerializer):
class Meta:
model = FollowUpAttachment
fields = ('id', 'followup', 'file', 'filename', 'mime_type', 'size')
class FollowUpSerializer(serializers.ModelSerializer):
followupattachment_set = FollowUpAttachmentSerializer(
many=True, read_only=True)
attachments = serializers.ListField(
child=serializers.FileField(),
write_only=True,
required=False
)
class Meta:
model = FollowUp
fields = (
'id', 'ticket', 'date', 'title', 'comment', 'public', 'user', 'new_status', 'message_id',
'time_spent', 'followupattachment_set', 'attachments'
)
def create(self, validated_data):
attachments = validated_data.pop('attachments', None)
followup = super().create(validated_data)
if attachments:
process_attachments(followup, attachments)
return followup
class TicketSerializer(serializers.ModelSerializer): class TicketSerializer(serializers.ModelSerializer):
followup_set = FollowUpSerializer(many=True, read_only=True)
attachment = serializers.FileField(write_only=True, required=False)
class Meta: class Meta:
model = Ticket model = Ticket
fields = ( fields = (
'id', 'queue', 'title', 'description', 'resolution', 'submitter_email', 'assigned_to', 'status', 'on_hold', 'id', 'queue', 'title', 'description', 'resolution', 'submitter_email', 'assigned_to', 'status', 'on_hold',
'priority', 'due_date', 'merged_to' 'priority', 'due_date', 'merged_to', 'attachment', 'followup_set'
) )
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -99,7 +132,10 @@ class TicketSerializer(serializers.ModelSerializer):
if data.get('merged_to'): if data.get('merged_to'):
data['merged_to'] = data['merged_to'].id data['merged_to'] = data['merged_to'].id
ticket_form = TicketForm(data=data, queue_choices=queue_choices) files = {'attachment': data.pop('attachment', None)}
ticket_form = TicketForm(
data=data, files=files, queue_choices=queue_choices)
if ticket_form.is_valid(): if ticket_form.is_valid():
ticket = ticket_form.save(user=self.context['request'].user) ticket = ticket_form.save(user=self.context['request'].user)
ticket.set_custom_field_values() ticket.set_custom_field_values()

View File

@ -17,7 +17,7 @@ from rest_framework.routers import DefaultRouter
from helpdesk.decorators import helpdesk_staff_member_required, protect_view from helpdesk.decorators import helpdesk_staff_member_required, protect_view
from helpdesk.views import feeds, staff, public, login from helpdesk.views import feeds, staff, public, login
from helpdesk import settings as helpdesk_settings from helpdesk import settings as helpdesk_settings
from helpdesk.views.api import TicketViewSet, CreateUserView from helpdesk.views.api import TicketViewSet, CreateUserView, FollowUpViewSet, FollowUpAttachmentViewSet
if helpdesk_settings.HELPDESK_KB_ENABLED: if helpdesk_settings.HELPDESK_KB_ENABLED:
from helpdesk.views import kb from helpdesk.views import kb
@ -183,6 +183,9 @@ urlpatterns += [
if helpdesk_settings.HELPDESK_ACTIVATE_API_ENDPOINT: if helpdesk_settings.HELPDESK_ACTIVATE_API_ENDPOINT:
router = DefaultRouter() router = DefaultRouter()
router.register(r"tickets", TicketViewSet, basename="ticket") router.register(r"tickets", TicketViewSet, basename="ticket")
router.register(r"followups", FollowUpViewSet, basename="followups")
router.register(r"followups-attachments",
FollowUpAttachmentViewSet, basename="followupattachments")
router.register(r"users", CreateUserView, basename="user") router.register(r"users", CreateUserView, basename="user")
urlpatterns += [re_path(r"^api/", include(router.urls))] urlpatterns += [re_path(r"^api/", include(router.urls))]

View File

@ -4,8 +4,8 @@ from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import CreateModelMixin from rest_framework.mixins import CreateModelMixin
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from helpdesk.models import Ticket from helpdesk.models import Ticket, FollowUp, FollowUpAttachment
from helpdesk.serializers import TicketSerializer, UserSerializer from helpdesk.serializers import TicketSerializer, UserSerializer, FollowUpSerializer, FollowUpAttachmentSerializer
class TicketViewSet(viewsets.ModelViewSet): class TicketViewSet(viewsets.ModelViewSet):
@ -28,6 +28,18 @@ class TicketViewSet(viewsets.ModelViewSet):
return ticket return ticket
class FollowUpViewSet(viewsets.ModelViewSet):
queryset = FollowUp.objects.all()
serializer_class = FollowUpSerializer
permission_classes = [IsAdminUser]
class FollowUpAttachmentViewSet(viewsets.ModelViewSet):
queryset = FollowUpAttachment.objects.all()
serializer_class = FollowUpAttachmentSerializer
permission_classes = [IsAdminUser]
class CreateUserView(CreateModelMixin, GenericViewSet): class CreateUserView(CreateModelMixin, GenericViewSet):
queryset = get_user_model().objects.all() queryset = get_user_model().objects.all()
serializer_class = UserSerializer serializer_class = UserSerializer

View File

@ -5,3 +5,4 @@ coverage
argparse argparse
pbr pbr
mock mock
freezegun

View File

@ -4,7 +4,7 @@ from distutils.util import convert_path
from fnmatch import fnmatchcase from fnmatch import fnmatchcase
from setuptools import setup, find_packages from setuptools import setup, find_packages
version = '0.4.0' version = '0.4.1'
# Provided as an attribute, so you can append to these instead # Provided as an attribute, so you can append to these instead
# of replicating them: # of replicating them: