mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-25 01:13:31 +01:00
Merge branch 'stable' of
git@github.com:superuser-marty-me-uk/django-helpdesk.git into formatting
This commit is contained in:
commit
b586442508
@ -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
|
||||
: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.
|
||||
|
||||
django-helpdesk was formerly known as Jutda Helpdesk, named after the
|
||||
|
@ -17,18 +17,24 @@ pool:
|
||||
vmImage: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
Python38Django22:
|
||||
PYTHON_VERSION: '3.8'
|
||||
DJANGO_VERSION: '22'
|
||||
Python39Django22:
|
||||
PYTHON_VERSION: '3.9'
|
||||
DJANGO_VERSION: '22'
|
||||
Python38Django32:
|
||||
PYTHON_VERSION: '3.8'
|
||||
DJANGO_VERSION: '32'
|
||||
Python39Django32:
|
||||
PYTHON_VERSION: '3.9'
|
||||
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
|
||||
|
||||
steps:
|
||||
@ -56,6 +62,7 @@ steps:
|
||||
- script: |
|
||||
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-testing.txt
|
||||
pip install unittest-xml-reporting
|
||||
displayName: 'Install prerequisites'
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
Django >=2.2,<3
|
||||
|
1
constraints-Django4.txt
Normal file
1
constraints-Django4.txt
Normal file
@ -0,0 +1 @@
|
||||
Django >=4,<5
|
@ -13,7 +13,7 @@ project_root = os.path.dirname(here)
|
||||
NAME = 'django-helpdesk-demodesk'
|
||||
DESCRIPTION = 'A demo Django project using django-helpdesk'
|
||||
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()
|
||||
AUTHOR = 'django-helpdesk team'
|
||||
URL = 'https://github.com/django-helpdesk/django-helpdesk'
|
||||
|
53
docs/api.rst
53
docs/api.rst
@ -1,20 +1,25 @@
|
||||
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::
|
||||
|
||||
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
|
||||
---
|
||||
|
||||
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
|
||||
----
|
||||
@ -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
|
||||
- **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>``.
|
||||
|
||||
@ -46,6 +52,34 @@ Here is an example of a cURL request to create a ticket (using Basic authenticat
|
||||
--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}'
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
---
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
@ -74,11 +74,12 @@ errors with trying to create User settings.
|
||||
|
||||
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')),
|
||||
|
||||
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')),
|
||||
|
||||
|
@ -4,8 +4,8 @@ from django.contrib.humanize.templatetags import humanize
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from .forms import TicketForm
|
||||
from .models import Ticket, CustomField
|
||||
from .lib import format_time_spent
|
||||
from .models import Ticket, CustomField, FollowUp, FollowUpAttachment
|
||||
from .lib import format_time_spent, process_attachments
|
||||
from .user import HelpdeskUser
|
||||
|
||||
|
||||
@ -71,12 +71,45 @@ class DatatablesTicketSerializer(serializers.ModelSerializer):
|
||||
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):
|
||||
followup_set = FollowUpSerializer(many=True, read_only=True)
|
||||
attachment = serializers.FileField(write_only=True, required=False)
|
||||
|
||||
class Meta:
|
||||
model = Ticket
|
||||
fields = (
|
||||
'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):
|
||||
@ -99,7 +132,10 @@ class TicketSerializer(serializers.ModelSerializer):
|
||||
if data.get('merged_to'):
|
||||
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():
|
||||
ticket = ticket_form.save(user=self.context['request'].user)
|
||||
ticket.set_custom_field_values()
|
||||
|
@ -17,7 +17,7 @@ from rest_framework.routers import DefaultRouter
|
||||
from helpdesk.decorators import helpdesk_staff_member_required, protect_view
|
||||
from helpdesk.views import feeds, staff, public, login
|
||||
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:
|
||||
from helpdesk.views import kb
|
||||
@ -183,6 +183,9 @@ urlpatterns += [
|
||||
if helpdesk_settings.HELPDESK_ACTIVATE_API_ENDPOINT:
|
||||
router = DefaultRouter()
|
||||
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")
|
||||
urlpatterns += [re_path(r"^api/", include(router.urls))]
|
||||
|
||||
|
@ -4,8 +4,8 @@ from rest_framework.viewsets import GenericViewSet
|
||||
from rest_framework.mixins import CreateModelMixin
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from helpdesk.models import Ticket
|
||||
from helpdesk.serializers import TicketSerializer, UserSerializer
|
||||
from helpdesk.models import Ticket, FollowUp, FollowUpAttachment
|
||||
from helpdesk.serializers import TicketSerializer, UserSerializer, FollowUpSerializer, FollowUpAttachmentSerializer
|
||||
|
||||
|
||||
class TicketViewSet(viewsets.ModelViewSet):
|
||||
@ -28,6 +28,18 @@ class TicketViewSet(viewsets.ModelViewSet):
|
||||
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):
|
||||
queryset = get_user_model().objects.all()
|
||||
serializer_class = UserSerializer
|
||||
|
@ -5,3 +5,4 @@ coverage
|
||||
argparse
|
||||
pbr
|
||||
mock
|
||||
freezegun
|
||||
|
Loading…
Reference in New Issue
Block a user