Coverage for apps/users/views.py: 67%
31 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-27 13:33 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-27 13:33 -0600
1from rest_framework.decorators import action
2from rest_framework.mixins import CreateModelMixin as Create
3from rest_framework.mixins import DestroyModelMixin as Delete
4from rest_framework.mixins import ListModelMixin as List
5from rest_framework.mixins import RetrieveModelMixin as Detail
6from rest_framework.mixins import UpdateModelMixin as Update
7from rest_framework.permissions import AllowAny
8from rest_framework.response import Response
9from rest_framework.viewsets import GenericViewSet
11from .mixins import AdminMixin
12from .serializers import ResetPasswordSerializer, SetPasswordSerializer, UserSerializer
13from .services import send_password_reset_email
16class AdminUsersViewSet(AdminMixin, GenericViewSet, Create, List, Detail, Update, Delete):
17 """
18 Django User Model ViewSet
19 """
21 serializer_class = UserSerializer
22 search_fields = ["email", "employee__name"]
23 filterset_fields = ["employee__permissions"]
25 @action(detail=False, methods=["POST"], permission_classes=[AllowAny])
26 def reset(self, request):
27 data = request.data
28 serializer = ResetPasswordSerializer(data=data)
29 serializer.is_valid(True)
30 url, user = serializer.save(data)
31 send_password_reset_email(user, url)
33 return Response()
35 @action(detail=False, methods=["POST"], permission_classes=[AllowAny])
36 def confirm(self, request):
37 data = request.data
38 serializer = SetPasswordSerializer(data=data)
39 serializer.is_valid(True)
40 serializer.save(data)
42 return Response()