From dc60d8a7f95ed789872817bf3a7e269f38b5fc3e Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Fri, 15 Apr 2022 00:05:51 +0200 Subject: [PATCH] Add setting HELPDESK_ACTIVATE_API_ENDPOINT and document it --- demo/demodesk/config/settings.py | 3 +++ docs/api.rst | 4 ++++ docs/settings.rst | 4 ++++ helpdesk/settings.py | 3 +++ helpdesk/urls.py | 13 +++++++------ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/demo/demodesk/config/settings.py b/demo/demodesk/config/settings.py index e2998c30..e4ac94f1 100644 --- a/demo/demodesk/config/settings.py +++ b/demo/demodesk/config/settings.py @@ -117,6 +117,9 @@ HELPDESK_KB_ENABLED = True # Allow users to change their passwords HELPDESK_SHOW_CHANGE_PASSWORD = True +# Activate the API +HELPDESK_ACTIVATE_API_ENDPOINT = True + # Instead of showing the public web portal first, # we can instead redirect users straight to the login page. HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = False diff --git a/docs/api.rst b/docs/api.rst index 42f4ec5d..474bfe22 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -3,6 +3,10 @@ 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. +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/) GET diff --git a/docs/settings.rst b/docs/settings.rst index 405e8f8d..246ce4b6 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -168,6 +168,10 @@ Staff Ticket Creation Settings **Default:** ``HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO = False`` +- **HELPDESK_ACTIVATE_API_ENDPOINT** Activate the API endpoint to manage tickets thanks to Django REST Framework. See the API section in documentation for more information. + + **Default:** ``HELPDESK_ACTIVATE_API_ENDPOINT = False`` + Staff Ticket View Settings ------------------------------ diff --git a/helpdesk/settings.py b/helpdesk/settings.py index 56be1dbb..a46af953 100644 --- a/helpdesk/settings.py +++ b/helpdesk/settings.py @@ -172,6 +172,9 @@ HELPDESK_MAX_EMAIL_ATTACHMENT_SIZE = getattr(settings, 'HELPDESK_MAX_EMAIL_ATTAC HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO = getattr( settings, 'HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO', False) +# Activate the API endpoint to manage tickets thanks to Django REST Framework +HELPDESK_ACTIVATE_API_ENDPOINT = getattr(settings, 'HELPDESK_ACTIVATE_API_ENDPOINT', False) + ################# # email options # diff --git a/helpdesk/urls.py b/helpdesk/urls.py index 29a6654f..fc185cc9 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -219,12 +219,13 @@ urlpatterns += [ ] -# API -router = DefaultRouter() -router.register(r'tickets', TicketViewSet, basename='ticket') -urlpatterns += [ - url(r'^api/', include(router.urls)) -] +# API is added to url conf based on the setting (False by default) +if helpdesk_settings.HELPDESK_ACTIVATE_API_ENDPOINT: + router = DefaultRouter() + router.register(r'tickets', TicketViewSet, basename='ticket') + urlpatterns += [ + url(r'^api/', include(router.urls)) + ] urlpatterns += [