mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2025-01-12 00:49:25 +01:00
feat(rest): create user
This commit is contained in:
parent
3ed6c68046
commit
25db44ba5e
@ -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
|
||||
@ -226,6 +226,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,8 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user