mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-22 07:53:19 +01:00
Merge in bugfixes from 0.3.5
This commit is contained in:
commit
ee42ba48a3
@ -17,7 +17,7 @@ contributors reaching far beyond Jutda.
|
||||
Complete documentation is available in the docs/ directory,
|
||||
or online at http://django-helpdesk.readthedocs.org/.
|
||||
|
||||
You can see a demo installation at http://django-helpdesk-demo.herokuapp.com/,
|
||||
You can see a demo installation at https://django-helpdesk-demo.herokuapp.com/,
|
||||
or run a demo locally in just a couple steps!
|
||||
|
||||
Demo Quickstart
|
||||
|
10
docs/api.rst
10
docs/api.rst
@ -46,6 +46,16 @@ 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}'
|
||||
|
||||
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 :
|
||||
|
||||
- **first_name**: first name
|
||||
- **last_name**: last name
|
||||
- **username**: username
|
||||
- **email**: user email
|
||||
- **password**: user password
|
||||
|
||||
PUT
|
||||
---
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.humanize.templatetags import humanize
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
@ -110,3 +111,18 @@ class TicketSerializer(serializers.ModelSerializer):
|
||||
instance = super().update(instance, validated_data)
|
||||
instance.save_custom_field_values(validated_data)
|
||||
return instance
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
password = serializers.CharField(write_only=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name', 'username', 'email', 'password')
|
||||
|
||||
def create(self, validated_data):
|
||||
user = super(UserSerializer, self).create(validated_data)
|
||||
user.is_active = True
|
||||
user.set_password(validated_data['password'])
|
||||
user.save()
|
||||
return user
|
||||
|
@ -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
|
||||
from helpdesk.views.api import TicketViewSet, CreateUserView
|
||||
|
||||
if helpdesk_settings.HELPDESK_KB_ENABLED:
|
||||
from helpdesk.views import kb
|
||||
@ -234,6 +234,7 @@ urlpatterns += [
|
||||
if helpdesk_settings.HELPDESK_ACTIVATE_API_ENDPOINT:
|
||||
router = DefaultRouter()
|
||||
router.register(r'tickets', TicketViewSet, basename='ticket')
|
||||
router.register(r'users', CreateUserView, basename='user')
|
||||
urlpatterns += [
|
||||
url(r'^api/', include(router.urls))
|
||||
]
|
||||
|
@ -1,8 +1,11 @@
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
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
|
||||
from helpdesk.serializers import TicketSerializer, UserSerializer
|
||||
|
||||
|
||||
class TicketViewSet(viewsets.ModelViewSet):
|
||||
@ -23,3 +26,9 @@ class TicketViewSet(viewsets.ModelViewSet):
|
||||
ticket = super().get_object()
|
||||
ticket.set_custom_field_values()
|
||||
return ticket
|
||||
|
||||
|
||||
class CreateUserView(CreateModelMixin, GenericViewSet):
|
||||
queryset = get_user_model().objects.all()
|
||||
serializer_class = UserSerializer
|
||||
permission_classes = [IsAdminUser]
|
||||
|
Loading…
Reference in New Issue
Block a user