2023-11-17 12:25:13 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2014-10-23 15:38:46 +00:00
|
|
|
from rest_framework import viewsets, exceptions
|
2014-09-30 09:49:07 +00:00
|
|
|
|
2015-04-05 18:02:36 +00:00
|
|
|
from orchestra.api import router, SetPasswordApiMixin, LogApiMixin
|
2015-04-05 10:46:24 +00:00
|
|
|
from orchestra.contrib.accounts.api import AccountApiMixin
|
2014-09-30 09:49:07 +00:00
|
|
|
|
2014-09-30 16:39:47 +00:00
|
|
|
from .models import SystemUser
|
|
|
|
from .serializers import SystemUserSerializer
|
2014-09-30 09:49:07 +00:00
|
|
|
|
|
|
|
|
2015-04-05 18:02:36 +00:00
|
|
|
class SystemUserViewSet(LogApiMixin, AccountApiMixin, SetPasswordApiMixin, viewsets.ModelViewSet):
|
2015-04-23 14:34:04 +00:00
|
|
|
queryset = SystemUser.objects.all()
|
2014-09-30 16:39:47 +00:00
|
|
|
serializer_class = SystemUserSerializer
|
2014-10-01 16:42:40 +00:00
|
|
|
filter_fields = ('username',)
|
2014-10-23 15:38:46 +00:00
|
|
|
|
|
|
|
def destroy(self, request, pk=None):
|
|
|
|
user = self.get_object()
|
|
|
|
if user.is_main:
|
|
|
|
raise exceptions.PermissionDenied(_("Main system user can not be deleted."))
|
2014-10-23 21:25:44 +00:00
|
|
|
return super(SystemUserViewSet, self).destroy(request, pk=pk)
|
2014-09-30 09:49:07 +00:00
|
|
|
|
|
|
|
|
2014-09-30 16:39:47 +00:00
|
|
|
router.register(r'systemusers', SystemUserViewSet)
|